From 6a15b09f985f981c3dec8ab46ad235f244bec24d Mon Sep 17 00:00:00 2001 From: kassens Date: Fri, 2 May 2025 13:59:14 -0700 Subject: [PATCH] Add missing copyright header (#33106) This made the build fail since there was no file header comment. DiffTrain build for [9de0304ad72bc3f8a77d2d84efa530b8051d1c15](https://github.com/facebook/react/commit/9de0304ad72bc3f8a77d2d84efa530b8051d1c15) --- compiled-rn/VERSION_NATIVE_FB | 2 +- .../eslint-plugin-react-hooks/LICENSE | 21 + .../eslint-plugin-react-hooks/README.md | 138 + .../cjs/eslint-plugin-react-hooks.d.ts | 87 + .../eslint-plugin-react-hooks.development.js | 60291 ++++++++++++++++ .../eslint-plugin-react-hooks.production.js | 60068 +++++++++++++++ .../eslint-plugin-react-hooks/index.d.ts | 8 + .../eslint-plugin-react-hooks/index.js | 17 + .../eslint-plugin-react-hooks/package.json | 69 + .../react/react-dom/cjs/ReactDOM-dev.js | 4 +- .../react/react-dom/cjs/ReactDOM-prod.js | 4 +- .../react/react-dom/cjs/ReactDOM-profiling.js | 4 +- .../react/react-dom/cjs/ReactDOMClient-dev.js | 12 +- .../react-dom/cjs/ReactDOMClient-prod.js | 12 +- .../react-dom/cjs/ReactDOMClient-profiling.js | 12 +- .../react-dom/cjs/ReactDOMProfiling-dev.js | 12 +- .../react-dom/cjs/ReactDOMProfiling-prod.js | 12 +- .../cjs/ReactDOMProfiling-profiling.js | 12 +- .../cjs/ReactTestRenderer-dev.js | 8 +- .../cjs/ReactTestRenderer-prod.js | 8 +- .../cjs/ReactTestRenderer-profiling.js | 8 +- .../vendor/react/react/cjs/React-dev.js | 4 +- .../vendor/react/react/cjs/React-prod.js | 4 +- .../vendor/react/react/cjs/React-profiling.js | 4 +- .../Libraries/Renderer/REVISION | 2 +- .../implementations/ReactFabric-dev.fb.js | 6 +- .../implementations/ReactFabric-prod.fb.js | 6 +- .../ReactFabric-profiling.fb.js | 6 +- .../ReactNativeRenderer-dev.fb.js | 10 +- .../ReactNativeRenderer-prod.fb.js | 10 +- .../ReactNativeRenderer-profiling.fb.js | 10 +- 31 files changed, 120785 insertions(+), 86 deletions(-) create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/LICENSE create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/README.md create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.d.ts create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.js create mode 100644 compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/package.json diff --git a/compiled-rn/VERSION_NATIVE_FB b/compiled-rn/VERSION_NATIVE_FB index 35d7b97794..a4b156d70d 100644 --- a/compiled-rn/VERSION_NATIVE_FB +++ b/compiled-rn/VERSION_NATIVE_FB @@ -1 +1 @@ -19.2.0-native-fb-0ed6ceb9-20250501 \ No newline at end of file +19.2.0-native-fb-9de0304a-20250502 \ No newline at end of file diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/LICENSE b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/LICENSE new file mode 100644 index 0000000000..b93be90515 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Meta Platforms, Inc. and affiliates. + +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. diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/README.md b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/README.md new file mode 100644 index 0000000000..10020afd61 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/README.md @@ -0,0 +1,138 @@ +# `eslint-plugin-react-hooks` + +This ESLint plugin enforces the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks). + +It is a part of the [Hooks API](https://react.dev/reference/react/hooks) for React. + +## Installation + +**Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.** + +Assuming you already have ESLint installed, run: + +```sh +# npm +npm install eslint-plugin-react-hooks --save-dev + +# yarn +yarn add eslint-plugin-react-hooks --dev +``` + +### Flat Config (eslint.config.js|ts) + +#### >= 6.0.0 + +For users of 6.0 and beyond, simply add the `recommended` config. + +```js +import * as reactHooks from 'eslint-plugin-react-hooks'; + +export default [ + // ... + reactHooks.configs.recommended, +]; +``` + +#### 5.2.0 + +For users of 5.2.0 (the first version with flat config support), add the `recommended-latest` config. + +```js +import * as reactHooks from 'eslint-plugin-react-hooks'; + +export default [ + // ... + reactHooks.configs['recommended-latest'], +]; +``` + +### Legacy Config (.eslintrc) + +#### >= 5.2.0 + +If you are still using ESLint below 9.0.0, you can use `recommended-legacy` for accessing a legacy version of the recommended config. + +```js +{ + "extends": [ + // ... + "plugin:react-hooks/recommended-legacy" + ] +} +``` + +#### < 5.2.0 + +If you're using a version earlier than 5.2.0, the legacy config was simply `recommended`. + +```js +{ + "extends": [ + // ... + "plugin:react-hooks/recommended" + ] +} +``` + +### Custom Configuration + +If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file: + +#### Flat Config (eslint.config.js|ts) + +```js +import * as reactHooks from 'eslint-plugin-react-hooks'; + +export default [ + { + files: ['**/*.{js,jsx}'], + plugins: { 'react-hooks': reactHooks }, + // ... + rules: { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + } + }, +]; +``` + +#### Legacy Config (.eslintrc) +```js +{ + "plugins": [ + // ... + "react-hooks" + ], + "rules": { + // ... + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" + } +} +``` + +## Advanced Configuration + +`exhaustive-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option. +This option accepts a regex to match the names of custom Hooks that have dependencies. + +```js +{ + rules: { + // ... + "react-hooks/exhaustive-deps": ["warn", { + additionalHooks: "(useMyCustomHook|useMyOtherCustomHook)" + }] + } +} +``` + +We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case. + +## Valid and Invalid Examples + +Please refer to the [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks) documentation to learn more about this rule. + +## License + +MIT diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts new file mode 100644 index 0000000000..94ed28a660 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.d.ts @@ -0,0 +1,87 @@ +import * as estree from 'estree'; +import { Rule, ESLint } from 'eslint'; + +declare const rules: { + 'exhaustive-deps': { + meta: { + type: "suggestion"; + docs: { + description: string; + recommended: true; + url: string; + }; + fixable: "code"; + hasSuggestions: true; + schema: { + type: "object"; + additionalProperties: false; + enableDangerousAutofixThisMayCauseInfiniteLoops: boolean; + properties: { + additionalHooks: { + type: "string"; + }; + enableDangerousAutofixThisMayCauseInfiniteLoops: { + type: "boolean"; + }; + }; + }[]; + }; + create(context: Rule.RuleContext): { + CallExpression: (node: estree.CallExpression) => void; + }; + }; + 'react-compiler': Rule.RuleModule; + 'rules-of-hooks': { + meta: { + type: "problem"; + docs: { + description: string; + recommended: true; + url: string; + }; + }; + create(context: Rule.RuleContext): { + '*'(node: any): void; + '*:exit'(node: any): void; + CallExpression(node: estree.CallExpression & Rule.NodeParentExtension): void; + Identifier(node: estree.Identifier & Rule.NodeParentExtension): void; + 'CallExpression:exit'(node: estree.CallExpression & Rule.NodeParentExtension): void; + FunctionDeclaration(node: estree.FunctionDeclaration & Rule.NodeParentExtension): void; + ArrowFunctionExpression(node: estree.ArrowFunctionExpression & Rule.NodeParentExtension): void; + }; + }; +}; +declare const configs: { + 'recommended-legacy': { + plugins: string[]; + rules: { + 'react-hooks/rules-of-hooks': "error"; + 'react-hooks/exhaustive-deps': "warn"; + }; + }; + recommended: { + name: string; + plugins: { + readonly 'react-hooks': ESLint.Plugin; + }; + rules: { + 'react-hooks/rules-of-hooks': "error"; + 'react-hooks/exhaustive-deps': "warn"; + }; + }; + 'recommended-latest': { + name: string; + plugins: { + readonly 'react-hooks': ESLint.Plugin; + }; + rules: { + 'react-hooks/rules-of-hooks': "error"; + 'react-hooks/exhaustive-deps': "warn"; + }; + }; +}; +declare const meta: { + name: string; +}; + +export { configs, meta, rules }; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js new file mode 100644 index 0000000000..8d7f9cdbb5 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js @@ -0,0 +1,60291 @@ +/** + * + * eslint-plugin-react-hooks.development.js + * + * 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. + * + * @noformat + * @nolint + * @lightSyntaxTransform + * @preventMunge + * @oncall react_core + * @generated SignedSource<<324e2b6f51fe0b8c1b4b81d5b67dc594>> + */ + +'use strict'; + +if (process.env.NODE_ENV !== "production") { + (function() { +'use strict'; + +var core$1 = require('@babel/core'); +var PluginProposalPrivateMethods = require('@babel/plugin-transform-private-methods'); +require('@babel/parser'); +var zod = require('zod'); +var zodValidationError = require('zod-validation-error'); +var crypto = require('crypto'); +var HermesParser = require('hermes-parser'); + +const rule$2 = { + meta: { + type: 'suggestion', + docs: { + description: 'verifies the list of dependencies for Hooks like useEffect and similar', + recommended: true, + url: 'https://github.com/facebook/react/issues/14920', + }, + fixable: 'code', + hasSuggestions: true, + schema: [ + { + type: 'object', + additionalProperties: false, + enableDangerousAutofixThisMayCauseInfiniteLoops: false, + properties: { + additionalHooks: { + type: 'string', + }, + enableDangerousAutofixThisMayCauseInfiniteLoops: { + type: 'boolean', + }, + }, + }, + ], + }, + create(context) { + const additionalHooks = context.options && + context.options[0] && + context.options[0].additionalHooks + ? new RegExp(context.options[0].additionalHooks) + : undefined; + const enableDangerousAutofixThisMayCauseInfiniteLoops = (context.options && + context.options[0] && + context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops) || + false; + const options = { + additionalHooks, + enableDangerousAutofixThisMayCauseInfiniteLoops, + }; + function reportProblem(problem) { + if (enableDangerousAutofixThisMayCauseInfiniteLoops) { + if (Array.isArray(problem.suggest) && + problem.suggest.length > 0 && + problem.suggest[0]) { + problem.fix = problem.suggest[0].fix; + } + } + context.report(problem); + } + const getSourceCode = typeof context.getSourceCode === 'function' + ? () => { + return context.getSourceCode(); + } + : () => { + return context.sourceCode; + }; + const getScope = typeof context.getScope === 'function' + ? () => { + return context.getScope(); + } + : (node) => { + return context.sourceCode.getScope(node); + }; + const scopeManager = getSourceCode().scopeManager; + const setStateCallSites = new WeakMap(); + const stateVariables = new WeakSet(); + const stableKnownValueCache = new WeakMap(); + const functionWithoutCapturedValueCache = new WeakMap(); + const useEffectEventVariables = new WeakSet(); + function memoizeWithWeakMap(fn, map) { + return function (arg) { + if (map.has(arg)) { + return map.get(arg); + } + const result = fn(arg); + map.set(arg, result); + return result; + }; + } + function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect) { + if (isEffect && node.async) { + reportProblem({ + node: node, + message: `Effect callbacks are synchronous to prevent race conditions. ` + + `Put the async function inside:\n\n` + + 'useEffect(() => {\n' + + ' async function fetchData() {\n' + + ' // You can await here\n' + + ' const response = await MyAPI.getData(someId);\n' + + ' // ...\n' + + ' }\n' + + ' fetchData();\n' + + `}, [someId]); // Or [] if effect doesn't need props or state\n\n` + + 'Learn more about data fetching with Hooks: https://react.dev/link/hooks-data-fetching', + }); + } + const scope = scopeManager.acquire(node); + if (!scope) { + throw new Error('Unable to acquire scope for the current node. This is a bug in eslint-plugin-react-hooks, please file an issue.'); + } + const pureScopes = new Set(); + let componentScope = null; + { + let currentScope = scope.upper; + while (currentScope) { + pureScopes.add(currentScope); + if (currentScope.type === 'function') { + break; + } + currentScope = currentScope.upper; + } + if (!currentScope) { + return; + } + componentScope = currentScope; + } + const isArray = Array.isArray; + function isStableKnownHookValue(resolved) { + if (!isArray(resolved.defs)) { + return false; + } + const def = resolved.defs[0]; + if (def == null) { + return false; + } + const defNode = def.node; + if (defNode.type !== 'VariableDeclarator') { + return false; + } + let init = defNode.init; + if (init == null) { + return false; + } + while (init.type === 'TSAsExpression' || init.type === 'AsExpression') { + init = init.expression; + } + let declaration = defNode.parent; + if (declaration == null && componentScope != null) { + fastFindReferenceWithParent(componentScope.block, def.node.id); + declaration = def.node.parent; + if (declaration == null) { + return false; + } + } + if (declaration != null && + 'kind' in declaration && + declaration.kind === 'const' && + init.type === 'Literal' && + (typeof init.value === 'string' || + typeof init.value === 'number' || + init.value === null)) { + return true; + } + if (init.type !== 'CallExpression') { + return false; + } + let callee = init.callee; + if (callee.type === 'MemberExpression' && + 'name' in callee.object && + callee.object.name === 'React' && + callee.property != null && + !callee.computed) { + callee = callee.property; + } + if (callee.type !== 'Identifier') { + return false; + } + const definitionNode = def.node; + const id = definitionNode.id; + const { name } = callee; + if (name === 'useRef' && id.type === 'Identifier') { + return true; + } + else if (isUseEffectEventIdentifier$1(callee) && + id.type === 'Identifier') { + for (const ref of resolved.references) { + if (ref !== id) { + useEffectEventVariables.add(ref.identifier); + } + } + return true; + } + else if (name === 'useState' || + name === 'useReducer' || + name === 'useActionState') { + if (id.type === 'ArrayPattern' && + id.elements.length === 2 && + isArray(resolved.identifiers)) { + if (id.elements[1] === resolved.identifiers[0]) { + if (name === 'useState') { + const references = resolved.references; + let writeCount = 0; + for (const reference of references) { + if (reference.isWrite()) { + writeCount++; + } + if (writeCount > 1) { + return false; + } + setStateCallSites.set(reference.identifier, id.elements[0]); + } + } + return true; + } + else if (id.elements[0] === resolved.identifiers[0]) { + if (name === 'useState') { + const references = resolved.references; + for (const reference of references) { + stateVariables.add(reference.identifier); + } + } + return false; + } + } + } + else if (name === 'useTransition') { + if (id.type === 'ArrayPattern' && + id.elements.length === 2 && + Array.isArray(resolved.identifiers)) { + if (id.elements[1] === resolved.identifiers[0]) { + return true; + } + } + } + return false; + } + function isFunctionWithoutCapturedValues(resolved) { + if (!isArray(resolved.defs)) { + return false; + } + const def = resolved.defs[0]; + if (def == null) { + return false; + } + if (def.node == null || def.node.id == null) { + return false; + } + const fnNode = def.node; + const childScopes = (componentScope === null || componentScope === void 0 ? void 0 : componentScope.childScopes) || []; + let fnScope = null; + for (const childScope of childScopes) { + const childScopeBlock = childScope.block; + if ((fnNode.type === 'FunctionDeclaration' && + childScopeBlock === fnNode) || + (fnNode.type === 'VariableDeclarator' && + childScopeBlock.parent === fnNode)) { + fnScope = childScope; + break; + } + } + if (fnScope == null) { + return false; + } + for (const ref of fnScope.through) { + if (ref.resolved == null) { + continue; + } + if (pureScopes.has(ref.resolved.scope) && + !memoizedIsStableKnownHookValue(ref.resolved)) { + return false; + } + } + return true; + } + const memoizedIsStableKnownHookValue = memoizeWithWeakMap(isStableKnownHookValue, stableKnownValueCache); + const memoizedIsFunctionWithoutCapturedValues = memoizeWithWeakMap(isFunctionWithoutCapturedValues, functionWithoutCapturedValueCache); + const currentRefsInEffectCleanup = new Map(); + function isInsideEffectCleanup(reference) { + let curScope = reference.from; + let isInReturnedFunction = false; + while (curScope != null && curScope.block !== node) { + if (curScope.type === 'function') { + isInReturnedFunction = + curScope.block.parent != null && + curScope.block.parent.type === 'ReturnStatement'; + } + curScope = curScope.upper; + } + return isInReturnedFunction; + } + const dependencies = new Map(); + const optionalChains = new Map(); + gatherDependenciesRecursively(scope); + function gatherDependenciesRecursively(currentScope) { + var _a, _b, _c, _d, _e; + for (const reference of currentScope.references) { + if (!reference.resolved) { + continue; + } + if (!pureScopes.has(reference.resolved.scope)) { + continue; + } + const referenceNode = fastFindReferenceWithParent(node, reference.identifier); + if (referenceNode == null) { + continue; + } + const dependencyNode = getDependency(referenceNode); + const dependency = analyzePropertyChain(dependencyNode, optionalChains); + if (isEffect && + dependencyNode.type === 'Identifier' && + (((_a = dependencyNode.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' || + ((_b = dependencyNode.parent) === null || _b === void 0 ? void 0 : _b.type) === 'OptionalMemberExpression') && + !dependencyNode.parent.computed && + dependencyNode.parent.property.type === 'Identifier' && + dependencyNode.parent.property.name === 'current' && + isInsideEffectCleanup(reference)) { + currentRefsInEffectCleanup.set(dependency, { + reference, + dependencyNode, + }); + } + if (((_c = dependencyNode.parent) === null || _c === void 0 ? void 0 : _c.type) === 'TSTypeQuery' || + ((_d = dependencyNode.parent) === null || _d === void 0 ? void 0 : _d.type) === 'TSTypeReference') { + continue; + } + const def = reference.resolved.defs[0]; + if (def == null) { + continue; + } + if (def.node != null && def.node.init === node.parent) { + continue; + } + if (def.type === 'TypeParameter') { + continue; + } + if (!dependencies.has(dependency)) { + const resolved = reference.resolved; + const isStable = memoizedIsStableKnownHookValue(resolved) || + memoizedIsFunctionWithoutCapturedValues(resolved); + dependencies.set(dependency, { + isStable, + references: [reference], + }); + } + else { + (_e = dependencies.get(dependency)) === null || _e === void 0 ? void 0 : _e.references.push(reference); + } + } + for (const childScope of currentScope.childScopes) { + gatherDependenciesRecursively(childScope); + } + } + currentRefsInEffectCleanup.forEach(({ reference, dependencyNode }, dependency) => { + var _a, _b; + const references = ((_a = reference.resolved) === null || _a === void 0 ? void 0 : _a.references) || []; + let foundCurrentAssignment = false; + for (const ref of references) { + const { identifier } = ref; + const { parent } = identifier; + if (parent != null && + parent.type === 'MemberExpression' && + !parent.computed && + parent.property.type === 'Identifier' && + parent.property.name === 'current' && + ((_b = parent.parent) === null || _b === void 0 ? void 0 : _b.type) === 'AssignmentExpression' && + parent.parent.left === parent) { + foundCurrentAssignment = true; + break; + } + } + if (foundCurrentAssignment) { + return; + } + reportProblem({ + node: dependencyNode.parent.property, + message: `The ref value '${dependency}.current' will likely have ` + + `changed by the time this effect cleanup function runs. If ` + + `this ref points to a node rendered by React, copy ` + + `'${dependency}.current' to a variable inside the effect, and ` + + `use that variable in the cleanup function.`, + }); + }); + const staleAssignments = new Set(); + function reportStaleAssignment(writeExpr, key) { + if (staleAssignments.has(key)) { + return; + } + staleAssignments.add(key); + reportProblem({ + node: writeExpr, + message: `Assignments to the '${key}' variable from inside React Hook ` + + `${getSourceCode().getText(reactiveHook)} will be lost after each ` + + `render. To preserve the value over time, store it in a useRef ` + + `Hook and keep the mutable value in the '.current' property. ` + + `Otherwise, you can move this variable directly inside ` + + `${getSourceCode().getText(reactiveHook)}.`, + }); + } + const stableDependencies = new Set(); + dependencies.forEach(({ isStable, references }, key) => { + if (isStable) { + stableDependencies.add(key); + } + references.forEach(reference => { + if (reference.writeExpr) { + reportStaleAssignment(reference.writeExpr, key); + } + }); + }); + if (staleAssignments.size > 0) { + return; + } + if (!declaredDependenciesNode) { + let setStateInsideEffectWithoutDeps = null; + dependencies.forEach(({ references }, key) => { + if (setStateInsideEffectWithoutDeps) { + return; + } + references.forEach(reference => { + if (setStateInsideEffectWithoutDeps) { + return; + } + const id = reference.identifier; + const isSetState = setStateCallSites.has(id); + if (!isSetState) { + return; + } + let fnScope = reference.from; + while (fnScope != null && fnScope.type !== 'function') { + fnScope = fnScope.upper; + } + const isDirectlyInsideEffect = (fnScope === null || fnScope === void 0 ? void 0 : fnScope.block) === node; + if (isDirectlyInsideEffect) { + setStateInsideEffectWithoutDeps = key; + } + }); + }); + if (setStateInsideEffectWithoutDeps) { + const { suggestedDependencies } = collectRecommendations({ + dependencies, + declaredDependencies: [], + stableDependencies, + externalDependencies: new Set(), + isEffect: true, + }); + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} contains a call to '${setStateInsideEffectWithoutDeps}'. ` + + `Without a list of dependencies, this can lead to an infinite chain of updates. ` + + `To fix this, pass [` + + suggestedDependencies.join(', ') + + `] as a second argument to the ${reactiveHookName} Hook.`, + suggest: [ + { + desc: `Add dependencies array: [${suggestedDependencies.join(', ')}]`, + fix(fixer) { + return fixer.insertTextAfter(node, `, [${suggestedDependencies.join(', ')}]`); + }, + }, + ], + }); + } + return; + } + const declaredDependencies = []; + const externalDependencies = new Set(); + const isArrayExpression = declaredDependenciesNode.type === 'ArrayExpression'; + const isTSAsArrayExpression = declaredDependenciesNode.type === 'TSAsExpression' && + declaredDependenciesNode.expression.type === 'ArrayExpression'; + if (!isArrayExpression && !isTSAsArrayExpression) { + reportProblem({ + node: declaredDependenciesNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} was passed a ` + + 'dependency list that is not an array literal. This means we ' + + "can't statically verify whether you've passed the correct " + + 'dependencies.', + }); + } + else { + const arrayExpression = isTSAsArrayExpression + ? declaredDependenciesNode.expression + : declaredDependenciesNode; + arrayExpression.elements.forEach(declaredDependencyNode => { + if (declaredDependencyNode === null) { + return; + } + if (declaredDependencyNode.type === 'SpreadElement') { + reportProblem({ + node: declaredDependencyNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has a spread ` + + "element in its dependency array. This means we can't " + + "statically verify whether you've passed the " + + 'correct dependencies.', + }); + return; + } + if (useEffectEventVariables.has(declaredDependencyNode)) { + reportProblem({ + node: declaredDependencyNode, + message: 'Functions returned from `useEffectEvent` must not be included in the dependency array. ' + + `Remove \`${getSourceCode().getText(declaredDependencyNode)}\` from the list.`, + suggest: [ + { + desc: `Remove the dependency \`${getSourceCode().getText(declaredDependencyNode)}\``, + fix(fixer) { + return fixer.removeRange(declaredDependencyNode.range); + }, + }, + ], + }); + } + let declaredDependency; + try { + declaredDependency = analyzePropertyChain(declaredDependencyNode, null); + } + catch (error) { + if (error instanceof Error && + /Unsupported node type/.test(error.message)) { + if (declaredDependencyNode.type === 'Literal') { + if (declaredDependencyNode.value && + dependencies.has(declaredDependencyNode.value)) { + reportProblem({ + node: declaredDependencyNode, + message: `The ${declaredDependencyNode.raw} literal is not a valid dependency ` + + `because it never changes. ` + + `Did you mean to include ${declaredDependencyNode.value} in the array instead?`, + }); + } + else { + reportProblem({ + node: declaredDependencyNode, + message: `The ${declaredDependencyNode.raw} literal is not a valid dependency ` + + 'because it never changes. You can safely remove it.', + }); + } + } + else { + reportProblem({ + node: declaredDependencyNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has a ` + + `complex expression in the dependency array. ` + + 'Extract it to a separate variable so it can be statically checked.', + }); + } + return; + } + else { + throw error; + } + } + let maybeID = declaredDependencyNode; + while (maybeID.type === 'MemberExpression' || + maybeID.type === 'OptionalMemberExpression' || + maybeID.type === 'ChainExpression') { + maybeID = maybeID.object || maybeID.expression.object; + } + const isDeclaredInComponent = !componentScope.through.some(ref => ref.identifier === maybeID); + declaredDependencies.push({ + key: declaredDependency, + node: declaredDependencyNode, + }); + if (!isDeclaredInComponent) { + externalDependencies.add(declaredDependency); + } + }); + } + const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies, } = collectRecommendations({ + dependencies, + declaredDependencies, + stableDependencies, + externalDependencies, + isEffect, + }); + let suggestedDeps = suggestedDependencies; + const problemCount = duplicateDependencies.size + + missingDependencies.size + + unnecessaryDependencies.size; + if (problemCount === 0) { + const constructions = scanForConstructions({ + declaredDependencies, + declaredDependenciesNode, + componentScope, + scope, + }); + constructions.forEach(({ construction, isUsedOutsideOfHook, depType }) => { + var _a; + const wrapperHook = depType === 'function' ? 'useCallback' : 'useMemo'; + const constructionType = depType === 'function' ? 'definition' : 'initialization'; + const defaultAdvice = `wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`; + const advice = isUsedOutsideOfHook + ? `To fix this, ${defaultAdvice}` + : `Move it inside the ${reactiveHookName} callback. Alternatively, ${defaultAdvice}`; + const causation = depType === 'conditional' || depType === 'logical expression' + ? 'could make' + : 'makes'; + const message = `The '${construction.name.name}' ${depType} ${causation} the dependencies of ` + + `${reactiveHookName} Hook (at line ${(_a = declaredDependenciesNode.loc) === null || _a === void 0 ? void 0 : _a.start.line}) ` + + `change on every render. ${advice}`; + let suggest; + if (isUsedOutsideOfHook && + construction.type === 'Variable' && + depType === 'function') { + suggest = [ + { + desc: `Wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`, + fix(fixer) { + const [before, after] = wrapperHook === 'useMemo' + ? [`useMemo(() => { return `, '; })'] + : ['useCallback(', ')']; + return [ + fixer.insertTextBefore(construction.node.init, before), + fixer.insertTextAfter(construction.node.init, after), + ]; + }, + }, + ]; + } + reportProblem({ + node: construction.node, + message, + suggest, + }); + }); + return; + } + if (!isEffect && missingDependencies.size > 0) { + suggestedDeps = collectRecommendations({ + dependencies, + declaredDependencies: [], + stableDependencies, + externalDependencies, + isEffect, + }).suggestedDependencies; + } + function areDeclaredDepsAlphabetized() { + if (declaredDependencies.length === 0) { + return true; + } + const declaredDepKeys = declaredDependencies.map(dep => dep.key); + const sortedDeclaredDepKeys = declaredDepKeys.slice().sort(); + return declaredDepKeys.join(',') === sortedDeclaredDepKeys.join(','); + } + if (areDeclaredDepsAlphabetized()) { + suggestedDeps.sort(); + } + function formatDependency(path) { + const members = path.split('.'); + let finalPath = ''; + for (let i = 0; i < members.length; i++) { + if (i !== 0) { + const pathSoFar = members.slice(0, i + 1).join('.'); + const isOptional = optionalChains.get(pathSoFar) === true; + finalPath += isOptional ? '?.' : '.'; + } + finalPath += members[i]; + } + return finalPath; + } + function getWarningMessage(deps, singlePrefix, label, fixVerb) { + if (deps.size === 0) { + return null; + } + return ((deps.size > 1 ? '' : singlePrefix + ' ') + + label + + ' ' + + (deps.size > 1 ? 'dependencies' : 'dependency') + + ': ' + + joinEnglish(Array.from(deps) + .sort() + .map(name => "'" + formatDependency(name) + "'")) + + `. Either ${fixVerb} ${deps.size > 1 ? 'them' : 'it'} or remove the dependency array.`); + } + let extraWarning = ''; + if (unnecessaryDependencies.size > 0) { + let badRef = null; + Array.from(unnecessaryDependencies.keys()).forEach(key => { + if (badRef !== null) { + return; + } + if (key.endsWith('.current')) { + badRef = key; + } + }); + if (badRef !== null) { + extraWarning = + ` Mutable values like '${badRef}' aren't valid dependencies ` + + "because mutating them doesn't re-render the component."; + } + else if (externalDependencies.size > 0) { + const dep = Array.from(externalDependencies)[0]; + if (!scope.set.has(dep)) { + extraWarning = + ` Outer scope values like '${dep}' aren't valid dependencies ` + + `because mutating them doesn't re-render the component.`; + } + } + } + if (!extraWarning && missingDependencies.has('props')) { + const propDep = dependencies.get('props'); + if (propDep == null) { + return; + } + const refs = propDep.references; + if (!Array.isArray(refs)) { + return; + } + let isPropsOnlyUsedInMembers = true; + for (const ref of refs) { + const id = fastFindReferenceWithParent(componentScope.block, ref.identifier); + if (!id) { + isPropsOnlyUsedInMembers = false; + break; + } + const parent = id.parent; + if (parent == null) { + isPropsOnlyUsedInMembers = false; + break; + } + if (parent.type !== 'MemberExpression' && + parent.type !== 'OptionalMemberExpression') { + isPropsOnlyUsedInMembers = false; + break; + } + } + if (isPropsOnlyUsedInMembers) { + extraWarning = + ` However, 'props' will change when *any* prop changes, so the ` + + `preferred fix is to destructure the 'props' object outside of ` + + `the ${reactiveHookName} call and refer to those specific props ` + + `inside ${getSourceCode().getText(reactiveHook)}.`; + } + } + if (!extraWarning && missingDependencies.size > 0) { + let missingCallbackDep = null; + missingDependencies.forEach(missingDep => { + var _a; + if (missingCallbackDep) { + return; + } + const topScopeRef = componentScope.set.get(missingDep); + const usedDep = dependencies.get(missingDep); + if (!(usedDep === null || usedDep === void 0 ? void 0 : usedDep.references) || + ((_a = usedDep === null || usedDep === void 0 ? void 0 : usedDep.references[0]) === null || _a === void 0 ? void 0 : _a.resolved) !== topScopeRef) { + return; + } + const def = topScopeRef === null || topScopeRef === void 0 ? void 0 : topScopeRef.defs[0]; + if (def == null || def.name == null || def.type !== 'Parameter') { + return; + } + let isFunctionCall = false; + let id; + for (const reference of usedDep.references) { + id = reference.identifier; + if (id != null && + id.parent != null && + (id.parent.type === 'CallExpression' || + id.parent.type === 'OptionalCallExpression') && + id.parent.callee === id) { + isFunctionCall = true; + break; + } + } + if (!isFunctionCall) { + return; + } + missingCallbackDep = missingDep; + }); + if (missingCallbackDep !== null) { + extraWarning = + ` If '${missingCallbackDep}' changes too often, ` + + `find the parent component that defines it ` + + `and wrap that definition in useCallback.`; + } + } + if (!extraWarning && missingDependencies.size > 0) { + let setStateRecommendation = null; + for (const missingDep of missingDependencies) { + if (setStateRecommendation !== null) { + break; + } + const usedDep = dependencies.get(missingDep); + const references = usedDep.references; + let id; + let maybeCall; + for (const reference of references) { + id = reference.identifier; + maybeCall = id.parent; + while (maybeCall != null && maybeCall !== componentScope.block) { + if (maybeCall.type === 'CallExpression') { + const correspondingStateVariable = setStateCallSites.get(maybeCall.callee); + if (correspondingStateVariable != null) { + if ('name' in correspondingStateVariable && + correspondingStateVariable.name === missingDep) { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee ? maybeCall.callee.name : '', + form: 'updater', + }; + } + else if (stateVariables.has(id)) { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee ? maybeCall.callee.name : '', + form: 'reducer', + }; + } + else { + const resolved = reference.resolved; + if (resolved != null) { + const def = resolved.defs[0]; + if (def != null && def.type === 'Parameter') { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee + ? maybeCall.callee.name + : '', + form: 'inlineReducer', + }; + } + } + } + break; + } + } + maybeCall = maybeCall.parent; + } + if (setStateRecommendation !== null) { + break; + } + } + } + if (setStateRecommendation !== null) { + switch (setStateRecommendation.form) { + case 'reducer': + extraWarning = + ` You can also replace multiple useState variables with useReducer ` + + `if '${setStateRecommendation.setter}' needs the ` + + `current value of '${setStateRecommendation.missingDep}'.`; + break; + case 'inlineReducer': + extraWarning = + ` If '${setStateRecommendation.setter}' needs the ` + + `current value of '${setStateRecommendation.missingDep}', ` + + `you can also switch to useReducer instead of useState and ` + + `read '${setStateRecommendation.missingDep}' in the reducer.`; + break; + case 'updater': + extraWarning = + ` You can also do a functional update '${setStateRecommendation.setter}(${setStateRecommendation.missingDep.slice(0, 1)} => ...)' if you only need '${setStateRecommendation.missingDep}'` + ` in the '${setStateRecommendation.setter}' call.`; + break; + default: + throw new Error('Unknown case.'); + } + } + } + reportProblem({ + node: declaredDependenciesNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has ` + + (getWarningMessage(missingDependencies, 'a', 'missing', 'include') || + getWarningMessage(unnecessaryDependencies, 'an', 'unnecessary', 'exclude') || + getWarningMessage(duplicateDependencies, 'a', 'duplicate', 'omit')) + + extraWarning, + suggest: [ + { + desc: `Update the dependencies array to be: [${suggestedDeps + .map(formatDependency) + .join(', ')}]`, + fix(fixer) { + return fixer.replaceText(declaredDependenciesNode, `[${suggestedDeps.map(formatDependency).join(', ')}]`); + }, + }, + ], + }); + } + function visitCallExpression(node) { + const callbackIndex = getReactiveHookCallbackIndex(node.callee, options); + if (callbackIndex === -1) { + return; + } + let callback = node.arguments[callbackIndex]; + const reactiveHook = node.callee; + const nodeWithoutNamespace = getNodeWithoutReactNamespace(reactiveHook); + const reactiveHookName = 'name' in nodeWithoutNamespace ? nodeWithoutNamespace.name : ''; + const maybeNode = node.arguments[callbackIndex + 1]; + const declaredDependenciesNode = maybeNode && + !(maybeNode.type === 'Identifier' && maybeNode.name === 'undefined') + ? maybeNode + : undefined; + const isEffect = /Effect($|[^a-z])/g.test(reactiveHookName); + if (!callback) { + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} requires an effect callback. ` + + `Did you forget to pass a callback to the hook?`, + }); + return; + } + if (!declaredDependenciesNode && !isEffect) { + if (reactiveHookName === 'useMemo' || + reactiveHookName === 'useCallback') { + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} does nothing when called with ` + + `only one argument. Did you forget to pass an array of ` + + `dependencies?`, + }); + } + return; + } + while (callback.type === 'TSAsExpression' || + callback.type === 'AsExpression') { + callback = callback.expression; + } + switch (callback.type) { + case 'FunctionExpression': + case 'ArrowFunctionExpression': + visitFunctionWithDependencies(callback, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + case 'Identifier': + if (!declaredDependenciesNode) { + return; + } + if ('elements' in declaredDependenciesNode && + declaredDependenciesNode.elements && + declaredDependenciesNode.elements.some(el => el && el.type === 'Identifier' && el.name === callback.name)) { + return; + } + const variable = getScope(callback).set.get(callback.name); + if (variable == null || variable.defs == null) { + return; + } + const def = variable.defs[0]; + if (!def || !def.node) { + break; + } + if (def.type === 'Parameter') { + reportProblem({ + node: reactiveHook, + message: getUnknownDependenciesMessage(reactiveHookName), + }); + return; + } + if (def.type !== 'Variable' && def.type !== 'FunctionName') { + break; + } + switch (def.node.type) { + case 'FunctionDeclaration': + visitFunctionWithDependencies(def.node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + case 'VariableDeclarator': + const init = def.node.init; + if (!init) { + break; + } + switch (init.type) { + case 'ArrowFunctionExpression': + case 'FunctionExpression': + visitFunctionWithDependencies(init, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + } + break; + } + break; + default: + reportProblem({ + node: reactiveHook, + message: getUnknownDependenciesMessage(reactiveHookName), + }); + return; + } + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} has a missing dependency: '${callback.name}'. ` + + `Either include it or remove the dependency array.`, + suggest: [ + { + desc: `Update the dependencies array to be: [${callback.name}]`, + fix(fixer) { + return fixer.replaceText(declaredDependenciesNode, `[${callback.name}]`); + }, + }, + ], + }); + } + return { + CallExpression: visitCallExpression, + }; + }, +}; +function collectRecommendations({ dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect, }) { + const depTree = createDepTree(); + function createDepTree() { + return { + isUsed: false, + isSatisfiedRecursively: false, + isSubtreeUsed: false, + children: new Map(), + }; + } + dependencies.forEach((_, key) => { + const node = getOrCreateNodeByPath(depTree, key); + node.isUsed = true; + markAllParentsByPath(depTree, key, parent => { + parent.isSubtreeUsed = true; + }); + }); + declaredDependencies.forEach(({ key }) => { + const node = getOrCreateNodeByPath(depTree, key); + node.isSatisfiedRecursively = true; + }); + stableDependencies.forEach(key => { + const node = getOrCreateNodeByPath(depTree, key); + node.isSatisfiedRecursively = true; + }); + function getOrCreateNodeByPath(rootNode, path) { + const keys = path.split('.'); + let node = rootNode; + for (const key of keys) { + let child = node.children.get(key); + if (!child) { + child = createDepTree(); + node.children.set(key, child); + } + node = child; + } + return node; + } + function markAllParentsByPath(rootNode, path, fn) { + const keys = path.split('.'); + let node = rootNode; + for (const key of keys) { + const child = node.children.get(key); + if (!child) { + return; + } + fn(child); + node = child; + } + } + const missingDependencies = new Set(); + const satisfyingDependencies = new Set(); + scanTreeRecursively(depTree, missingDependencies, satisfyingDependencies, key => key); + function scanTreeRecursively(node, missingPaths, satisfyingPaths, keyToPath) { + node.children.forEach((child, key) => { + const path = keyToPath(key); + if (child.isSatisfiedRecursively) { + if (child.isSubtreeUsed) { + satisfyingPaths.add(path); + } + return; + } + if (child.isUsed) { + missingPaths.add(path); + return; + } + scanTreeRecursively(child, missingPaths, satisfyingPaths, childKey => path + '.' + childKey); + }); + } + const suggestedDependencies = []; + const unnecessaryDependencies = new Set(); + const duplicateDependencies = new Set(); + declaredDependencies.forEach(({ key }) => { + if (satisfyingDependencies.has(key)) { + if (suggestedDependencies.indexOf(key) === -1) { + suggestedDependencies.push(key); + } + else { + duplicateDependencies.add(key); + } + } + else { + if (isEffect && + !key.endsWith('.current') && + !externalDependencies.has(key)) { + if (suggestedDependencies.indexOf(key) === -1) { + suggestedDependencies.push(key); + } + } + else { + unnecessaryDependencies.add(key); + } + } + }); + missingDependencies.forEach(key => { + suggestedDependencies.push(key); + }); + return { + suggestedDependencies, + unnecessaryDependencies, + duplicateDependencies, + missingDependencies, + }; +} +function getConstructionExpressionType(node) { + switch (node.type) { + case 'ObjectExpression': + return 'object'; + case 'ArrayExpression': + return 'array'; + case 'ArrowFunctionExpression': + case 'FunctionExpression': + return 'function'; + case 'ClassExpression': + return 'class'; + case 'ConditionalExpression': + if (getConstructionExpressionType(node.consequent) != null || + getConstructionExpressionType(node.alternate) != null) { + return 'conditional'; + } + return null; + case 'LogicalExpression': + if (getConstructionExpressionType(node.left) != null || + getConstructionExpressionType(node.right) != null) { + return 'logical expression'; + } + return null; + case 'JSXFragment': + return 'JSX fragment'; + case 'JSXElement': + return 'JSX element'; + case 'AssignmentExpression': + if (getConstructionExpressionType(node.right) != null) { + return 'assignment expression'; + } + return null; + case 'NewExpression': + return 'object construction'; + case 'Literal': + if (node.value instanceof RegExp) { + return 'regular expression'; + } + return null; + case 'TypeCastExpression': + case 'AsExpression': + case 'TSAsExpression': + return getConstructionExpressionType(node.expression); + } + return null; +} +function scanForConstructions({ declaredDependencies, declaredDependenciesNode, componentScope, scope, }) { + const constructions = declaredDependencies + .map(({ key }) => { + const ref = componentScope.variables.find(v => v.name === key); + if (ref == null) { + return null; + } + const node = ref.defs[0]; + if (node == null) { + return null; + } + if (node.type === 'Variable' && + node.node.type === 'VariableDeclarator' && + node.node.id.type === 'Identifier' && + node.node.init != null) { + const constantExpressionType = getConstructionExpressionType(node.node.init); + if (constantExpressionType) { + return [ref, constantExpressionType]; + } + } + if (node.type === 'FunctionName' && + node.node.type === 'FunctionDeclaration') { + return [ref, 'function']; + } + if (node.type === 'ClassName' && node.node.type === 'ClassDeclaration') { + return [ref, 'class']; + } + return null; + }) + .filter(Boolean); + function isUsedOutsideOfHook(ref) { + let foundWriteExpr = false; + for (const reference of ref.references) { + if (reference.writeExpr) { + if (foundWriteExpr) { + return true; + } + else { + foundWriteExpr = true; + continue; + } + } + let currentScope = reference.from; + while (currentScope !== scope && currentScope != null) { + currentScope = currentScope.upper; + } + if (currentScope !== scope) { + if (!isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) { + return true; + } + } + } + return false; + } + return constructions.map(([ref, depType]) => ({ + construction: ref.defs[0], + depType, + isUsedOutsideOfHook: isUsedOutsideOfHook(ref), + })); +} +function getDependency(node) { + if (node.parent && + (node.parent.type === 'MemberExpression' || + node.parent.type === 'OptionalMemberExpression') && + node.parent.object === node && + 'name' in node.parent.property && + node.parent.property.name !== 'current' && + !node.parent.computed && + !(node.parent.parent != null && + (node.parent.parent.type === 'CallExpression' || + node.parent.parent.type === 'OptionalCallExpression') && + node.parent.parent.callee === node.parent)) { + return getDependency(node.parent); + } + else if (node.type === 'MemberExpression' && + node.parent && + node.parent.type === 'AssignmentExpression' && + node.parent.left === node) { + return node.object; + } + else { + return node; + } +} +function markNode(node, optionalChains, result) { + if (optionalChains) { + if ('optional' in node && node.optional) { + if (!optionalChains.has(result)) { + optionalChains.set(result, true); + } + } + else { + optionalChains.set(result, false); + } + } +} +function analyzePropertyChain(node, optionalChains) { + if (node.type === 'Identifier' || node.type === 'JSXIdentifier') { + const result = node.name; + if (optionalChains) { + optionalChains.set(result, false); + } + return result; + } + else if (node.type === 'MemberExpression' && !node.computed) { + const object = analyzePropertyChain(node.object, optionalChains); + const property = analyzePropertyChain(node.property, null); + const result = `${object}.${property}`; + markNode(node, optionalChains, result); + return result; + } + else if (node.type === 'OptionalMemberExpression' && !node.computed) { + const object = analyzePropertyChain(node.object, optionalChains); + const property = analyzePropertyChain(node.property, null); + const result = `${object}.${property}`; + markNode(node, optionalChains, result); + return result; + } + else if (node.type === 'ChainExpression' && + (!('computed' in node) || !node.computed)) { + const expression = node.expression; + if (expression.type === 'CallExpression') { + throw new Error(`Unsupported node type: ${expression.type}`); + } + const object = analyzePropertyChain(expression.object, optionalChains); + const property = analyzePropertyChain(expression.property, null); + const result = `${object}.${property}`; + markNode(expression, optionalChains, result); + return result; + } + else { + throw new Error(`Unsupported node type: ${node.type}`); + } +} +function getNodeWithoutReactNamespace(node) { + if (node.type === 'MemberExpression' && + node.object.type === 'Identifier' && + node.object.name === 'React' && + node.property.type === 'Identifier' && + !node.computed) { + return node.property; + } + return node; +} +function getReactiveHookCallbackIndex(calleeNode, options) { + const node = getNodeWithoutReactNamespace(calleeNode); + if (node.type !== 'Identifier') { + return -1; + } + switch (node.name) { + case 'useEffect': + case 'useLayoutEffect': + case 'useCallback': + case 'useMemo': + return 0; + case 'useImperativeHandle': + return 1; + default: + if (node === calleeNode && options && options.additionalHooks) { + let name; + try { + name = analyzePropertyChain(node, null); + } + catch (error) { + if (error instanceof Error && + /Unsupported node type/.test(error.message)) { + return 0; + } + else { + throw error; + } + } + return options.additionalHooks.test(name) ? 0 : -1; + } + else { + return -1; + } + } +} +function fastFindReferenceWithParent(start, target) { + const queue = [start]; + let item; + while (queue.length) { + item = queue.shift(); + if (isSameIdentifier(item, target)) { + return item; + } + if (!isAncestorNodeOf(item, target)) { + continue; + } + for (const [key, value] of Object.entries(item)) { + if (key === 'parent') { + continue; + } + if (isNodeLike(value)) { + value.parent = item; + queue.push(value); + } + else if (Array.isArray(value)) { + value.forEach(val => { + if (isNodeLike(val)) { + val.parent = item; + queue.push(val); + } + }); + } + } + } + return null; +} +function joinEnglish(arr) { + let s = ''; + for (let i = 0; i < arr.length; i++) { + s += arr[i]; + if (i === 0 && arr.length === 2) { + s += ' and '; + } + else if (i === arr.length - 2 && arr.length > 2) { + s += ', and '; + } + else if (i < arr.length - 1) { + s += ', '; + } + } + return s; +} +function isNodeLike(val) { + return (typeof val === 'object' && + val !== null && + !Array.isArray(val) && + 'type' in val && + typeof val.type === 'string'); +} +function isSameIdentifier(a, b) { + return ((a.type === 'Identifier' || a.type === 'JSXIdentifier') && + a.type === b.type && + a.name === b.name && + !!a.range && + !!b.range && + a.range[0] === b.range[0] && + a.range[1] === b.range[1]); +} +function isAncestorNodeOf(a, b) { + return (!!a.range && + !!b.range && + a.range[0] <= b.range[0] && + a.range[1] >= b.range[1]); +} +function isUseEffectEventIdentifier$1(node) { + { + return node.type === 'Identifier' && node.name === 'useEffectEvent'; + } +} +function getUnknownDependenciesMessage(reactiveHookName) { + return (`React Hook ${reactiveHookName} received a function whose dependencies ` + + `are unknown. Pass an inline function instead.`); +} + +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +} + +var invariant_1; +var hasRequiredInvariant; + +function requireInvariant () { + if (hasRequiredInvariant) return invariant_1; + hasRequiredInvariant = 1; + + var invariant = function(condition, format, a, b, c, d, e, f) { + { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); + } + } + + if (!condition) { + var error; + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error( + format.replace(/%s/g, function() { return args[argIndex++]; }) + ); + error.name = 'Invariant Violation'; + } + + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; + } + }; + + invariant_1 = invariant; + return invariant_1; +} + +var invariantExports = requireInvariant(); +var invariant = /*@__PURE__*/getDefaultExportFromCjs(invariantExports); + +var lib$3 = {}; + +var isReactComponent = {}; + +var buildMatchMemberExpression = {}; + +var matchesPattern = {}; + +var generated$3 = {}; + +var shallowEqual = {}; + +var hasRequiredShallowEqual; + +function requireShallowEqual () { + if (hasRequiredShallowEqual) return shallowEqual; + hasRequiredShallowEqual = 1; + + Object.defineProperty(shallowEqual, "__esModule", { + value: true + }); + shallowEqual.default = shallowEqual$1; + function shallowEqual$1(actual, expected) { + const keys = Object.keys(expected); + for (const key of keys) { + if (actual[key] !== expected[key]) { + return false; + } + } + return true; + } + + + return shallowEqual; +} + +var deprecationWarning = {}; + +var hasRequiredDeprecationWarning; + +function requireDeprecationWarning () { + if (hasRequiredDeprecationWarning) return deprecationWarning; + hasRequiredDeprecationWarning = 1; + + Object.defineProperty(deprecationWarning, "__esModule", { + value: true + }); + deprecationWarning.default = deprecationWarning$1; + const warnings = new Set(); + function deprecationWarning$1(oldName, newName, prefix = "") { + if (warnings.has(oldName)) return; + warnings.add(oldName); + const { + internal, + trace + } = captureShortStackTrace(1, 2); + if (internal) { + return; + } + console.warn(`${prefix}\`${oldName}\` has been deprecated, please migrate to \`${newName}\`\n${trace}`); + } + function captureShortStackTrace(skip, length) { + const { + stackTraceLimit, + prepareStackTrace + } = Error; + let stackTrace; + Error.stackTraceLimit = 1 + skip + length; + Error.prepareStackTrace = function (err, stack) { + stackTrace = stack; + }; + Error.stackTraceLimit = stackTraceLimit; + Error.prepareStackTrace = prepareStackTrace; + if (!stackTrace) return { + internal: false, + trace: "" + }; + const shortStackTrace = stackTrace.slice(1 + skip, 1 + skip + length); + return { + internal: /[\\/]@babel[\\/]/.test(shortStackTrace[1].getFileName()), + trace: shortStackTrace.map(frame => ` at ${frame}`).join("\n") + }; + } + + + return deprecationWarning; +} + +var hasRequiredGenerated$3; + +function requireGenerated$3 () { + if (hasRequiredGenerated$3) return generated$3; + hasRequiredGenerated$3 = 1; + + Object.defineProperty(generated$3, "__esModule", { + value: true + }); + generated$3.isAccessor = isAccessor; + generated$3.isAnyTypeAnnotation = isAnyTypeAnnotation; + generated$3.isArgumentPlaceholder = isArgumentPlaceholder; + generated$3.isArrayExpression = isArrayExpression; + generated$3.isArrayPattern = isArrayPattern; + generated$3.isArrayTypeAnnotation = isArrayTypeAnnotation; + generated$3.isArrowFunctionExpression = isArrowFunctionExpression; + generated$3.isAssignmentExpression = isAssignmentExpression; + generated$3.isAssignmentPattern = isAssignmentPattern; + generated$3.isAwaitExpression = isAwaitExpression; + generated$3.isBigIntLiteral = isBigIntLiteral; + generated$3.isBinary = isBinary; + generated$3.isBinaryExpression = isBinaryExpression; + generated$3.isBindExpression = isBindExpression; + generated$3.isBlock = isBlock; + generated$3.isBlockParent = isBlockParent; + generated$3.isBlockStatement = isBlockStatement; + generated$3.isBooleanLiteral = isBooleanLiteral; + generated$3.isBooleanLiteralTypeAnnotation = isBooleanLiteralTypeAnnotation; + generated$3.isBooleanTypeAnnotation = isBooleanTypeAnnotation; + generated$3.isBreakStatement = isBreakStatement; + generated$3.isCallExpression = isCallExpression; + generated$3.isCatchClause = isCatchClause; + generated$3.isClass = isClass; + generated$3.isClassAccessorProperty = isClassAccessorProperty; + generated$3.isClassBody = isClassBody; + generated$3.isClassDeclaration = isClassDeclaration; + generated$3.isClassExpression = isClassExpression; + generated$3.isClassImplements = isClassImplements; + generated$3.isClassMethod = isClassMethod; + generated$3.isClassPrivateMethod = isClassPrivateMethod; + generated$3.isClassPrivateProperty = isClassPrivateProperty; + generated$3.isClassProperty = isClassProperty; + generated$3.isCompletionStatement = isCompletionStatement; + generated$3.isConditional = isConditional; + generated$3.isConditionalExpression = isConditionalExpression; + generated$3.isContinueStatement = isContinueStatement; + generated$3.isDebuggerStatement = isDebuggerStatement; + generated$3.isDecimalLiteral = isDecimalLiteral; + generated$3.isDeclaration = isDeclaration; + generated$3.isDeclareClass = isDeclareClass; + generated$3.isDeclareExportAllDeclaration = isDeclareExportAllDeclaration; + generated$3.isDeclareExportDeclaration = isDeclareExportDeclaration; + generated$3.isDeclareFunction = isDeclareFunction; + generated$3.isDeclareInterface = isDeclareInterface; + generated$3.isDeclareModule = isDeclareModule; + generated$3.isDeclareModuleExports = isDeclareModuleExports; + generated$3.isDeclareOpaqueType = isDeclareOpaqueType; + generated$3.isDeclareTypeAlias = isDeclareTypeAlias; + generated$3.isDeclareVariable = isDeclareVariable; + generated$3.isDeclaredPredicate = isDeclaredPredicate; + generated$3.isDecorator = isDecorator; + generated$3.isDirective = isDirective; + generated$3.isDirectiveLiteral = isDirectiveLiteral; + generated$3.isDoExpression = isDoExpression; + generated$3.isDoWhileStatement = isDoWhileStatement; + generated$3.isEmptyStatement = isEmptyStatement; + generated$3.isEmptyTypeAnnotation = isEmptyTypeAnnotation; + generated$3.isEnumBody = isEnumBody; + generated$3.isEnumBooleanBody = isEnumBooleanBody; + generated$3.isEnumBooleanMember = isEnumBooleanMember; + generated$3.isEnumDeclaration = isEnumDeclaration; + generated$3.isEnumDefaultedMember = isEnumDefaultedMember; + generated$3.isEnumMember = isEnumMember; + generated$3.isEnumNumberBody = isEnumNumberBody; + generated$3.isEnumNumberMember = isEnumNumberMember; + generated$3.isEnumStringBody = isEnumStringBody; + generated$3.isEnumStringMember = isEnumStringMember; + generated$3.isEnumSymbolBody = isEnumSymbolBody; + generated$3.isExistsTypeAnnotation = isExistsTypeAnnotation; + generated$3.isExportAllDeclaration = isExportAllDeclaration; + generated$3.isExportDeclaration = isExportDeclaration; + generated$3.isExportDefaultDeclaration = isExportDefaultDeclaration; + generated$3.isExportDefaultSpecifier = isExportDefaultSpecifier; + generated$3.isExportNamedDeclaration = isExportNamedDeclaration; + generated$3.isExportNamespaceSpecifier = isExportNamespaceSpecifier; + generated$3.isExportSpecifier = isExportSpecifier; + generated$3.isExpression = isExpression; + generated$3.isExpressionStatement = isExpressionStatement; + generated$3.isExpressionWrapper = isExpressionWrapper; + generated$3.isFile = isFile; + generated$3.isFlow = isFlow; + generated$3.isFlowBaseAnnotation = isFlowBaseAnnotation; + generated$3.isFlowDeclaration = isFlowDeclaration; + generated$3.isFlowPredicate = isFlowPredicate; + generated$3.isFlowType = isFlowType; + generated$3.isFor = isFor; + generated$3.isForInStatement = isForInStatement; + generated$3.isForOfStatement = isForOfStatement; + generated$3.isForStatement = isForStatement; + generated$3.isForXStatement = isForXStatement; + generated$3.isFunction = isFunction; + generated$3.isFunctionDeclaration = isFunctionDeclaration; + generated$3.isFunctionExpression = isFunctionExpression; + generated$3.isFunctionParent = isFunctionParent; + generated$3.isFunctionTypeAnnotation = isFunctionTypeAnnotation; + generated$3.isFunctionTypeParam = isFunctionTypeParam; + generated$3.isGenericTypeAnnotation = isGenericTypeAnnotation; + generated$3.isIdentifier = isIdentifier; + generated$3.isIfStatement = isIfStatement; + generated$3.isImmutable = isImmutable; + generated$3.isImport = isImport; + generated$3.isImportAttribute = isImportAttribute; + generated$3.isImportDeclaration = isImportDeclaration; + generated$3.isImportDefaultSpecifier = isImportDefaultSpecifier; + generated$3.isImportExpression = isImportExpression; + generated$3.isImportNamespaceSpecifier = isImportNamespaceSpecifier; + generated$3.isImportOrExportDeclaration = isImportOrExportDeclaration; + generated$3.isImportSpecifier = isImportSpecifier; + generated$3.isIndexedAccessType = isIndexedAccessType; + generated$3.isInferredPredicate = isInferredPredicate; + generated$3.isInterfaceDeclaration = isInterfaceDeclaration; + generated$3.isInterfaceExtends = isInterfaceExtends; + generated$3.isInterfaceTypeAnnotation = isInterfaceTypeAnnotation; + generated$3.isInterpreterDirective = isInterpreterDirective; + generated$3.isIntersectionTypeAnnotation = isIntersectionTypeAnnotation; + generated$3.isJSX = isJSX; + generated$3.isJSXAttribute = isJSXAttribute; + generated$3.isJSXClosingElement = isJSXClosingElement; + generated$3.isJSXClosingFragment = isJSXClosingFragment; + generated$3.isJSXElement = isJSXElement; + generated$3.isJSXEmptyExpression = isJSXEmptyExpression; + generated$3.isJSXExpressionContainer = isJSXExpressionContainer; + generated$3.isJSXFragment = isJSXFragment; + generated$3.isJSXIdentifier = isJSXIdentifier; + generated$3.isJSXMemberExpression = isJSXMemberExpression; + generated$3.isJSXNamespacedName = isJSXNamespacedName; + generated$3.isJSXOpeningElement = isJSXOpeningElement; + generated$3.isJSXOpeningFragment = isJSXOpeningFragment; + generated$3.isJSXSpreadAttribute = isJSXSpreadAttribute; + generated$3.isJSXSpreadChild = isJSXSpreadChild; + generated$3.isJSXText = isJSXText; + generated$3.isLVal = isLVal; + generated$3.isLabeledStatement = isLabeledStatement; + generated$3.isLiteral = isLiteral; + generated$3.isLogicalExpression = isLogicalExpression; + generated$3.isLoop = isLoop; + generated$3.isMemberExpression = isMemberExpression; + generated$3.isMetaProperty = isMetaProperty; + generated$3.isMethod = isMethod; + generated$3.isMiscellaneous = isMiscellaneous; + generated$3.isMixedTypeAnnotation = isMixedTypeAnnotation; + generated$3.isModuleDeclaration = isModuleDeclaration; + generated$3.isModuleExpression = isModuleExpression; + generated$3.isModuleSpecifier = isModuleSpecifier; + generated$3.isNewExpression = isNewExpression; + generated$3.isNoop = isNoop; + generated$3.isNullLiteral = isNullLiteral; + generated$3.isNullLiteralTypeAnnotation = isNullLiteralTypeAnnotation; + generated$3.isNullableTypeAnnotation = isNullableTypeAnnotation; + generated$3.isNumberLiteral = isNumberLiteral; + generated$3.isNumberLiteralTypeAnnotation = isNumberLiteralTypeAnnotation; + generated$3.isNumberTypeAnnotation = isNumberTypeAnnotation; + generated$3.isNumericLiteral = isNumericLiteral; + generated$3.isObjectExpression = isObjectExpression; + generated$3.isObjectMember = isObjectMember; + generated$3.isObjectMethod = isObjectMethod; + generated$3.isObjectPattern = isObjectPattern; + generated$3.isObjectProperty = isObjectProperty; + generated$3.isObjectTypeAnnotation = isObjectTypeAnnotation; + generated$3.isObjectTypeCallProperty = isObjectTypeCallProperty; + generated$3.isObjectTypeIndexer = isObjectTypeIndexer; + generated$3.isObjectTypeInternalSlot = isObjectTypeInternalSlot; + generated$3.isObjectTypeProperty = isObjectTypeProperty; + generated$3.isObjectTypeSpreadProperty = isObjectTypeSpreadProperty; + generated$3.isOpaqueType = isOpaqueType; + generated$3.isOptionalCallExpression = isOptionalCallExpression; + generated$3.isOptionalIndexedAccessType = isOptionalIndexedAccessType; + generated$3.isOptionalMemberExpression = isOptionalMemberExpression; + generated$3.isParenthesizedExpression = isParenthesizedExpression; + generated$3.isPattern = isPattern; + generated$3.isPatternLike = isPatternLike; + generated$3.isPipelineBareFunction = isPipelineBareFunction; + generated$3.isPipelinePrimaryTopicReference = isPipelinePrimaryTopicReference; + generated$3.isPipelineTopicExpression = isPipelineTopicExpression; + generated$3.isPlaceholder = isPlaceholder; + generated$3.isPrivate = isPrivate; + generated$3.isPrivateName = isPrivateName; + generated$3.isProgram = isProgram; + generated$3.isProperty = isProperty; + generated$3.isPureish = isPureish; + generated$3.isQualifiedTypeIdentifier = isQualifiedTypeIdentifier; + generated$3.isRecordExpression = isRecordExpression; + generated$3.isRegExpLiteral = isRegExpLiteral; + generated$3.isRegexLiteral = isRegexLiteral; + generated$3.isRestElement = isRestElement; + generated$3.isRestProperty = isRestProperty; + generated$3.isReturnStatement = isReturnStatement; + generated$3.isScopable = isScopable; + generated$3.isSequenceExpression = isSequenceExpression; + generated$3.isSpreadElement = isSpreadElement; + generated$3.isSpreadProperty = isSpreadProperty; + generated$3.isStandardized = isStandardized; + generated$3.isStatement = isStatement; + generated$3.isStaticBlock = isStaticBlock; + generated$3.isStringLiteral = isStringLiteral; + generated$3.isStringLiteralTypeAnnotation = isStringLiteralTypeAnnotation; + generated$3.isStringTypeAnnotation = isStringTypeAnnotation; + generated$3.isSuper = isSuper; + generated$3.isSwitchCase = isSwitchCase; + generated$3.isSwitchStatement = isSwitchStatement; + generated$3.isSymbolTypeAnnotation = isSymbolTypeAnnotation; + generated$3.isTSAnyKeyword = isTSAnyKeyword; + generated$3.isTSArrayType = isTSArrayType; + generated$3.isTSAsExpression = isTSAsExpression; + generated$3.isTSBaseType = isTSBaseType; + generated$3.isTSBigIntKeyword = isTSBigIntKeyword; + generated$3.isTSBooleanKeyword = isTSBooleanKeyword; + generated$3.isTSCallSignatureDeclaration = isTSCallSignatureDeclaration; + generated$3.isTSConditionalType = isTSConditionalType; + generated$3.isTSConstructSignatureDeclaration = isTSConstructSignatureDeclaration; + generated$3.isTSConstructorType = isTSConstructorType; + generated$3.isTSDeclareFunction = isTSDeclareFunction; + generated$3.isTSDeclareMethod = isTSDeclareMethod; + generated$3.isTSEntityName = isTSEntityName; + generated$3.isTSEnumDeclaration = isTSEnumDeclaration; + generated$3.isTSEnumMember = isTSEnumMember; + generated$3.isTSExportAssignment = isTSExportAssignment; + generated$3.isTSExpressionWithTypeArguments = isTSExpressionWithTypeArguments; + generated$3.isTSExternalModuleReference = isTSExternalModuleReference; + generated$3.isTSFunctionType = isTSFunctionType; + generated$3.isTSImportEqualsDeclaration = isTSImportEqualsDeclaration; + generated$3.isTSImportType = isTSImportType; + generated$3.isTSIndexSignature = isTSIndexSignature; + generated$3.isTSIndexedAccessType = isTSIndexedAccessType; + generated$3.isTSInferType = isTSInferType; + generated$3.isTSInstantiationExpression = isTSInstantiationExpression; + generated$3.isTSInterfaceBody = isTSInterfaceBody; + generated$3.isTSInterfaceDeclaration = isTSInterfaceDeclaration; + generated$3.isTSIntersectionType = isTSIntersectionType; + generated$3.isTSIntrinsicKeyword = isTSIntrinsicKeyword; + generated$3.isTSLiteralType = isTSLiteralType; + generated$3.isTSMappedType = isTSMappedType; + generated$3.isTSMethodSignature = isTSMethodSignature; + generated$3.isTSModuleBlock = isTSModuleBlock; + generated$3.isTSModuleDeclaration = isTSModuleDeclaration; + generated$3.isTSNamedTupleMember = isTSNamedTupleMember; + generated$3.isTSNamespaceExportDeclaration = isTSNamespaceExportDeclaration; + generated$3.isTSNeverKeyword = isTSNeverKeyword; + generated$3.isTSNonNullExpression = isTSNonNullExpression; + generated$3.isTSNullKeyword = isTSNullKeyword; + generated$3.isTSNumberKeyword = isTSNumberKeyword; + generated$3.isTSObjectKeyword = isTSObjectKeyword; + generated$3.isTSOptionalType = isTSOptionalType; + generated$3.isTSParameterProperty = isTSParameterProperty; + generated$3.isTSParenthesizedType = isTSParenthesizedType; + generated$3.isTSPropertySignature = isTSPropertySignature; + generated$3.isTSQualifiedName = isTSQualifiedName; + generated$3.isTSRestType = isTSRestType; + generated$3.isTSSatisfiesExpression = isTSSatisfiesExpression; + generated$3.isTSStringKeyword = isTSStringKeyword; + generated$3.isTSSymbolKeyword = isTSSymbolKeyword; + generated$3.isTSThisType = isTSThisType; + generated$3.isTSTupleType = isTSTupleType; + generated$3.isTSType = isTSType; + generated$3.isTSTypeAliasDeclaration = isTSTypeAliasDeclaration; + generated$3.isTSTypeAnnotation = isTSTypeAnnotation; + generated$3.isTSTypeAssertion = isTSTypeAssertion; + generated$3.isTSTypeElement = isTSTypeElement; + generated$3.isTSTypeLiteral = isTSTypeLiteral; + generated$3.isTSTypeOperator = isTSTypeOperator; + generated$3.isTSTypeParameter = isTSTypeParameter; + generated$3.isTSTypeParameterDeclaration = isTSTypeParameterDeclaration; + generated$3.isTSTypeParameterInstantiation = isTSTypeParameterInstantiation; + generated$3.isTSTypePredicate = isTSTypePredicate; + generated$3.isTSTypeQuery = isTSTypeQuery; + generated$3.isTSTypeReference = isTSTypeReference; + generated$3.isTSUndefinedKeyword = isTSUndefinedKeyword; + generated$3.isTSUnionType = isTSUnionType; + generated$3.isTSUnknownKeyword = isTSUnknownKeyword; + generated$3.isTSVoidKeyword = isTSVoidKeyword; + generated$3.isTaggedTemplateExpression = isTaggedTemplateExpression; + generated$3.isTemplateElement = isTemplateElement; + generated$3.isTemplateLiteral = isTemplateLiteral; + generated$3.isTerminatorless = isTerminatorless; + generated$3.isThisExpression = isThisExpression; + generated$3.isThisTypeAnnotation = isThisTypeAnnotation; + generated$3.isThrowStatement = isThrowStatement; + generated$3.isTopicReference = isTopicReference; + generated$3.isTryStatement = isTryStatement; + generated$3.isTupleExpression = isTupleExpression; + generated$3.isTupleTypeAnnotation = isTupleTypeAnnotation; + generated$3.isTypeAlias = isTypeAlias; + generated$3.isTypeAnnotation = isTypeAnnotation; + generated$3.isTypeCastExpression = isTypeCastExpression; + generated$3.isTypeParameter = isTypeParameter; + generated$3.isTypeParameterDeclaration = isTypeParameterDeclaration; + generated$3.isTypeParameterInstantiation = isTypeParameterInstantiation; + generated$3.isTypeScript = isTypeScript; + generated$3.isTypeofTypeAnnotation = isTypeofTypeAnnotation; + generated$3.isUnaryExpression = isUnaryExpression; + generated$3.isUnaryLike = isUnaryLike; + generated$3.isUnionTypeAnnotation = isUnionTypeAnnotation; + generated$3.isUpdateExpression = isUpdateExpression; + generated$3.isUserWhitespacable = isUserWhitespacable; + generated$3.isV8IntrinsicIdentifier = isV8IntrinsicIdentifier; + generated$3.isVariableDeclaration = isVariableDeclaration; + generated$3.isVariableDeclarator = isVariableDeclarator; + generated$3.isVariance = isVariance; + generated$3.isVoidTypeAnnotation = isVoidTypeAnnotation; + generated$3.isWhile = isWhile; + generated$3.isWhileStatement = isWhileStatement; + generated$3.isWithStatement = isWithStatement; + generated$3.isYieldExpression = isYieldExpression; + var _shallowEqual = requireShallowEqual(); + var _deprecationWarning = requireDeprecationWarning(); + function isArrayExpression(node, opts) { + if (!node) return false; + if (node.type !== "ArrayExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAssignmentExpression(node, opts) { + if (!node) return false; + if (node.type !== "AssignmentExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBinaryExpression(node, opts) { + if (!node) return false; + if (node.type !== "BinaryExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterpreterDirective(node, opts) { + if (!node) return false; + if (node.type !== "InterpreterDirective") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDirective(node, opts) { + if (!node) return false; + if (node.type !== "Directive") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDirectiveLiteral(node, opts) { + if (!node) return false; + if (node.type !== "DirectiveLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlockStatement(node, opts) { + if (!node) return false; + if (node.type !== "BlockStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBreakStatement(node, opts) { + if (!node) return false; + if (node.type !== "BreakStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCallExpression(node, opts) { + if (!node) return false; + if (node.type !== "CallExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCatchClause(node, opts) { + if (!node) return false; + if (node.type !== "CatchClause") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isConditionalExpression(node, opts) { + if (!node) return false; + if (node.type !== "ConditionalExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isContinueStatement(node, opts) { + if (!node) return false; + if (node.type !== "ContinueStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDebuggerStatement(node, opts) { + if (!node) return false; + if (node.type !== "DebuggerStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDoWhileStatement(node, opts) { + if (!node) return false; + if (node.type !== "DoWhileStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEmptyStatement(node, opts) { + if (!node) return false; + if (node.type !== "EmptyStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpressionStatement(node, opts) { + if (!node) return false; + if (node.type !== "ExpressionStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFile(node, opts) { + if (!node) return false; + if (node.type !== "File") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForInStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForInStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "FunctionDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionExpression(node, opts) { + if (!node) return false; + if (node.type !== "FunctionExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "Identifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIfStatement(node, opts) { + if (!node) return false; + if (node.type !== "IfStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLabeledStatement(node, opts) { + if (!node) return false; + if (node.type !== "LabeledStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringLiteral(node, opts) { + if (!node) return false; + if (node.type !== "StringLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumericLiteral(node, opts) { + if (!node) return false; + if (node.type !== "NumericLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullLiteral(node, opts) { + if (!node) return false; + if (node.type !== "NullLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanLiteral(node, opts) { + if (!node) return false; + if (node.type !== "BooleanLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRegExpLiteral(node, opts) { + if (!node) return false; + if (node.type !== "RegExpLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLogicalExpression(node, opts) { + if (!node) return false; + if (node.type !== "LogicalExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "MemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNewExpression(node, opts) { + if (!node) return false; + if (node.type !== "NewExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isProgram(node, opts) { + if (!node) return false; + if (node.type !== "Program") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectExpression(node, opts) { + if (!node) return false; + if (node.type !== "ObjectExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectMethod(node, opts) { + if (!node) return false; + if (node.type !== "ObjectMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRestElement(node, opts) { + if (!node) return false; + if (node.type !== "RestElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isReturnStatement(node, opts) { + if (!node) return false; + if (node.type !== "ReturnStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSequenceExpression(node, opts) { + if (!node) return false; + if (node.type !== "SequenceExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isParenthesizedExpression(node, opts) { + if (!node) return false; + if (node.type !== "ParenthesizedExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSwitchCase(node, opts) { + if (!node) return false; + if (node.type !== "SwitchCase") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSwitchStatement(node, opts) { + if (!node) return false; + if (node.type !== "SwitchStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThisExpression(node, opts) { + if (!node) return false; + if (node.type !== "ThisExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThrowStatement(node, opts) { + if (!node) return false; + if (node.type !== "ThrowStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTryStatement(node, opts) { + if (!node) return false; + if (node.type !== "TryStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnaryExpression(node, opts) { + if (!node) return false; + if (node.type !== "UnaryExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUpdateExpression(node, opts) { + if (!node) return false; + if (node.type !== "UpdateExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariableDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "VariableDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariableDeclarator(node, opts) { + if (!node) return false; + if (node.type !== "VariableDeclarator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWhileStatement(node, opts) { + if (!node) return false; + if (node.type !== "WhileStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWithStatement(node, opts) { + if (!node) return false; + if (node.type !== "WithStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAssignmentPattern(node, opts) { + if (!node) return false; + if (node.type !== "AssignmentPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrayPattern(node, opts) { + if (!node) return false; + if (node.type !== "ArrayPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrowFunctionExpression(node, opts) { + if (!node) return false; + if (node.type !== "ArrowFunctionExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassBody(node, opts) { + if (!node) return false; + if (node.type !== "ClassBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassExpression(node, opts) { + if (!node) return false; + if (node.type !== "ClassExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ClassDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportAllDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportAllDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDefaultDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportDefaultDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportNamedDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportNamedDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForOfStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForOfStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ImportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportDefaultSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportDefaultSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportNamespaceSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportNamespaceSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportExpression(node, opts) { + if (!node) return false; + if (node.type !== "ImportExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMetaProperty(node, opts) { + if (!node) return false; + if (node.type !== "MetaProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassMethod(node, opts) { + if (!node) return false; + if (node.type !== "ClassMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectPattern(node, opts) { + if (!node) return false; + if (node.type !== "ObjectPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSpreadElement(node, opts) { + if (!node) return false; + if (node.type !== "SpreadElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSuper(node, opts) { + if (!node) return false; + if (node.type !== "Super") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTaggedTemplateExpression(node, opts) { + if (!node) return false; + if (node.type !== "TaggedTemplateExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTemplateElement(node, opts) { + if (!node) return false; + if (node.type !== "TemplateElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTemplateLiteral(node, opts) { + if (!node) return false; + if (node.type !== "TemplateLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isYieldExpression(node, opts) { + if (!node) return false; + if (node.type !== "YieldExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAwaitExpression(node, opts) { + if (!node) return false; + if (node.type !== "AwaitExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImport(node, opts) { + if (!node) return false; + if (node.type !== "Import") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBigIntLiteral(node, opts) { + if (!node) return false; + if (node.type !== "BigIntLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportNamespaceSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportNamespaceSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "OptionalMemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalCallExpression(node, opts) { + if (!node) return false; + if (node.type !== "OptionalCallExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassAccessorProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassAccessorProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassPrivateProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassPrivateProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassPrivateMethod(node, opts) { + if (!node) return false; + if (node.type !== "ClassPrivateMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPrivateName(node, opts) { + if (!node) return false; + if (node.type !== "PrivateName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStaticBlock(node, opts) { + if (!node) return false; + if (node.type !== "StaticBlock") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAnyTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "AnyTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrayTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ArrayTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "BooleanTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "BooleanLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NullLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassImplements(node, opts) { + if (!node) return false; + if (node.type !== "ClassImplements") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareClass(node, opts) { + if (!node) return false; + if (node.type !== "DeclareClass") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareFunction(node, opts) { + if (!node) return false; + if (node.type !== "DeclareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareInterface(node, opts) { + if (!node) return false; + if (node.type !== "DeclareInterface") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareModule(node, opts) { + if (!node) return false; + if (node.type !== "DeclareModule") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareModuleExports(node, opts) { + if (!node) return false; + if (node.type !== "DeclareModuleExports") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareTypeAlias(node, opts) { + if (!node) return false; + if (node.type !== "DeclareTypeAlias") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareOpaqueType(node, opts) { + if (!node) return false; + if (node.type !== "DeclareOpaqueType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareVariable(node, opts) { + if (!node) return false; + if (node.type !== "DeclareVariable") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareExportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "DeclareExportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareExportAllDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "DeclareExportAllDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclaredPredicate(node, opts) { + if (!node) return false; + if (node.type !== "DeclaredPredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExistsTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ExistsTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "FunctionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionTypeParam(node, opts) { + if (!node) return false; + if (node.type !== "FunctionTypeParam") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isGenericTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "GenericTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInferredPredicate(node, opts) { + if (!node) return false; + if (node.type !== "InferredPredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceExtends(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceExtends") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIntersectionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "IntersectionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMixedTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "MixedTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEmptyTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "EmptyTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullableTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NullableTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NumberLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NumberTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeInternalSlot(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeInternalSlot") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeCallProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeCallProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeIndexer(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeIndexer") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeSpreadProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeSpreadProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOpaqueType(node, opts) { + if (!node) return false; + if (node.type !== "OpaqueType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isQualifiedTypeIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "QualifiedTypeIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "StringLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "StringTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSymbolTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "SymbolTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThisTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ThisTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTupleTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TupleTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeofTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TypeofTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeAlias(node, opts) { + if (!node) return false; + if (node.type !== "TypeAlias") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeCastExpression(node, opts) { + if (!node) return false; + if (node.type !== "TypeCastExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameter(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameter") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameterDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameterDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameterInstantiation(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameterInstantiation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "UnionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariance(node, opts) { + if (!node) return false; + if (node.type !== "Variance") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVoidTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "VoidTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "EnumDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBooleanBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumBooleanBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumNumberBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumNumberBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumStringBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumStringBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumSymbolBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumSymbolBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBooleanMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumBooleanMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumNumberMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumNumberMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumStringMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumStringMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumDefaultedMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumDefaultedMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "IndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "OptionalIndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXAttribute(node, opts) { + if (!node) return false; + if (node.type !== "JSXAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXClosingElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXClosingElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXEmptyExpression(node, opts) { + if (!node) return false; + if (node.type !== "JSXEmptyExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXExpressionContainer(node, opts) { + if (!node) return false; + if (node.type !== "JSXExpressionContainer") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXSpreadChild(node, opts) { + if (!node) return false; + if (node.type !== "JSXSpreadChild") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "JSXIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "JSXMemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXNamespacedName(node, opts) { + if (!node) return false; + if (node.type !== "JSXNamespacedName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXOpeningElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXOpeningElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXSpreadAttribute(node, opts) { + if (!node) return false; + if (node.type !== "JSXSpreadAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXText(node, opts) { + if (!node) return false; + if (node.type !== "JSXText") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXOpeningFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXOpeningFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXClosingFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXClosingFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNoop(node, opts) { + if (!node) return false; + if (node.type !== "Noop") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPlaceholder(node, opts) { + if (!node) return false; + if (node.type !== "Placeholder") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isV8IntrinsicIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "V8IntrinsicIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArgumentPlaceholder(node, opts) { + if (!node) return false; + if (node.type !== "ArgumentPlaceholder") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBindExpression(node, opts) { + if (!node) return false; + if (node.type !== "BindExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportAttribute(node, opts) { + if (!node) return false; + if (node.type !== "ImportAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDecorator(node, opts) { + if (!node) return false; + if (node.type !== "Decorator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDoExpression(node, opts) { + if (!node) return false; + if (node.type !== "DoExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDefaultSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportDefaultSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRecordExpression(node, opts) { + if (!node) return false; + if (node.type !== "RecordExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTupleExpression(node, opts) { + if (!node) return false; + if (node.type !== "TupleExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDecimalLiteral(node, opts) { + if (!node) return false; + if (node.type !== "DecimalLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleExpression(node, opts) { + if (!node) return false; + if (node.type !== "ModuleExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTopicReference(node, opts) { + if (!node) return false; + if (node.type !== "TopicReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelineTopicExpression(node, opts) { + if (!node) return false; + if (node.type !== "PipelineTopicExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelineBareFunction(node, opts) { + if (!node) return false; + if (node.type !== "PipelineBareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelinePrimaryTopicReference(node, opts) { + if (!node) return false; + if (node.type !== "PipelinePrimaryTopicReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSParameterProperty(node, opts) { + if (!node) return false; + if (node.type !== "TSParameterProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSDeclareFunction(node, opts) { + if (!node) return false; + if (node.type !== "TSDeclareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSDeclareMethod(node, opts) { + if (!node) return false; + if (node.type !== "TSDeclareMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSQualifiedName(node, opts) { + if (!node) return false; + if (node.type !== "TSQualifiedName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSCallSignatureDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSCallSignatureDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConstructSignatureDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSConstructSignatureDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSPropertySignature(node, opts) { + if (!node) return false; + if (node.type !== "TSPropertySignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSMethodSignature(node, opts) { + if (!node) return false; + if (node.type !== "TSMethodSignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIndexSignature(node, opts) { + if (!node) return false; + if (node.type !== "TSIndexSignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSAnyKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSAnyKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBooleanKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSBooleanKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBigIntKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSBigIntKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIntrinsicKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSIntrinsicKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNeverKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNeverKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNullKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNullKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNumberKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNumberKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSObjectKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSObjectKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSStringKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSStringKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSSymbolKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSSymbolKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUndefinedKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSUndefinedKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUnknownKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSUnknownKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSVoidKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSVoidKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSThisType(node, opts) { + if (!node) return false; + if (node.type !== "TSThisType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSFunctionType(node, opts) { + if (!node) return false; + if (node.type !== "TSFunctionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConstructorType(node, opts) { + if (!node) return false; + if (node.type !== "TSConstructorType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeReference(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypePredicate(node, opts) { + if (!node) return false; + if (node.type !== "TSTypePredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeQuery(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeQuery") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeLiteral(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSArrayType(node, opts) { + if (!node) return false; + if (node.type !== "TSArrayType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTupleType(node, opts) { + if (!node) return false; + if (node.type !== "TSTupleType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSOptionalType(node, opts) { + if (!node) return false; + if (node.type !== "TSOptionalType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSRestType(node, opts) { + if (!node) return false; + if (node.type !== "TSRestType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNamedTupleMember(node, opts) { + if (!node) return false; + if (node.type !== "TSNamedTupleMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUnionType(node, opts) { + if (!node) return false; + if (node.type !== "TSUnionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIntersectionType(node, opts) { + if (!node) return false; + if (node.type !== "TSIntersectionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConditionalType(node, opts) { + if (!node) return false; + if (node.type !== "TSConditionalType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInferType(node, opts) { + if (!node) return false; + if (node.type !== "TSInferType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSParenthesizedType(node, opts) { + if (!node) return false; + if (node.type !== "TSParenthesizedType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeOperator(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeOperator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "TSIndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSMappedType(node, opts) { + if (!node) return false; + if (node.type !== "TSMappedType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSLiteralType(node, opts) { + if (!node) return false; + if (node.type !== "TSLiteralType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExpressionWithTypeArguments(node, opts) { + if (!node) return false; + if (node.type !== "TSExpressionWithTypeArguments") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInterfaceDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSInterfaceDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInterfaceBody(node, opts) { + if (!node) return false; + if (node.type !== "TSInterfaceBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAliasDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAliasDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInstantiationExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSInstantiationExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSAsExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSAsExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSSatisfiesExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSSatisfiesExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAssertion(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAssertion") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEnumDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSEnumDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEnumMember(node, opts) { + if (!node) return false; + if (node.type !== "TSEnumMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSModuleDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSModuleDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSModuleBlock(node, opts) { + if (!node) return false; + if (node.type !== "TSModuleBlock") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSImportType(node, opts) { + if (!node) return false; + if (node.type !== "TSImportType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSImportEqualsDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSImportEqualsDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExternalModuleReference(node, opts) { + if (!node) return false; + if (node.type !== "TSExternalModuleReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNonNullExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSNonNullExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExportAssignment(node, opts) { + if (!node) return false; + if (node.type !== "TSExportAssignment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNamespaceExportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSNamespaceExportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameterInstantiation(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameterInstantiation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameterDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameterDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameter(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameter") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStandardized(node, opts) { + if (!node) return false; + switch (node.type) { + case "ArrayExpression": + case "AssignmentExpression": + case "BinaryExpression": + case "InterpreterDirective": + case "Directive": + case "DirectiveLiteral": + case "BlockStatement": + case "BreakStatement": + case "CallExpression": + case "CatchClause": + case "ConditionalExpression": + case "ContinueStatement": + case "DebuggerStatement": + case "DoWhileStatement": + case "EmptyStatement": + case "ExpressionStatement": + case "File": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Identifier": + case "IfStatement": + case "LabeledStatement": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "LogicalExpression": + case "MemberExpression": + case "NewExpression": + case "Program": + case "ObjectExpression": + case "ObjectMethod": + case "ObjectProperty": + case "RestElement": + case "ReturnStatement": + case "SequenceExpression": + case "ParenthesizedExpression": + case "SwitchCase": + case "SwitchStatement": + case "ThisExpression": + case "ThrowStatement": + case "TryStatement": + case "UnaryExpression": + case "UpdateExpression": + case "VariableDeclaration": + case "VariableDeclarator": + case "WhileStatement": + case "WithStatement": + case "AssignmentPattern": + case "ArrayPattern": + case "ArrowFunctionExpression": + case "ClassBody": + case "ClassExpression": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ExportSpecifier": + case "ForOfStatement": + case "ImportDeclaration": + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + case "ImportExpression": + case "MetaProperty": + case "ClassMethod": + case "ObjectPattern": + case "SpreadElement": + case "Super": + case "TaggedTemplateExpression": + case "TemplateElement": + case "TemplateLiteral": + case "YieldExpression": + case "AwaitExpression": + case "Import": + case "BigIntLiteral": + case "ExportNamespaceSpecifier": + case "OptionalMemberExpression": + case "OptionalCallExpression": + case "ClassProperty": + case "ClassAccessorProperty": + case "ClassPrivateProperty": + case "ClassPrivateMethod": + case "PrivateName": + case "StaticBlock": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Identifier": + case "StringLiteral": + case "BlockStatement": + case "ClassBody": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpression(node, opts) { + if (!node) return false; + switch (node.type) { + case "ArrayExpression": + case "AssignmentExpression": + case "BinaryExpression": + case "CallExpression": + case "ConditionalExpression": + case "FunctionExpression": + case "Identifier": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "LogicalExpression": + case "MemberExpression": + case "NewExpression": + case "ObjectExpression": + case "SequenceExpression": + case "ParenthesizedExpression": + case "ThisExpression": + case "UnaryExpression": + case "UpdateExpression": + case "ArrowFunctionExpression": + case "ClassExpression": + case "ImportExpression": + case "MetaProperty": + case "Super": + case "TaggedTemplateExpression": + case "TemplateLiteral": + case "YieldExpression": + case "AwaitExpression": + case "Import": + case "BigIntLiteral": + case "OptionalMemberExpression": + case "OptionalCallExpression": + case "TypeCastExpression": + case "JSXElement": + case "JSXFragment": + case "BindExpression": + case "DoExpression": + case "RecordExpression": + case "TupleExpression": + case "DecimalLiteral": + case "ModuleExpression": + case "TopicReference": + case "PipelineTopicExpression": + case "PipelineBareFunction": + case "PipelinePrimaryTopicReference": + case "TSInstantiationExpression": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Expression": + case "Identifier": + case "StringLiteral": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBinary(node, opts) { + if (!node) return false; + switch (node.type) { + case "BinaryExpression": + case "LogicalExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isScopable(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "CatchClause": + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Program": + case "ObjectMethod": + case "SwitchStatement": + case "WhileStatement": + case "ArrowFunctionExpression": + case "ClassExpression": + case "ClassDeclaration": + case "ForOfStatement": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlockParent(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "CatchClause": + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Program": + case "ObjectMethod": + case "SwitchStatement": + case "WhileStatement": + case "ArrowFunctionExpression": + case "ForOfStatement": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlock(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "Program": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "BreakStatement": + case "ContinueStatement": + case "DebuggerStatement": + case "DoWhileStatement": + case "EmptyStatement": + case "ExpressionStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "IfStatement": + case "LabeledStatement": + case "ReturnStatement": + case "SwitchStatement": + case "ThrowStatement": + case "TryStatement": + case "VariableDeclaration": + case "WhileStatement": + case "WithStatement": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ForOfStatement": + case "ImportDeclaration": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + case "EnumDeclaration": + case "TSDeclareFunction": + case "TSInterfaceDeclaration": + case "TSTypeAliasDeclaration": + case "TSEnumDeclaration": + case "TSModuleDeclaration": + case "TSImportEqualsDeclaration": + case "TSExportAssignment": + case "TSNamespaceExportDeclaration": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Statement": + case "Declaration": + case "BlockStatement": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTerminatorless(node, opts) { + if (!node) return false; + switch (node.type) { + case "BreakStatement": + case "ContinueStatement": + case "ReturnStatement": + case "ThrowStatement": + case "YieldExpression": + case "AwaitExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCompletionStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "BreakStatement": + case "ContinueStatement": + case "ReturnStatement": + case "ThrowStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isConditional(node, opts) { + if (!node) return false; + switch (node.type) { + case "ConditionalExpression": + case "IfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLoop(node, opts) { + if (!node) return false; + switch (node.type) { + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "WhileStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWhile(node, opts) { + if (!node) return false; + switch (node.type) { + case "DoWhileStatement": + case "WhileStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpressionWrapper(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExpressionStatement": + case "ParenthesizedExpression": + case "TypeCastExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFor(node, opts) { + if (!node) return false; + switch (node.type) { + case "ForInStatement": + case "ForStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForXStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "ForInStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunction(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "ObjectMethod": + case "ArrowFunctionExpression": + case "ClassMethod": + case "ClassPrivateMethod": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionParent(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "ObjectMethod": + case "ArrowFunctionExpression": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPureish(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "ArrowFunctionExpression": + case "BigIntLiteral": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "VariableDeclaration": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ImportDeclaration": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + case "EnumDeclaration": + case "TSDeclareFunction": + case "TSInterfaceDeclaration": + case "TSTypeAliasDeclaration": + case "TSEnumDeclaration": + case "TSModuleDeclaration": + break; + case "Placeholder": + if (node.expectedNode === "Declaration") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPatternLike(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "RestElement": + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Pattern": + case "Identifier": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLVal(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "MemberExpression": + case "RestElement": + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + case "TSParameterProperty": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Pattern": + case "Identifier": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEntityName(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "TSQualifiedName": + break; + case "Placeholder": + if (node.expectedNode === "Identifier") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLiteral(node, opts) { + if (!node) return false; + switch (node.type) { + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "TemplateLiteral": + case "BigIntLiteral": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImmutable(node, opts) { + if (!node) return false; + switch (node.type) { + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "BigIntLiteral": + case "JSXAttribute": + case "JSXClosingElement": + case "JSXElement": + case "JSXExpressionContainer": + case "JSXSpreadChild": + case "JSXOpeningElement": + case "JSXText": + case "JSXFragment": + case "JSXOpeningFragment": + case "JSXClosingFragment": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUserWhitespacable(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ObjectProperty": + case "ObjectTypeInternalSlot": + case "ObjectTypeCallProperty": + case "ObjectTypeIndexer": + case "ObjectTypeProperty": + case "ObjectTypeSpreadProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMethod(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ClassMethod": + case "ClassPrivateMethod": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectMember(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ObjectProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isProperty(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectProperty": + case "ClassProperty": + case "ClassAccessorProperty": + case "ClassPrivateProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnaryLike(node, opts) { + if (!node) return false; + switch (node.type) { + case "UnaryExpression": + case "SpreadElement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPattern(node, opts) { + if (!node) return false; + switch (node.type) { + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + break; + case "Placeholder": + if (node.expectedNode === "Pattern") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClass(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassExpression": + case "ClassDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportOrExportDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ImportDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleSpecifier(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportSpecifier": + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + case "ExportNamespaceSpecifier": + case "ExportDefaultSpecifier": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAccessor(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassAccessorProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPrivate(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassPrivateProperty": + case "ClassPrivateMethod": + case "PrivateName": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlow(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "ArrayTypeAnnotation": + case "BooleanTypeAnnotation": + case "BooleanLiteralTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "ClassImplements": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "DeclaredPredicate": + case "ExistsTypeAnnotation": + case "FunctionTypeAnnotation": + case "FunctionTypeParam": + case "GenericTypeAnnotation": + case "InferredPredicate": + case "InterfaceExtends": + case "InterfaceDeclaration": + case "InterfaceTypeAnnotation": + case "IntersectionTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NullableTypeAnnotation": + case "NumberLiteralTypeAnnotation": + case "NumberTypeAnnotation": + case "ObjectTypeAnnotation": + case "ObjectTypeInternalSlot": + case "ObjectTypeCallProperty": + case "ObjectTypeIndexer": + case "ObjectTypeProperty": + case "ObjectTypeSpreadProperty": + case "OpaqueType": + case "QualifiedTypeIdentifier": + case "StringLiteralTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "TupleTypeAnnotation": + case "TypeofTypeAnnotation": + case "TypeAlias": + case "TypeAnnotation": + case "TypeCastExpression": + case "TypeParameter": + case "TypeParameterDeclaration": + case "TypeParameterInstantiation": + case "UnionTypeAnnotation": + case "Variance": + case "VoidTypeAnnotation": + case "EnumDeclaration": + case "EnumBooleanBody": + case "EnumNumberBody": + case "EnumStringBody": + case "EnumSymbolBody": + case "EnumBooleanMember": + case "EnumNumberMember": + case "EnumStringMember": + case "EnumDefaultedMember": + case "IndexedAccessType": + case "OptionalIndexedAccessType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowType(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "ArrayTypeAnnotation": + case "BooleanTypeAnnotation": + case "BooleanLiteralTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "ExistsTypeAnnotation": + case "FunctionTypeAnnotation": + case "GenericTypeAnnotation": + case "InterfaceTypeAnnotation": + case "IntersectionTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NullableTypeAnnotation": + case "NumberLiteralTypeAnnotation": + case "NumberTypeAnnotation": + case "ObjectTypeAnnotation": + case "StringLiteralTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "TupleTypeAnnotation": + case "TypeofTypeAnnotation": + case "UnionTypeAnnotation": + case "VoidTypeAnnotation": + case "IndexedAccessType": + case "OptionalIndexedAccessType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowBaseAnnotation(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "BooleanTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NumberTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "VoidTypeAnnotation": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowPredicate(node, opts) { + if (!node) return false; + switch (node.type) { + case "DeclaredPredicate": + case "InferredPredicate": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBody(node, opts) { + if (!node) return false; + switch (node.type) { + case "EnumBooleanBody": + case "EnumNumberBody": + case "EnumStringBody": + case "EnumSymbolBody": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumMember(node, opts) { + if (!node) return false; + switch (node.type) { + case "EnumBooleanMember": + case "EnumNumberMember": + case "EnumStringMember": + case "EnumDefaultedMember": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSX(node, opts) { + if (!node) return false; + switch (node.type) { + case "JSXAttribute": + case "JSXClosingElement": + case "JSXElement": + case "JSXEmptyExpression": + case "JSXExpressionContainer": + case "JSXSpreadChild": + case "JSXIdentifier": + case "JSXMemberExpression": + case "JSXNamespacedName": + case "JSXOpeningElement": + case "JSXSpreadAttribute": + case "JSXText": + case "JSXFragment": + case "JSXOpeningFragment": + case "JSXClosingFragment": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMiscellaneous(node, opts) { + if (!node) return false; + switch (node.type) { + case "Noop": + case "Placeholder": + case "V8IntrinsicIdentifier": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeScript(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSParameterProperty": + case "TSDeclareFunction": + case "TSDeclareMethod": + case "TSQualifiedName": + case "TSCallSignatureDeclaration": + case "TSConstructSignatureDeclaration": + case "TSPropertySignature": + case "TSMethodSignature": + case "TSIndexSignature": + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSFunctionType": + case "TSConstructorType": + case "TSTypeReference": + case "TSTypePredicate": + case "TSTypeQuery": + case "TSTypeLiteral": + case "TSArrayType": + case "TSTupleType": + case "TSOptionalType": + case "TSRestType": + case "TSNamedTupleMember": + case "TSUnionType": + case "TSIntersectionType": + case "TSConditionalType": + case "TSInferType": + case "TSParenthesizedType": + case "TSTypeOperator": + case "TSIndexedAccessType": + case "TSMappedType": + case "TSLiteralType": + case "TSExpressionWithTypeArguments": + case "TSInterfaceDeclaration": + case "TSInterfaceBody": + case "TSTypeAliasDeclaration": + case "TSInstantiationExpression": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSEnumDeclaration": + case "TSEnumMember": + case "TSModuleDeclaration": + case "TSModuleBlock": + case "TSImportType": + case "TSImportEqualsDeclaration": + case "TSExternalModuleReference": + case "TSNonNullExpression": + case "TSExportAssignment": + case "TSNamespaceExportDeclaration": + case "TSTypeAnnotation": + case "TSTypeParameterInstantiation": + case "TSTypeParameterDeclaration": + case "TSTypeParameter": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeElement(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSCallSignatureDeclaration": + case "TSConstructSignatureDeclaration": + case "TSPropertySignature": + case "TSMethodSignature": + case "TSIndexSignature": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSType(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSFunctionType": + case "TSConstructorType": + case "TSTypeReference": + case "TSTypePredicate": + case "TSTypeQuery": + case "TSTypeLiteral": + case "TSArrayType": + case "TSTupleType": + case "TSOptionalType": + case "TSRestType": + case "TSUnionType": + case "TSIntersectionType": + case "TSConditionalType": + case "TSInferType": + case "TSParenthesizedType": + case "TSTypeOperator": + case "TSIndexedAccessType": + case "TSMappedType": + case "TSLiteralType": + case "TSExpressionWithTypeArguments": + case "TSImportType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBaseType(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSLiteralType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberLiteral(node, opts) { + (0, _deprecationWarning.default)("isNumberLiteral", "isNumericLiteral"); + if (!node) return false; + if (node.type !== "NumberLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRegexLiteral(node, opts) { + (0, _deprecationWarning.default)("isRegexLiteral", "isRegExpLiteral"); + if (!node) return false; + if (node.type !== "RegexLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRestProperty(node, opts) { + (0, _deprecationWarning.default)("isRestProperty", "isRestElement"); + if (!node) return false; + if (node.type !== "RestProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSpreadProperty(node, opts) { + (0, _deprecationWarning.default)("isSpreadProperty", "isSpreadElement"); + if (!node) return false; + if (node.type !== "SpreadProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleDeclaration(node, opts) { + (0, _deprecationWarning.default)("isModuleDeclaration", "isImportOrExportDeclaration"); + return isImportOrExportDeclaration(node, opts); + } + + + return generated$3; +} + +var hasRequiredMatchesPattern; + +function requireMatchesPattern () { + if (hasRequiredMatchesPattern) return matchesPattern; + hasRequiredMatchesPattern = 1; + + Object.defineProperty(matchesPattern, "__esModule", { + value: true + }); + matchesPattern.default = matchesPattern$1; + var _index = requireGenerated$3(); + function matchesPattern$1(member, match, allowPartial) { + if (!(0, _index.isMemberExpression)(member)) return false; + const parts = Array.isArray(match) ? match : match.split("."); + const nodes = []; + let node; + for (node = member; (0, _index.isMemberExpression)(node); node = node.object) { + nodes.push(node.property); + } + nodes.push(node); + if (nodes.length < parts.length) return false; + if (!allowPartial && nodes.length > parts.length) return false; + for (let i = 0, j = nodes.length - 1; i < parts.length; i++, j--) { + const node = nodes[j]; + let value; + if ((0, _index.isIdentifier)(node)) { + value = node.name; + } else if ((0, _index.isStringLiteral)(node)) { + value = node.value; + } else if ((0, _index.isThisExpression)(node)) { + value = "this"; + } else { + return false; + } + if (parts[i] !== value) return false; + } + return true; + } + + + return matchesPattern; +} + +var hasRequiredBuildMatchMemberExpression; + +function requireBuildMatchMemberExpression () { + if (hasRequiredBuildMatchMemberExpression) return buildMatchMemberExpression; + hasRequiredBuildMatchMemberExpression = 1; + + Object.defineProperty(buildMatchMemberExpression, "__esModule", { + value: true + }); + buildMatchMemberExpression.default = buildMatchMemberExpression$1; + var _matchesPattern = requireMatchesPattern(); + function buildMatchMemberExpression$1(match, allowPartial) { + const parts = match.split("."); + return member => (0, _matchesPattern.default)(member, parts, allowPartial); + } + + + return buildMatchMemberExpression; +} + +var hasRequiredIsReactComponent; + +function requireIsReactComponent () { + if (hasRequiredIsReactComponent) return isReactComponent; + hasRequiredIsReactComponent = 1; + + Object.defineProperty(isReactComponent, "__esModule", { + value: true + }); + isReactComponent.default = void 0; + var _buildMatchMemberExpression = requireBuildMatchMemberExpression(); + const isReactComponent$1 = (0, _buildMatchMemberExpression.default)("React.Component"); + isReactComponent.default = isReactComponent$1; + + + return isReactComponent; +} + +var isCompatTag = {}; + +var hasRequiredIsCompatTag; + +function requireIsCompatTag () { + if (hasRequiredIsCompatTag) return isCompatTag; + hasRequiredIsCompatTag = 1; + + Object.defineProperty(isCompatTag, "__esModule", { + value: true + }); + isCompatTag.default = isCompatTag$1; + function isCompatTag$1(tagName) { + return !!tagName && /^[a-z]/.test(tagName); + } + + + return isCompatTag; +} + +var buildChildren = {}; + +var cleanJSXElementLiteralChild = {}; + +var generated$2 = {}; + +var validate$1 = {}; + +var definitions = {}; + +var core = {}; + +var is = {}; + +var isType = {}; + +var hasRequiredIsType; + +function requireIsType () { + if (hasRequiredIsType) return isType; + hasRequiredIsType = 1; + + Object.defineProperty(isType, "__esModule", { + value: true + }); + isType.default = isType$1; + var _index = requireDefinitions(); + function isType$1(nodeType, targetType) { + if (nodeType === targetType) return true; + if (nodeType == null) return false; + if (_index.ALIAS_KEYS[targetType]) return false; + const aliases = _index.FLIPPED_ALIAS_KEYS[targetType]; + if (aliases) { + if (aliases[0] === nodeType) return true; + for (const alias of aliases) { + if (nodeType === alias) return true; + } + } + return false; + } + + + return isType; +} + +var isPlaceholderType = {}; + +var hasRequiredIsPlaceholderType; + +function requireIsPlaceholderType () { + if (hasRequiredIsPlaceholderType) return isPlaceholderType; + hasRequiredIsPlaceholderType = 1; + + Object.defineProperty(isPlaceholderType, "__esModule", { + value: true + }); + isPlaceholderType.default = isPlaceholderType$1; + var _index = requireDefinitions(); + function isPlaceholderType$1(placeholderType, targetType) { + if (placeholderType === targetType) return true; + const aliases = _index.PLACEHOLDERS_ALIAS[placeholderType]; + if (aliases) { + for (const alias of aliases) { + if (targetType === alias) return true; + } + } + return false; + } + + + return isPlaceholderType; +} + +var hasRequiredIs; + +function requireIs () { + if (hasRequiredIs) return is; + hasRequiredIs = 1; + + Object.defineProperty(is, "__esModule", { + value: true + }); + is.default = is$1; + var _shallowEqual = requireShallowEqual(); + var _isType = requireIsType(); + var _isPlaceholderType = requireIsPlaceholderType(); + var _index = requireDefinitions(); + function is$1(type, node, opts) { + if (!node) return false; + const matches = (0, _isType.default)(node.type, type); + if (!matches) { + if (!opts && node.type === "Placeholder" && type in _index.FLIPPED_ALIAS_KEYS) { + return (0, _isPlaceholderType.default)(node.expectedNode, type); + } + return false; + } + if (opts === undefined) { + return true; + } else { + return (0, _shallowEqual.default)(node, opts); + } + } + + + return is; +} + +var isValidIdentifier = {}; + +var lib$2 = {}; + +var identifier = {}; + +var hasRequiredIdentifier; + +function requireIdentifier () { + if (hasRequiredIdentifier) return identifier; + hasRequiredIdentifier = 1; + + Object.defineProperty(identifier, "__esModule", { + value: true + }); + identifier.isIdentifierChar = isIdentifierChar; + identifier.isIdentifierName = isIdentifierName; + identifier.isIdentifierStart = isIdentifierStart; + let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; + let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65"; + const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); + const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); + nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; + const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191]; + const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; + function isInAstralSet(code, set) { + let pos = 0x10000; + for (let i = 0, length = set.length; i < length; i += 2) { + pos += set[i]; + if (pos > code) return false; + pos += set[i + 1]; + if (pos >= code) return true; + } + return false; + } + function isIdentifierStart(code) { + if (code < 65) return code === 36; + if (code <= 90) return true; + if (code < 97) return code === 95; + if (code <= 122) return true; + if (code <= 0xffff) { + return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)); + } + return isInAstralSet(code, astralIdentifierStartCodes); + } + function isIdentifierChar(code) { + if (code < 48) return code === 36; + if (code < 58) return true; + if (code < 65) return false; + if (code <= 90) return true; + if (code < 97) return code === 95; + if (code <= 122) return true; + if (code <= 0xffff) { + return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)); + } + return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes); + } + function isIdentifierName(name) { + let isFirst = true; + for (let i = 0; i < name.length; i++) { + let cp = name.charCodeAt(i); + if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) { + const trail = name.charCodeAt(++i); + if ((trail & 0xfc00) === 0xdc00) { + cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff); + } + } + if (isFirst) { + isFirst = false; + if (!isIdentifierStart(cp)) { + return false; + } + } else if (!isIdentifierChar(cp)) { + return false; + } + } + return !isFirst; + } + + + return identifier; +} + +var keyword = {}; + +var hasRequiredKeyword; + +function requireKeyword () { + if (hasRequiredKeyword) return keyword; + hasRequiredKeyword = 1; + + Object.defineProperty(keyword, "__esModule", { + value: true + }); + keyword.isKeyword = isKeyword; + keyword.isReservedWord = isReservedWord; + keyword.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord; + keyword.isStrictBindReservedWord = isStrictBindReservedWord; + keyword.isStrictReservedWord = isStrictReservedWord; + const reservedWords = { + keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"], + strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"], + strictBind: ["eval", "arguments"] + }; + const keywords = new Set(reservedWords.keyword); + const reservedWordsStrictSet = new Set(reservedWords.strict); + const reservedWordsStrictBindSet = new Set(reservedWords.strictBind); + function isReservedWord(word, inModule) { + return inModule && word === "await" || word === "enum"; + } + function isStrictReservedWord(word, inModule) { + return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word); + } + function isStrictBindOnlyReservedWord(word) { + return reservedWordsStrictBindSet.has(word); + } + function isStrictBindReservedWord(word, inModule) { + return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word); + } + function isKeyword(word) { + return keywords.has(word); + } + + + return keyword; +} + +var hasRequiredLib$3; + +function requireLib$3 () { + if (hasRequiredLib$3) return lib$2; + hasRequiredLib$3 = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "isIdentifierChar", { + enumerable: true, + get: function () { + return _identifier.isIdentifierChar; + } + }); + Object.defineProperty(exports, "isIdentifierName", { + enumerable: true, + get: function () { + return _identifier.isIdentifierName; + } + }); + Object.defineProperty(exports, "isIdentifierStart", { + enumerable: true, + get: function () { + return _identifier.isIdentifierStart; + } + }); + Object.defineProperty(exports, "isKeyword", { + enumerable: true, + get: function () { + return _keyword.isKeyword; + } + }); + Object.defineProperty(exports, "isReservedWord", { + enumerable: true, + get: function () { + return _keyword.isReservedWord; + } + }); + Object.defineProperty(exports, "isStrictBindOnlyReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictBindOnlyReservedWord; + } + }); + Object.defineProperty(exports, "isStrictBindReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictBindReservedWord; + } + }); + Object.defineProperty(exports, "isStrictReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictReservedWord; + } + }); + var _identifier = requireIdentifier(); + var _keyword = requireKeyword(); + + +} (lib$2)); + return lib$2; +} + +var hasRequiredIsValidIdentifier; + +function requireIsValidIdentifier () { + if (hasRequiredIsValidIdentifier) return isValidIdentifier; + hasRequiredIsValidIdentifier = 1; + + Object.defineProperty(isValidIdentifier, "__esModule", { + value: true + }); + isValidIdentifier.default = isValidIdentifier$1; + var _helperValidatorIdentifier = requireLib$3(); + function isValidIdentifier$1(name, reserved = true) { + if (typeof name !== "string") return false; + if (reserved) { + if ((0, _helperValidatorIdentifier.isKeyword)(name) || (0, _helperValidatorIdentifier.isStrictReservedWord)(name, true)) { + return false; + } + } + return (0, _helperValidatorIdentifier.isIdentifierName)(name); + } + + + return isValidIdentifier; +} + +var lib$1 = {}; + +var hasRequiredLib$2; + +function requireLib$2 () { + if (hasRequiredLib$2) return lib$1; + hasRequiredLib$2 = 1; + + Object.defineProperty(lib$1, "__esModule", { + value: true + }); + lib$1.readCodePoint = readCodePoint; + lib$1.readInt = readInt; + lib$1.readStringContents = readStringContents; + var _isDigit = function isDigit(code) { + return code >= 48 && code <= 57; + }; + const forbiddenNumericSeparatorSiblings = { + decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]), + hex: new Set([46, 88, 95, 120]) + }; + const isAllowedNumericSeparatorSibling = { + bin: ch => ch === 48 || ch === 49, + oct: ch => ch >= 48 && ch <= 55, + dec: ch => ch >= 48 && ch <= 57, + hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102 + }; + function readStringContents(type, input, pos, lineStart, curLine, errors) { + const initialPos = pos; + const initialLineStart = lineStart; + const initialCurLine = curLine; + let out = ""; + let firstInvalidLoc = null; + let chunkStart = pos; + const { + length + } = input; + for (;;) { + if (pos >= length) { + errors.unterminated(initialPos, initialLineStart, initialCurLine); + out += input.slice(chunkStart, pos); + break; + } + const ch = input.charCodeAt(pos); + if (isStringEnd(type, ch, input, pos)) { + out += input.slice(chunkStart, pos); + break; + } + if (ch === 92) { + out += input.slice(chunkStart, pos); + const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors); + if (res.ch === null && !firstInvalidLoc) { + firstInvalidLoc = { + pos, + lineStart, + curLine + }; + } else { + out += res.ch; + } + ({ + pos, + lineStart, + curLine + } = res); + chunkStart = pos; + } else if (ch === 8232 || ch === 8233) { + ++pos; + ++curLine; + lineStart = pos; + } else if (ch === 10 || ch === 13) { + if (type === "template") { + out += input.slice(chunkStart, pos) + "\n"; + ++pos; + if (ch === 13 && input.charCodeAt(pos) === 10) { + ++pos; + } + ++curLine; + chunkStart = lineStart = pos; + } else { + errors.unterminated(initialPos, initialLineStart, initialCurLine); + } + } else { + ++pos; + } + } + return { + pos, + str: out, + firstInvalidLoc, + lineStart, + curLine, + containsInvalid: !!firstInvalidLoc + }; + } + function isStringEnd(type, ch, input, pos) { + if (type === "template") { + return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123; + } + return ch === (type === "double" ? 34 : 39); + } + function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) { + const throwOnInvalid = !inTemplate; + pos++; + const res = ch => ({ + pos, + ch, + lineStart, + curLine + }); + const ch = input.charCodeAt(pos++); + switch (ch) { + case 110: + return res("\n"); + case 114: + return res("\r"); + case 120: + { + let code; + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors)); + return res(code === null ? null : String.fromCharCode(code)); + } + case 117: + { + let code; + ({ + code, + pos + } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors)); + return res(code === null ? null : String.fromCodePoint(code)); + } + case 116: + return res("\t"); + case 98: + return res("\b"); + case 118: + return res("\u000b"); + case 102: + return res("\f"); + case 13: + if (input.charCodeAt(pos) === 10) { + ++pos; + } + case 10: + lineStart = pos; + ++curLine; + case 8232: + case 8233: + return res(""); + case 56: + case 57: + if (inTemplate) { + return res(null); + } else { + errors.strictNumericEscape(pos - 1, lineStart, curLine); + } + default: + if (ch >= 48 && ch <= 55) { + const startPos = pos - 1; + const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2)); + let octalStr = match[0]; + let octal = parseInt(octalStr, 8); + if (octal > 255) { + octalStr = octalStr.slice(0, -1); + octal = parseInt(octalStr, 8); + } + pos += octalStr.length - 1; + const next = input.charCodeAt(pos); + if (octalStr !== "0" || next === 56 || next === 57) { + if (inTemplate) { + return res(null); + } else { + errors.strictNumericEscape(startPos, lineStart, curLine); + } + } + return res(String.fromCharCode(octal)); + } + return res(String.fromCharCode(ch)); + } + } + function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) { + const initialPos = pos; + let n; + ({ + n, + pos + } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid)); + if (n === null) { + if (throwOnInvalid) { + errors.invalidEscapeSequence(initialPos, lineStart, curLine); + } else { + pos = initialPos - 1; + } + } + return { + code: n, + pos + }; + } + function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) { + const start = pos; + const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct; + const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin; + let invalid = false; + let total = 0; + for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { + const code = input.charCodeAt(pos); + let val; + if (code === 95 && allowNumSeparator !== "bail") { + const prev = input.charCodeAt(pos - 1); + const next = input.charCodeAt(pos + 1); + if (!allowNumSeparator) { + if (bailOnError) return { + n: null, + pos + }; + errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine); + } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) { + if (bailOnError) return { + n: null, + pos + }; + errors.unexpectedNumericSeparator(pos, lineStart, curLine); + } + ++pos; + continue; + } + if (code >= 97) { + val = code - 97 + 10; + } else if (code >= 65) { + val = code - 65 + 10; + } else if (_isDigit(code)) { + val = code - 48; + } else { + val = Infinity; + } + if (val >= radix) { + if (val <= 9 && bailOnError) { + return { + n: null, + pos + }; + } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) { + val = 0; + } else if (forceLen) { + val = 0; + invalid = true; + } else { + break; + } + } + ++pos; + total = total * radix + val; + } + if (pos === start || len != null && pos - start !== len || invalid) { + return { + n: null, + pos + }; + } + return { + n: total, + pos + }; + } + function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) { + const ch = input.charCodeAt(pos); + let code; + if (ch === 123) { + ++pos; + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors)); + ++pos; + if (code !== null && code > 0x10ffff) { + if (throwOnInvalid) { + errors.invalidCodePoint(pos, lineStart, curLine); + } else { + return { + code: null, + pos + }; + } + } + } else { + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors)); + } + return { + code, + pos + }; + } + + + return lib$1; +} + +var constants = {}; + +var hasRequiredConstants; + +function requireConstants () { + if (hasRequiredConstants) return constants; + hasRequiredConstants = 1; + + Object.defineProperty(constants, "__esModule", { + value: true + }); + constants.UPDATE_OPERATORS = constants.UNARY_OPERATORS = constants.STRING_UNARY_OPERATORS = constants.STATEMENT_OR_BLOCK_KEYS = constants.NUMBER_UNARY_OPERATORS = constants.NUMBER_BINARY_OPERATORS = constants.NOT_LOCAL_BINDING = constants.LOGICAL_OPERATORS = constants.INHERIT_KEYS = constants.FOR_INIT_KEYS = constants.FLATTENABLE_KEYS = constants.EQUALITY_BINARY_OPERATORS = constants.COMPARISON_BINARY_OPERATORS = constants.COMMENT_KEYS = constants.BOOLEAN_UNARY_OPERATORS = constants.BOOLEAN_NUMBER_BINARY_OPERATORS = constants.BOOLEAN_BINARY_OPERATORS = constants.BLOCK_SCOPED_SYMBOL = constants.BINARY_OPERATORS = constants.ASSIGNMENT_OPERATORS = void 0; + constants.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; + constants.FLATTENABLE_KEYS = ["body", "expressions"]; + constants.FOR_INIT_KEYS = ["left", "init"]; + constants.COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"]; + const LOGICAL_OPERATORS = constants.LOGICAL_OPERATORS = ["||", "&&", "??"]; + constants.UPDATE_OPERATORS = ["++", "--"]; + const BOOLEAN_NUMBER_BINARY_OPERATORS = constants.BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="]; + const EQUALITY_BINARY_OPERATORS = constants.EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="]; + const COMPARISON_BINARY_OPERATORS = constants.COMPARISON_BINARY_OPERATORS = [...EQUALITY_BINARY_OPERATORS, "in", "instanceof"]; + const BOOLEAN_BINARY_OPERATORS = constants.BOOLEAN_BINARY_OPERATORS = [...COMPARISON_BINARY_OPERATORS, ...BOOLEAN_NUMBER_BINARY_OPERATORS]; + const NUMBER_BINARY_OPERATORS = constants.NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"]; + constants.BINARY_OPERATORS = ["+", ...NUMBER_BINARY_OPERATORS, ...BOOLEAN_BINARY_OPERATORS, "|>"]; + constants.ASSIGNMENT_OPERATORS = ["=", "+=", ...NUMBER_BINARY_OPERATORS.map(op => op + "="), ...LOGICAL_OPERATORS.map(op => op + "=")]; + const BOOLEAN_UNARY_OPERATORS = constants.BOOLEAN_UNARY_OPERATORS = ["delete", "!"]; + const NUMBER_UNARY_OPERATORS = constants.NUMBER_UNARY_OPERATORS = ["+", "-", "~"]; + const STRING_UNARY_OPERATORS = constants.STRING_UNARY_OPERATORS = ["typeof"]; + constants.UNARY_OPERATORS = ["void", "throw", ...BOOLEAN_UNARY_OPERATORS, ...NUMBER_UNARY_OPERATORS, ...STRING_UNARY_OPERATORS]; + constants.INHERIT_KEYS = { + optional: ["typeAnnotation", "typeParameters", "returnType"], + force: ["start", "loc", "end"] + }; + constants.BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); + constants.NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding"); + + + return constants; +} + +var utils = {}; + +var hasRequiredUtils; + +function requireUtils () { + if (hasRequiredUtils) return utils; + hasRequiredUtils = 1; + + Object.defineProperty(utils, "__esModule", { + value: true + }); + utils.VISITOR_KEYS = utils.NODE_PARENT_VALIDATIONS = utils.NODE_FIELDS = utils.FLIPPED_ALIAS_KEYS = utils.DEPRECATED_KEYS = utils.BUILDER_KEYS = utils.ALIAS_KEYS = void 0; + utils.arrayOf = arrayOf; + utils.arrayOfType = arrayOfType; + utils.assertEach = assertEach; + utils.assertNodeOrValueType = assertNodeOrValueType; + utils.assertNodeType = assertNodeType; + utils.assertOneOf = assertOneOf; + utils.assertOptionalChainStart = assertOptionalChainStart; + utils.assertShape = assertShape; + utils.assertValueType = assertValueType; + utils.chain = chain; + utils.default = defineType; + utils.defineAliasedType = defineAliasedType; + utils.validate = validate; + utils.validateArrayOfType = validateArrayOfType; + utils.validateOptional = validateOptional; + utils.validateOptionalType = validateOptionalType; + utils.validateType = validateType; + var _is = requireIs(); + var _validate = requireValidate(); + const VISITOR_KEYS = utils.VISITOR_KEYS = {}; + const ALIAS_KEYS = utils.ALIAS_KEYS = {}; + const FLIPPED_ALIAS_KEYS = utils.FLIPPED_ALIAS_KEYS = {}; + const NODE_FIELDS = utils.NODE_FIELDS = {}; + const BUILDER_KEYS = utils.BUILDER_KEYS = {}; + const DEPRECATED_KEYS = utils.DEPRECATED_KEYS = {}; + const NODE_PARENT_VALIDATIONS = utils.NODE_PARENT_VALIDATIONS = {}; + function getType(val) { + if (Array.isArray(val)) { + return "array"; + } else if (val === null) { + return "null"; + } else { + return typeof val; + } + } + function validate(validate) { + return { + validate + }; + } + function validateType(...typeNames) { + return validate(assertNodeType(...typeNames)); + } + function validateOptional(validate) { + return { + validate, + optional: true + }; + } + function validateOptionalType(...typeNames) { + return { + validate: assertNodeType(...typeNames), + optional: true + }; + } + function arrayOf(elementType) { + return chain(assertValueType("array"), assertEach(elementType)); + } + function arrayOfType(...typeNames) { + return arrayOf(assertNodeType(...typeNames)); + } + function validateArrayOfType(...typeNames) { + return validate(arrayOfType(...typeNames)); + } + function assertEach(callback) { + const childValidator = process.env.BABEL_TYPES_8_BREAKING ? _validate.validateChild : () => {}; + function validator(node, key, val) { + if (!Array.isArray(val)) return; + for (let i = 0; i < val.length; i++) { + const subkey = `${key}[${i}]`; + const v = val[i]; + callback(node, subkey, v); + childValidator(node, subkey, v); + } + } + validator.each = callback; + return validator; + } + function assertOneOf(...values) { + function validate(node, key, val) { + if (!values.includes(val)) { + throw new TypeError(`Property ${key} expected value to be one of ${JSON.stringify(values)} but got ${JSON.stringify(val)}`); + } + } + validate.oneOf = values; + return validate; + } + function assertNodeType(...types) { + function validate(node, key, val) { + for (const type of types) { + if ((0, _is.default)(type, val)) { + (0, _validate.validateChild)(node, key, val); + return; + } + } + throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`); + } + validate.oneOfNodeTypes = types; + return validate; + } + function assertNodeOrValueType(...types) { + function validate(node, key, val) { + for (const type of types) { + if (getType(val) === type || (0, _is.default)(type, val)) { + (0, _validate.validateChild)(node, key, val); + return; + } + } + throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`); + } + validate.oneOfNodeOrValueTypes = types; + return validate; + } + function assertValueType(type) { + function validate(node, key, val) { + const valid = getType(val) === type; + if (!valid) { + throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); + } + } + validate.type = type; + return validate; + } + function assertShape(shape) { + function validate(node, key, val) { + const errors = []; + for (const property of Object.keys(shape)) { + try { + (0, _validate.validateField)(node, property, val[property], shape[property]); + } catch (error) { + if (error instanceof TypeError) { + errors.push(error.message); + continue; + } + throw error; + } + } + if (errors.length) { + throw new TypeError(`Property ${key} of ${node.type} expected to have the following:\n${errors.join("\n")}`); + } + } + validate.shapeOf = shape; + return validate; + } + function assertOptionalChainStart() { + function validate(node) { + var _current; + let current = node; + while (node) { + const { + type + } = current; + if (type === "OptionalCallExpression") { + if (current.optional) return; + current = current.callee; + continue; + } + if (type === "OptionalMemberExpression") { + if (current.optional) return; + current = current.object; + continue; + } + break; + } + throw new TypeError(`Non-optional ${node.type} must chain from an optional OptionalMemberExpression or OptionalCallExpression. Found chain from ${(_current = current) == null ? void 0 : _current.type}`); + } + return validate; + } + function chain(...fns) { + function validate(...args) { + for (const fn of fns) { + fn(...args); + } + } + validate.chainOf = fns; + if (fns.length >= 2 && "type" in fns[0] && fns[0].type === "array" && !("each" in fns[1])) { + throw new Error(`An assertValueType("array") validator can only be followed by an assertEach(...) validator.`); + } + return validate; + } + const validTypeOpts = new Set(["aliases", "builder", "deprecatedAlias", "fields", "inherits", "visitor", "validate"]); + const validFieldKeys = new Set(["default", "optional", "deprecated", "validate"]); + const store = {}; + function defineAliasedType(...aliases) { + return (type, opts = {}) => { + let defined = opts.aliases; + if (!defined) { + var _store$opts$inherits$, _defined; + if (opts.inherits) defined = (_store$opts$inherits$ = store[opts.inherits].aliases) == null ? void 0 : _store$opts$inherits$.slice(); + (_defined = defined) != null ? _defined : defined = []; + opts.aliases = defined; + } + const additional = aliases.filter(a => !defined.includes(a)); + defined.unshift(...additional); + defineType(type, opts); + }; + } + function defineType(type, opts = {}) { + const inherits = opts.inherits && store[opts.inherits] || {}; + let fields = opts.fields; + if (!fields) { + fields = {}; + if (inherits.fields) { + const keys = Object.getOwnPropertyNames(inherits.fields); + for (const key of keys) { + const field = inherits.fields[key]; + const def = field.default; + if (Array.isArray(def) ? def.length > 0 : def && typeof def === "object") { + throw new Error("field defaults can only be primitives or empty arrays currently"); + } + fields[key] = { + default: Array.isArray(def) ? [] : def, + optional: field.optional, + deprecated: field.deprecated, + validate: field.validate + }; + } + } + } + const visitor = opts.visitor || inherits.visitor || []; + const aliases = opts.aliases || inherits.aliases || []; + const builder = opts.builder || inherits.builder || opts.visitor || []; + for (const k of Object.keys(opts)) { + if (!validTypeOpts.has(k)) { + throw new Error(`Unknown type option "${k}" on ${type}`); + } + } + if (opts.deprecatedAlias) { + DEPRECATED_KEYS[opts.deprecatedAlias] = type; + } + for (const key of visitor.concat(builder)) { + fields[key] = fields[key] || {}; + } + for (const key of Object.keys(fields)) { + const field = fields[key]; + if (field.default !== undefined && !builder.includes(key)) { + field.optional = true; + } + if (field.default === undefined) { + field.default = null; + } else if (!field.validate && field.default != null) { + field.validate = assertValueType(getType(field.default)); + } + for (const k of Object.keys(field)) { + if (!validFieldKeys.has(k)) { + throw new Error(`Unknown field key "${k}" on ${type}.${key}`); + } + } + } + VISITOR_KEYS[type] = opts.visitor = visitor; + BUILDER_KEYS[type] = opts.builder = builder; + NODE_FIELDS[type] = opts.fields = fields; + ALIAS_KEYS[type] = opts.aliases = aliases; + aliases.forEach(alias => { + FLIPPED_ALIAS_KEYS[alias] = FLIPPED_ALIAS_KEYS[alias] || []; + FLIPPED_ALIAS_KEYS[alias].push(type); + }); + if (opts.validate) { + NODE_PARENT_VALIDATIONS[type] = opts.validate; + } + store[type] = opts; + } + + + return utils; +} + +var hasRequiredCore; + +function requireCore () { + if (hasRequiredCore) return core; + hasRequiredCore = 1; + + Object.defineProperty(core, "__esModule", { + value: true + }); + core.patternLikeCommon = core.importAttributes = core.functionTypeAnnotationCommon = core.functionDeclarationCommon = core.functionCommon = core.classMethodOrPropertyCommon = core.classMethodOrDeclareMethodCommon = void 0; + var _is = requireIs(); + var _isValidIdentifier = requireIsValidIdentifier(); + var _helperValidatorIdentifier = requireLib$3(); + var _helperStringParser = requireLib$2(); + var _index = requireConstants(); + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("Standardized"); + defineType("ArrayExpression", { + fields: { + elements: { + validate: (0, _utils.arrayOf)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement")), + default: !process.env.BABEL_TYPES_8_BREAKING ? [] : undefined + } + }, + visitor: ["elements"], + aliases: ["Expression"] + }); + defineType("AssignmentExpression", { + fields: { + operator: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("string") : Object.assign(function () { + const identifier = (0, _utils.assertOneOf)(..._index.ASSIGNMENT_OPERATORS); + const pattern = (0, _utils.assertOneOf)("="); + return function (node, key, val) { + const validator = (0, _is.default)("Pattern", node.left) ? pattern : identifier; + validator(node, key, val); + }; + }(), { + type: "string" + }) + }, + left: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal", "OptionalMemberExpression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression", "OptionalMemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + builder: ["operator", "left", "right"], + visitor: ["left", "right"], + aliases: ["Expression"] + }); + defineType("BinaryExpression", { + builder: ["operator", "left", "right"], + fields: { + operator: { + validate: (0, _utils.assertOneOf)(..._index.BINARY_OPERATORS) + }, + left: { + validate: function () { + const expression = (0, _utils.assertNodeType)("Expression"); + const inOp = (0, _utils.assertNodeType)("Expression", "PrivateName"); + const validator = Object.assign(function (node, key, val) { + const validator = node.operator === "in" ? inOp : expression; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "PrivateName"] + }); + return validator; + }() + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + visitor: ["left", "right"], + aliases: ["Binary", "Expression"] + }); + defineType("InterpreterDirective", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("Directive", { + visitor: ["value"], + fields: { + value: { + validate: (0, _utils.assertNodeType)("DirectiveLiteral") + } + } + }); + defineType("DirectiveLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("BlockStatement", { + builder: ["body", "directives"], + visitor: ["directives", "body"], + fields: { + directives: { + validate: (0, _utils.arrayOfType)("Directive"), + default: [] + }, + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "Block", "Statement"] + }); + defineType("BreakStatement", { + visitor: ["label"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }, + aliases: ["Statement", "Terminatorless", "CompletionStatement"] + }); + defineType("CallExpression", { + visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + builder: ["callee", "arguments"], + aliases: ["Expression"], + fields: Object.assign({ + callee: { + validate: (0, _utils.assertNodeType)("Expression", "Super", "V8IntrinsicIdentifier") + }, + arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder") + }, !process.env.BABEL_TYPES_8_BREAKING ? { + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + } : {}, { + typeArguments: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"), + optional: true + } + }) + }); + defineType("CatchClause", { + visitor: ["param", "body"], + fields: { + param: { + validate: (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }, + aliases: ["Scopable", "BlockParent"] + }); + defineType("ConditionalExpression", { + visitor: ["test", "consequent", "alternate"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + consequent: { + validate: (0, _utils.assertNodeType)("Expression") + }, + alternate: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression", "Conditional"] + }); + defineType("ContinueStatement", { + visitor: ["label"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }, + aliases: ["Statement", "Terminatorless", "CompletionStatement"] + }); + defineType("DebuggerStatement", { + aliases: ["Statement"] + }); + defineType("DoWhileStatement", { + builder: ["test", "body"], + visitor: ["body", "test"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + }, + aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"] + }); + defineType("EmptyStatement", { + aliases: ["Statement"] + }); + defineType("ExpressionStatement", { + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Statement", "ExpressionWrapper"] + }); + defineType("File", { + builder: ["program", "comments", "tokens"], + visitor: ["program"], + fields: { + program: { + validate: (0, _utils.assertNodeType)("Program") + }, + comments: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? Object.assign(() => {}, { + each: { + oneOfNodeTypes: ["CommentBlock", "CommentLine"] + } + }) : (0, _utils.assertEach)((0, _utils.assertNodeType)("CommentBlock", "CommentLine")), + optional: true + }, + tokens: { + validate: (0, _utils.assertEach)(Object.assign(() => {}, { + type: "any" + })), + optional: true + } + } + }); + defineType("ForInStatement", { + visitor: ["left", "right", "body"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], + fields: { + left: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("VariableDeclaration", "LVal") : (0, _utils.assertNodeType)("VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("ForStatement", { + visitor: ["init", "test", "update", "body"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"], + fields: { + init: { + validate: (0, _utils.assertNodeType)("VariableDeclaration", "Expression"), + optional: true + }, + test: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + update: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + const functionCommon = () => ({ + params: (0, _utils.validateArrayOfType)("Identifier", "Pattern", "RestElement"), + generator: { + default: false + }, + async: { + default: false + } + }); + core.functionCommon = functionCommon; + const functionTypeAnnotationCommon = () => ({ + returnType: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + } + }); + core.functionTypeAnnotationCommon = functionTypeAnnotationCommon; + const functionDeclarationCommon = () => Object.assign({}, functionCommon(), { + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }); + core.functionDeclarationCommon = functionDeclarationCommon; + defineType("FunctionDeclaration", { + builder: ["id", "params", "body", "generator", "async"], + visitor: ["id", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, functionDeclarationCommon(), functionTypeAnnotationCommon(), { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }), + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pureish", "Declaration"], + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const identifier = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if (!(0, _is.default)("ExportDefaultDeclaration", parent)) { + identifier(node, "id", node.id); + } + }; + }() + }); + defineType("FunctionExpression", { + inherits: "FunctionDeclaration", + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }) + }); + const patternLikeCommon = () => ({ + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }); + core.patternLikeCommon = patternLikeCommon; + defineType("Identifier", { + builder: ["name"], + visitor: ["typeAnnotation", "decorators"], + aliases: ["Expression", "PatternLike", "LVal", "TSEntityName"], + fields: Object.assign({}, patternLikeCommon(), { + name: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) { + if (!(0, _isValidIdentifier.default)(val, false)) { + throw new TypeError(`"${val}" is not a valid identifier name`); + } + }, { + type: "string" + })) : (0, _utils.assertValueType)("string") + } + }), + validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key, node) { + const match = /\.(\w+)$/.exec(key); + if (!match) return; + const [, parentKey] = match; + const nonComp = { + computed: false + }; + if (parentKey === "property") { + if ((0, _is.default)("MemberExpression", parent, nonComp)) return; + if ((0, _is.default)("OptionalMemberExpression", parent, nonComp)) return; + } else if (parentKey === "key") { + if ((0, _is.default)("Property", parent, nonComp)) return; + if ((0, _is.default)("Method", parent, nonComp)) return; + } else if (parentKey === "exported") { + if ((0, _is.default)("ExportSpecifier", parent)) return; + } else if (parentKey === "imported") { + if ((0, _is.default)("ImportSpecifier", parent, { + imported: node + })) return; + } else if (parentKey === "meta") { + if ((0, _is.default)("MetaProperty", parent, { + meta: node + })) return; + } + if (((0, _helperValidatorIdentifier.isKeyword)(node.name) || (0, _helperValidatorIdentifier.isReservedWord)(node.name, false)) && node.name !== "this") { + throw new TypeError(`"${node.name}" is not a valid identifier`); + } + } : undefined + }); + defineType("IfStatement", { + visitor: ["test", "consequent", "alternate"], + aliases: ["Statement", "Conditional"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + consequent: { + validate: (0, _utils.assertNodeType)("Statement") + }, + alternate: { + optional: true, + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("LabeledStatement", { + visitor: ["label", "body"], + aliases: ["Statement"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("StringLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("NumericLiteral", { + builder: ["value"], + deprecatedAlias: "NumberLiteral", + fields: { + value: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("number"), Object.assign(function (node, key, val) { + }, { + type: "number" + })) + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("NullLiteral", { + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("BooleanLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("boolean") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("RegExpLiteral", { + builder: ["pattern", "flags"], + deprecatedAlias: "RegexLiteral", + aliases: ["Expression", "Pureish", "Literal"], + fields: { + pattern: { + validate: (0, _utils.assertValueType)("string") + }, + flags: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) { + const invalid = /[^gimsuy]/.exec(val); + if (invalid) { + throw new TypeError(`"${invalid[0]}" is not a valid RegExp flag`); + } + }, { + type: "string" + })) : (0, _utils.assertValueType)("string"), + default: "" + } + } + }); + defineType("LogicalExpression", { + builder: ["operator", "left", "right"], + visitor: ["left", "right"], + aliases: ["Binary", "Expression"], + fields: { + operator: { + validate: (0, _utils.assertOneOf)(..._index.LOGICAL_OPERATORS) + }, + left: { + validate: (0, _utils.assertNodeType)("Expression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("MemberExpression", { + builder: ["object", "property", "computed", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["optional"] : [])], + visitor: ["object", "property"], + aliases: ["Expression", "LVal"], + fields: Object.assign({ + object: { + validate: (0, _utils.assertNodeType)("Expression", "Super") + }, + property: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + validator.oneOfNodeTypes = ["Expression", "Identifier", "PrivateName"]; + return validator; + }() + }, + computed: { + default: false + } + }, !process.env.BABEL_TYPES_8_BREAKING ? { + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + } : {}) + }); + defineType("NewExpression", { + inherits: "CallExpression" + }); + defineType("Program", { + visitor: ["directives", "body"], + builder: ["body", "directives", "sourceType", "interpreter"], + fields: { + sourceType: { + validate: (0, _utils.assertOneOf)("script", "module"), + default: "script" + }, + interpreter: { + validate: (0, _utils.assertNodeType)("InterpreterDirective"), + default: null, + optional: true + }, + directives: { + validate: (0, _utils.arrayOfType)("Directive"), + default: [] + }, + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "Block"] + }); + defineType("ObjectExpression", { + visitor: ["properties"], + aliases: ["Expression"], + fields: { + properties: (0, _utils.validateArrayOfType)("ObjectMethod", "ObjectProperty", "SpreadElement") + } + }); + defineType("ObjectMethod", { + builder: ["kind", "key", "params", "body", "computed", "generator", "async"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + kind: Object.assign({ + validate: (0, _utils.assertOneOf)("method", "get", "set") + }, !process.env.BABEL_TYPES_8_BREAKING ? { + default: "method" + } : {}), + computed: { + default: false + }, + key: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + validator.oneOfNodeTypes = ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"]; + return validator; + }() + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }), + aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"] + }); + defineType("ObjectProperty", { + builder: ["key", "value", "computed", "shorthand", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["decorators"] : [])], + fields: { + computed: { + default: false + }, + key: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = Object.assign(function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName"] + }); + return validator; + }() + }, + value: { + validate: (0, _utils.assertNodeType)("Expression", "PatternLike") + }, + shorthand: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, shorthand) { + if (!shorthand) return; + if (node.computed) { + throw new TypeError("Property shorthand of ObjectProperty cannot be true if computed is true"); + } + if (!(0, _is.default)("Identifier", node.key)) { + throw new TypeError("Property shorthand of ObjectProperty cannot be true if key is not an Identifier"); + } + }, { + type: "boolean" + })) : (0, _utils.assertValueType)("boolean"), + default: false + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }, + visitor: ["key", "value", "decorators"], + aliases: ["UserWhitespacable", "Property", "ObjectMember"], + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const pattern = (0, _utils.assertNodeType)("Identifier", "Pattern", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"); + const expression = (0, _utils.assertNodeType)("Expression"); + return function (parent, key, node) { + const validator = (0, _is.default)("ObjectPattern", parent) ? pattern : expression; + validator(node, "value", node.value); + }; + }() + }); + defineType("RestElement", { + visitor: ["argument", "typeAnnotation"], + builder: ["argument"], + aliases: ["LVal", "PatternLike"], + deprecatedAlias: "RestProperty", + fields: Object.assign({}, patternLikeCommon(), { + argument: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + } + }), + validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key) { + const match = /(\w+)\[(\d+)\]/.exec(key); + if (!match) throw new Error("Internal Babel error: malformed key."); + const [, listKey, index] = match; + if (parent[listKey].length > +index + 1) { + throw new TypeError(`RestElement must be last element of ${listKey}`); + } + } : undefined + }); + defineType("ReturnStatement", { + visitor: ["argument"], + aliases: ["Statement", "Terminatorless", "CompletionStatement"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("SequenceExpression", { + visitor: ["expressions"], + fields: { + expressions: (0, _utils.validateArrayOfType)("Expression") + }, + aliases: ["Expression"] + }); + defineType("ParenthesizedExpression", { + visitor: ["expression"], + aliases: ["Expression", "ExpressionWrapper"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("SwitchCase", { + visitor: ["test", "consequent"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + consequent: (0, _utils.validateArrayOfType)("Statement") + } + }); + defineType("SwitchStatement", { + visitor: ["discriminant", "cases"], + aliases: ["Statement", "BlockParent", "Scopable"], + fields: { + discriminant: { + validate: (0, _utils.assertNodeType)("Expression") + }, + cases: (0, _utils.validateArrayOfType)("SwitchCase") + } + }); + defineType("ThisExpression", { + aliases: ["Expression"] + }); + defineType("ThrowStatement", { + visitor: ["argument"], + aliases: ["Statement", "Terminatorless", "CompletionStatement"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("TryStatement", { + visitor: ["block", "handler", "finalizer"], + aliases: ["Statement"], + fields: { + block: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("BlockStatement"), Object.assign(function (node) { + if (!node.handler && !node.finalizer) { + throw new TypeError("TryStatement expects either a handler or finalizer, or both"); + } + }, { + oneOfNodeTypes: ["BlockStatement"] + })) : (0, _utils.assertNodeType)("BlockStatement") + }, + handler: { + optional: true, + validate: (0, _utils.assertNodeType)("CatchClause") + }, + finalizer: { + optional: true, + validate: (0, _utils.assertNodeType)("BlockStatement") + } + } + }); + defineType("UnaryExpression", { + builder: ["operator", "argument", "prefix"], + fields: { + prefix: { + default: true + }, + argument: { + validate: (0, _utils.assertNodeType)("Expression") + }, + operator: { + validate: (0, _utils.assertOneOf)(..._index.UNARY_OPERATORS) + } + }, + visitor: ["argument"], + aliases: ["UnaryLike", "Expression"] + }); + defineType("UpdateExpression", { + builder: ["operator", "argument", "prefix"], + fields: { + prefix: { + default: false + }, + argument: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("Expression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression") + }, + operator: { + validate: (0, _utils.assertOneOf)(..._index.UPDATE_OPERATORS) + } + }, + visitor: ["argument"], + aliases: ["Expression"] + }); + defineType("VariableDeclaration", { + builder: ["kind", "declarations"], + visitor: ["declarations"], + aliases: ["Statement", "Declaration"], + fields: { + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + kind: { + validate: (0, _utils.assertOneOf)("var", "let", "const", "using", "await using") + }, + declarations: (0, _utils.validateArrayOfType)("VariableDeclarator") + }, + validate: process.env.BABEL_TYPES_8_BREAKING ? (() => { + const withoutInit = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if ((0, _is.default)("ForXStatement", parent, { + left: node + })) { + if (node.declarations.length !== 1) { + throw new TypeError(`Exactly one VariableDeclarator is required in the VariableDeclaration of a ${parent.type}`); + } + } else { + node.declarations.forEach(decl => { + if (!decl.init) withoutInit(decl, "id", decl.id); + }); + } + }; + })() : undefined + }); + defineType("VariableDeclarator", { + visitor: ["id", "init"], + fields: { + id: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern") + }, + definite: { + optional: true, + validate: (0, _utils.assertValueType)("boolean") + }, + init: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("WhileStatement", { + visitor: ["test", "body"], + aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("WithStatement", { + visitor: ["object", "body"], + aliases: ["Statement"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("AssignmentPattern", { + visitor: ["left", "right", "decorators"], + builder: ["left", "right"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + left: { + validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }) + }); + defineType("ArrayPattern", { + visitor: ["elements", "typeAnnotation"], + builder: ["elements"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + elements: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "PatternLike", "LVal"))) + } + }) + }); + defineType("ArrowFunctionExpression", { + builder: ["params", "body", "async"], + visitor: ["typeParameters", "params", "returnType", "body"], + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + expression: { + validate: (0, _utils.assertValueType)("boolean") + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement", "Expression") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }) + }); + defineType("ClassBody", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("ClassMethod", "ClassPrivateMethod", "ClassProperty", "ClassPrivateProperty", "ClassAccessorProperty", "TSDeclareMethod", "TSIndexSignature", "StaticBlock") + } + }); + defineType("ClassExpression", { + builder: ["id", "superClass", "body", "decorators"], + visitor: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "mixins", "implements", "body"], + aliases: ["Scopable", "Class", "Expression"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("ClassBody") + }, + superClass: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + }, + superTypeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + }, + implements: { + validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + mixins: { + validate: (0, _utils.assertNodeType)("InterfaceExtends"), + optional: true + } + } + }); + defineType("ClassDeclaration", { + inherits: "ClassExpression", + aliases: ["Scopable", "Class", "Statement", "Declaration"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("ClassBody") + }, + superClass: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + }, + superTypeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + }, + implements: { + validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + mixins: { + validate: (0, _utils.assertNodeType)("InterfaceExtends"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + abstract: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + }, + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const identifier = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if (!(0, _is.default)("ExportDefaultDeclaration", parent)) { + identifier(node, "id", node.id); + } + }; + }() + }); + const importAttributes = core.importAttributes = { + attributes: { + optional: true, + validate: (0, _utils.arrayOfType)("ImportAttribute") + }, + assertions: { + deprecated: true, + optional: true, + validate: (0, _utils.arrayOfType)("ImportAttribute") + } + }; + defineType("ExportAllDeclaration", { + builder: ["source"], + visitor: ["source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: Object.assign({ + source: { + validate: (0, _utils.assertNodeType)("StringLiteral") + }, + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }, importAttributes) + }); + defineType("ExportDefaultDeclaration", { + visitor: ["declaration"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: { + declaration: (0, _utils.validateType)("TSDeclareFunction", "FunctionDeclaration", "ClassDeclaration", "Expression"), + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("value")) + } + }); + defineType("ExportNamedDeclaration", { + builder: ["declaration", "specifiers", "source"], + visitor: process.env ? ["declaration", "specifiers", "source", "attributes"] : ["declaration", "specifiers", "source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: Object.assign({ + declaration: { + optional: true, + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Declaration"), Object.assign(function (node, key, val) { + if (val && node.specifiers.length) { + throw new TypeError("Only declaration or specifiers is allowed on ExportNamedDeclaration"); + } + if (val && node.source) { + throw new TypeError("Cannot export a declaration from a source"); + } + }, { + oneOfNodeTypes: ["Declaration"] + })) : (0, _utils.assertNodeType)("Declaration") + } + }, importAttributes, { + specifiers: { + default: [], + validate: (0, _utils.arrayOf)(function () { + const sourced = (0, _utils.assertNodeType)("ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier"); + const sourceless = (0, _utils.assertNodeType)("ExportSpecifier"); + if (!process.env.BABEL_TYPES_8_BREAKING) return sourced; + return Object.assign(function (node, key, val) { + const validator = node.source ? sourced : sourceless; + validator(node, key, val); + }, { + oneOfNodeTypes: ["ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier"] + }); + }()) + }, + source: { + validate: (0, _utils.assertNodeType)("StringLiteral"), + optional: true + }, + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }) + }); + defineType("ExportSpecifier", { + visitor: ["local", "exported"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + exported: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + exportKind: { + validate: (0, _utils.assertOneOf)("type", "value"), + optional: true + } + } + }); + defineType("ForOfStatement", { + visitor: ["left", "right", "body"], + builder: ["left", "right", "body", "await"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], + fields: { + left: { + validate: function () { + if (!process.env.BABEL_TYPES_8_BREAKING) { + return (0, _utils.assertNodeType)("VariableDeclaration", "LVal"); + } + const declaration = (0, _utils.assertNodeType)("VariableDeclaration"); + const lval = (0, _utils.assertNodeType)("Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression"); + return Object.assign(function (node, key, val) { + if ((0, _is.default)("VariableDeclaration", val)) { + declaration(node, key, val); + } else { + lval(node, key, val); + } + }, { + oneOfNodeTypes: ["VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression"] + }); + }() + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + }, + await: { + default: false + } + } + }); + defineType("ImportDeclaration", { + builder: ["specifiers", "source"], + visitor: ["specifiers", "source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration"], + fields: Object.assign({}, importAttributes, { + module: { + optional: true, + validate: (0, _utils.assertValueType)("boolean") + }, + phase: { + default: null, + validate: (0, _utils.assertOneOf)("source", "defer") + }, + specifiers: (0, _utils.validateArrayOfType)("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier"), + source: { + validate: (0, _utils.assertNodeType)("StringLiteral") + }, + importKind: { + validate: (0, _utils.assertOneOf)("type", "typeof", "value"), + optional: true + } + }) + }); + defineType("ImportDefaultSpecifier", { + visitor: ["local"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("ImportNamespaceSpecifier", { + visitor: ["local"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("ImportSpecifier", { + visitor: ["imported", "local"], + builder: ["local", "imported"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + imported: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + importKind: { + validate: (0, _utils.assertOneOf)("type", "typeof", "value"), + optional: true + } + } + }); + defineType("ImportExpression", { + visitor: ["source", "options"], + aliases: ["Expression"], + fields: { + phase: { + default: null, + validate: (0, _utils.assertOneOf)("source", "defer") + }, + source: { + validate: (0, _utils.assertNodeType)("Expression") + }, + options: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("MetaProperty", { + visitor: ["meta", "property"], + aliases: ["Expression"], + fields: { + meta: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Identifier"), Object.assign(function (node, key, val) { + let property; + switch (val.name) { + case "function": + property = "sent"; + break; + case "new": + property = "target"; + break; + case "import": + property = "meta"; + break; + } + if (!(0, _is.default)("Identifier", node.property, { + name: property + })) { + throw new TypeError("Unrecognised MetaProperty"); + } + }, { + oneOfNodeTypes: ["Identifier"] + })) : (0, _utils.assertNodeType)("Identifier") + }, + property: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + const classMethodOrPropertyCommon = () => ({ + abstract: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + accessibility: { + validate: (0, _utils.assertOneOf)("public", "private", "protected"), + optional: true + }, + static: { + default: false + }, + override: { + default: false + }, + computed: { + default: false + }, + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + key: { + validate: (0, _utils.chain)(function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"); + const computed = (0, _utils.assertNodeType)("Expression"); + return function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression")) + } + }); + core.classMethodOrPropertyCommon = classMethodOrPropertyCommon; + const classMethodOrDeclareMethodCommon = () => Object.assign({}, functionCommon(), classMethodOrPropertyCommon(), { + params: (0, _utils.validateArrayOfType)("Identifier", "Pattern", "RestElement", "TSParameterProperty"), + kind: { + validate: (0, _utils.assertOneOf)("get", "set", "method", "constructor"), + default: "method" + }, + access: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("public", "private", "protected")), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }); + core.classMethodOrDeclareMethodCommon = classMethodOrDeclareMethodCommon; + defineType("ClassMethod", { + aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"], + builder: ["kind", "key", "params", "body", "computed", "static", "generator", "async"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }) + }); + defineType("ObjectPattern", { + visitor: ["properties", "typeAnnotation", "decorators"], + builder: ["properties"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + properties: (0, _utils.validateArrayOfType)("RestElement", "ObjectProperty") + }) + }); + defineType("SpreadElement", { + visitor: ["argument"], + aliases: ["UnaryLike"], + deprecatedAlias: "SpreadProperty", + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("Super", { + aliases: ["Expression"] + }); + defineType("TaggedTemplateExpression", { + visitor: ["tag", "typeParameters", "quasi"], + builder: ["tag", "quasi"], + aliases: ["Expression"], + fields: { + tag: { + validate: (0, _utils.assertNodeType)("Expression") + }, + quasi: { + validate: (0, _utils.assertNodeType)("TemplateLiteral") + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("TemplateElement", { + builder: ["value", "tail"], + fields: { + value: { + validate: (0, _utils.chain)((0, _utils.assertShape)({ + raw: { + validate: (0, _utils.assertValueType)("string") + }, + cooked: { + validate: (0, _utils.assertValueType)("string"), + optional: true + } + }), function templateElementCookedValidator(node) { + const raw = node.value.raw; + let unterminatedCalled = false; + const error = () => { + throw new Error("Internal @babel/types error."); + }; + const { + str, + firstInvalidLoc + } = (0, _helperStringParser.readStringContents)("template", raw, 0, 0, 0, { + unterminated() { + unterminatedCalled = true; + }, + strictNumericEscape: error, + invalidEscapeSequence: error, + numericSeparatorInEscapeSequence: error, + unexpectedNumericSeparator: error, + invalidDigit: error, + invalidCodePoint: error + }); + if (!unterminatedCalled) throw new Error("Invalid raw"); + node.value.cooked = firstInvalidLoc ? null : str; + }) + }, + tail: { + default: false + } + } + }); + defineType("TemplateLiteral", { + visitor: ["quasis", "expressions"], + aliases: ["Expression", "Literal"], + fields: { + quasis: (0, _utils.validateArrayOfType)("TemplateElement"), + expressions: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "TSType")), function (node, key, val) { + if (node.quasis.length !== val.length + 1) { + throw new TypeError(`Number of ${node.type} quasis should be exactly one more than the number of expressions.\nExpected ${val.length + 1} quasis but got ${node.quasis.length}`); + } + }) + } + } + }); + defineType("YieldExpression", { + builder: ["argument", "delegate"], + visitor: ["argument"], + aliases: ["Expression", "Terminatorless"], + fields: { + delegate: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, val) { + if (val && !node.argument) { + throw new TypeError("Property delegate of YieldExpression cannot be true if there is no argument"); + } + }, { + type: "boolean" + })) : (0, _utils.assertValueType)("boolean"), + default: false + }, + argument: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("AwaitExpression", { + builder: ["argument"], + visitor: ["argument"], + aliases: ["Expression", "Terminatorless"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("Import", { + aliases: ["Expression"] + }); + defineType("BigIntLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("ExportNamespaceSpecifier", { + visitor: ["exported"], + aliases: ["ModuleSpecifier"], + fields: { + exported: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("OptionalMemberExpression", { + builder: ["object", "property", "computed", "optional"], + visitor: ["object", "property"], + aliases: ["Expression"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + property: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = Object.assign(function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "Identifier"] + }); + return validator; + }() + }, + computed: { + default: false + }, + optional: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)()) + } + } + }); + defineType("OptionalCallExpression", { + visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + builder: ["callee", "arguments", "optional"], + aliases: ["Expression"], + fields: { + callee: { + validate: (0, _utils.assertNodeType)("Expression") + }, + arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder"), + optional: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)()) + }, + typeArguments: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("ClassProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"], + aliases: ["Property"], + fields: Object.assign({}, classMethodOrPropertyCommon(), { + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + }) + }); + defineType("ClassAccessorProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"], + aliases: ["Property", "Accessor"], + fields: Object.assign({}, classMethodOrPropertyCommon(), { + key: { + validate: (0, _utils.chain)(function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + return function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression", "PrivateName")) + }, + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + }) + }); + defineType("ClassPrivateProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "decorators", "static"], + aliases: ["Property", "Private"], + fields: { + key: { + validate: (0, _utils.assertNodeType)("PrivateName") + }, + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + static: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + } + }); + defineType("ClassPrivateMethod", { + builder: ["kind", "key", "params", "body", "static"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method", "Private"], + fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), { + kind: { + validate: (0, _utils.assertOneOf)("get", "set", "method"), + default: "method" + }, + key: { + validate: (0, _utils.assertNodeType)("PrivateName") + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }) + }); + defineType("PrivateName", { + visitor: ["id"], + aliases: ["Private"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("StaticBlock", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "FunctionParent"] + }); + + + return core; +} + +var flow$1 = {}; + +var hasRequiredFlow$1; + +function requireFlow$1 () { + if (hasRequiredFlow$1) return flow$1; + hasRequiredFlow$1 = 1; + + var _core = requireCore(); + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("Flow"); + const defineInterfaceishType = name => { + const isDeclareClass = name === "DeclareClass"; + defineType(name, { + builder: ["id", "typeParameters", "extends", "body"], + visitor: ["id", "typeParameters", "extends", ...(isDeclareClass ? ["mixins", "implements"] : []), "body"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")) + }, isDeclareClass ? { + mixins: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")), + implements: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ClassImplements")) + } : {}, { + body: (0, _utils.validateType)("ObjectTypeAnnotation") + }) + }); + }; + defineType("AnyTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ArrayTypeAnnotation", { + visitor: ["elementType"], + aliases: ["FlowType"], + fields: { + elementType: (0, _utils.validateType)("FlowType") + } + }); + defineType("BooleanTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("BooleanLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("NullLiteralTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ClassImplements", { + visitor: ["id", "typeParameters"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineInterfaceishType("DeclareClass"); + defineType("DeclareFunction", { + visitor: ["id"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + predicate: (0, _utils.validateOptionalType)("DeclaredPredicate") + } + }); + defineInterfaceishType("DeclareInterface"); + defineType("DeclareModule", { + builder: ["id", "body", "kind"], + visitor: ["id", "body"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + body: (0, _utils.validateType)("BlockStatement"), + kind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("CommonJS", "ES")) + } + }); + defineType("DeclareModuleExports", { + visitor: ["typeAnnotation"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + typeAnnotation: (0, _utils.validateType)("TypeAnnotation") + } + }); + defineType("DeclareTypeAlias", { + visitor: ["id", "typeParameters", "right"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + right: (0, _utils.validateType)("FlowType") + } + }); + defineType("DeclareOpaqueType", { + visitor: ["id", "typeParameters", "supertype"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + supertype: (0, _utils.validateOptionalType)("FlowType"), + impltype: (0, _utils.validateOptionalType)("FlowType") + } + }); + defineType("DeclareVariable", { + visitor: ["id"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("DeclareExportDeclaration", { + visitor: ["declaration", "specifiers", "source", "attributes"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + declaration: (0, _utils.validateOptionalType)("Flow"), + specifiers: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ExportSpecifier", "ExportNamespaceSpecifier")), + source: (0, _utils.validateOptionalType)("StringLiteral"), + default: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + }, _core.importAttributes) + }); + defineType("DeclareExportAllDeclaration", { + visitor: ["source", "attributes"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + source: (0, _utils.validateType)("StringLiteral"), + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }, _core.importAttributes) + }); + defineType("DeclaredPredicate", { + visitor: ["value"], + aliases: ["FlowPredicate"], + fields: { + value: (0, _utils.validateType)("Flow") + } + }); + defineType("ExistsTypeAnnotation", { + aliases: ["FlowType"] + }); + defineType("FunctionTypeAnnotation", { + visitor: ["typeParameters", "params", "rest", "returnType"], + aliases: ["FlowType"], + fields: { + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + params: (0, _utils.validateArrayOfType)("FunctionTypeParam"), + rest: (0, _utils.validateOptionalType)("FunctionTypeParam"), + this: (0, _utils.validateOptionalType)("FunctionTypeParam"), + returnType: (0, _utils.validateType)("FlowType") + } + }); + defineType("FunctionTypeParam", { + visitor: ["name", "typeAnnotation"], + fields: { + name: (0, _utils.validateOptionalType)("Identifier"), + typeAnnotation: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("GenericTypeAnnotation", { + visitor: ["id", "typeParameters"], + aliases: ["FlowType"], + fields: { + id: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineType("InferredPredicate", { + aliases: ["FlowPredicate"] + }); + defineType("InterfaceExtends", { + visitor: ["id", "typeParameters"], + fields: { + id: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineInterfaceishType("InterfaceDeclaration"); + defineType("InterfaceTypeAnnotation", { + visitor: ["extends", "body"], + aliases: ["FlowType"], + fields: { + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")), + body: (0, _utils.validateType)("ObjectTypeAnnotation") + } + }); + defineType("IntersectionTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("MixedTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("EmptyTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("NullableTypeAnnotation", { + visitor: ["typeAnnotation"], + aliases: ["FlowType"], + fields: { + typeAnnotation: (0, _utils.validateType)("FlowType") + } + }); + defineType("NumberLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("number")) + } + }); + defineType("NumberTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ObjectTypeAnnotation", { + visitor: ["properties", "indexers", "callProperties", "internalSlots"], + aliases: ["FlowType"], + builder: ["properties", "indexers", "callProperties", "internalSlots", "exact"], + fields: { + properties: (0, _utils.validate)((0, _utils.arrayOfType)("ObjectTypeProperty", "ObjectTypeSpreadProperty")), + indexers: { + validate: (0, _utils.arrayOfType)("ObjectTypeIndexer"), + optional: true, + default: [] + }, + callProperties: { + validate: (0, _utils.arrayOfType)("ObjectTypeCallProperty"), + optional: true, + default: [] + }, + internalSlots: { + validate: (0, _utils.arrayOfType)("ObjectTypeInternalSlot"), + optional: true, + default: [] + }, + exact: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + }, + inexact: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeInternalSlot", { + visitor: ["id", "value"], + builder: ["id", "value", "optional", "static", "method"], + aliases: ["UserWhitespacable"], + fields: { + id: (0, _utils.validateType)("Identifier"), + value: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + method: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeCallProperty", { + visitor: ["value"], + aliases: ["UserWhitespacable"], + fields: { + value: (0, _utils.validateType)("FlowType"), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeIndexer", { + visitor: ["variance", "id", "key", "value"], + builder: ["id", "key", "value", "variance"], + aliases: ["UserWhitespacable"], + fields: { + id: (0, _utils.validateOptionalType)("Identifier"), + key: (0, _utils.validateType)("FlowType"), + value: (0, _utils.validateType)("FlowType"), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + variance: (0, _utils.validateOptionalType)("Variance") + } + }); + defineType("ObjectTypeProperty", { + visitor: ["key", "value", "variance"], + aliases: ["UserWhitespacable"], + fields: { + key: (0, _utils.validateType)("Identifier", "StringLiteral"), + value: (0, _utils.validateType)("FlowType"), + kind: (0, _utils.validate)((0, _utils.assertOneOf)("init", "get", "set")), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + proto: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + variance: (0, _utils.validateOptionalType)("Variance"), + method: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeSpreadProperty", { + visitor: ["argument"], + aliases: ["UserWhitespacable"], + fields: { + argument: (0, _utils.validateType)("FlowType") + } + }); + defineType("OpaqueType", { + visitor: ["id", "typeParameters", "supertype", "impltype"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + supertype: (0, _utils.validateOptionalType)("FlowType"), + impltype: (0, _utils.validateType)("FlowType") + } + }); + defineType("QualifiedTypeIdentifier", { + visitor: ["qualification", "id"], + builder: ["id", "qualification"], + fields: { + id: (0, _utils.validateType)("Identifier"), + qualification: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier") + } + }); + defineType("StringLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("string")) + } + }); + defineType("StringTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("SymbolTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ThisTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("TupleTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("TypeofTypeAnnotation", { + visitor: ["argument"], + aliases: ["FlowType"], + fields: { + argument: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeAlias", { + visitor: ["id", "typeParameters", "right"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + right: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeAnnotation", { + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeCastExpression", { + visitor: ["expression", "typeAnnotation"], + aliases: ["ExpressionWrapper", "Expression"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeAnnotation: (0, _utils.validateType)("TypeAnnotation") + } + }); + defineType("TypeParameter", { + visitor: ["bound", "default", "variance"], + fields: { + name: (0, _utils.validate)((0, _utils.assertValueType)("string")), + bound: (0, _utils.validateOptionalType)("TypeAnnotation"), + default: (0, _utils.validateOptionalType)("FlowType"), + variance: (0, _utils.validateOptionalType)("Variance") + } + }); + defineType("TypeParameterDeclaration", { + visitor: ["params"], + fields: { + params: (0, _utils.validate)((0, _utils.arrayOfType)("TypeParameter")) + } + }); + defineType("TypeParameterInstantiation", { + visitor: ["params"], + fields: { + params: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("UnionTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("Variance", { + builder: ["kind"], + fields: { + kind: (0, _utils.validate)((0, _utils.assertOneOf)("minus", "plus")) + } + }); + defineType("VoidTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("EnumDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "body"], + fields: { + id: (0, _utils.validateType)("Identifier"), + body: (0, _utils.validateType)("EnumBooleanBody", "EnumNumberBody", "EnumStringBody", "EnumSymbolBody") + } + }); + defineType("EnumBooleanBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumBooleanMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumNumberBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumNumberMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumStringBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumStringMember", "EnumDefaultedMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumSymbolBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + members: (0, _utils.validateArrayOfType)("EnumDefaultedMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumBooleanMember", { + aliases: ["EnumMember"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("BooleanLiteral") + } + }); + defineType("EnumNumberMember", { + aliases: ["EnumMember"], + visitor: ["id", "init"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("NumericLiteral") + } + }); + defineType("EnumStringMember", { + aliases: ["EnumMember"], + visitor: ["id", "init"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("StringLiteral") + } + }); + defineType("EnumDefaultedMember", { + aliases: ["EnumMember"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("IndexedAccessType", { + visitor: ["objectType", "indexType"], + aliases: ["FlowType"], + fields: { + objectType: (0, _utils.validateType)("FlowType"), + indexType: (0, _utils.validateType)("FlowType") + } + }); + defineType("OptionalIndexedAccessType", { + visitor: ["objectType", "indexType"], + aliases: ["FlowType"], + fields: { + objectType: (0, _utils.validateType)("FlowType"), + indexType: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + + + return flow$1; +} + +var jsx$1 = {}; + +var hasRequiredJsx$1; + +function requireJsx$1 () { + if (hasRequiredJsx$1) return jsx$1; + hasRequiredJsx$1 = 1; + + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("JSX"); + defineType("JSXAttribute", { + visitor: ["name", "value"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXNamespacedName") + }, + value: { + optional: true, + validate: (0, _utils.assertNodeType)("JSXElement", "JSXFragment", "StringLiteral", "JSXExpressionContainer") + } + } + }); + defineType("JSXClosingElement", { + visitor: ["name"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression", "JSXNamespacedName") + } + } + }); + defineType("JSXElement", { + builder: ["openingElement", "closingElement", "children", "selfClosing"], + visitor: ["openingElement", "children", "closingElement"], + aliases: ["Immutable", "Expression"], + fields: Object.assign({ + openingElement: { + validate: (0, _utils.assertNodeType)("JSXOpeningElement") + }, + closingElement: { + optional: true, + validate: (0, _utils.assertNodeType)("JSXClosingElement") + }, + children: (0, _utils.validateArrayOfType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment") + }, { + selfClosing: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + }) + }); + defineType("JSXEmptyExpression", {}); + defineType("JSXExpressionContainer", { + visitor: ["expression"], + aliases: ["Immutable"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression", "JSXEmptyExpression") + } + } + }); + defineType("JSXSpreadChild", { + visitor: ["expression"], + aliases: ["Immutable"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("JSXIdentifier", { + builder: ["name"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("JSXMemberExpression", { + visitor: ["object", "property"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("JSXMemberExpression", "JSXIdentifier") + }, + property: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + } + } + }); + defineType("JSXNamespacedName", { + visitor: ["namespace", "name"], + fields: { + namespace: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + }, + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + } + } + }); + defineType("JSXOpeningElement", { + builder: ["name", "attributes", "selfClosing"], + visitor: ["name", "attributes"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression", "JSXNamespacedName") + }, + selfClosing: { + default: false + }, + attributes: (0, _utils.validateArrayOfType)("JSXAttribute", "JSXSpreadAttribute"), + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("JSXSpreadAttribute", { + visitor: ["argument"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("JSXText", { + aliases: ["Immutable"], + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("JSXFragment", { + builder: ["openingFragment", "closingFragment", "children"], + visitor: ["openingFragment", "children", "closingFragment"], + aliases: ["Immutable", "Expression"], + fields: { + openingFragment: { + validate: (0, _utils.assertNodeType)("JSXOpeningFragment") + }, + closingFragment: { + validate: (0, _utils.assertNodeType)("JSXClosingFragment") + }, + children: (0, _utils.validateArrayOfType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment") + } + }); + defineType("JSXOpeningFragment", { + aliases: ["Immutable"] + }); + defineType("JSXClosingFragment", { + aliases: ["Immutable"] + }); + + + return jsx$1; +} + +var misc = {}; + +var placeholders = {}; + +var hasRequiredPlaceholders; + +function requirePlaceholders () { + if (hasRequiredPlaceholders) return placeholders; + hasRequiredPlaceholders = 1; + + Object.defineProperty(placeholders, "__esModule", { + value: true + }); + placeholders.PLACEHOLDERS_FLIPPED_ALIAS = placeholders.PLACEHOLDERS_ALIAS = placeholders.PLACEHOLDERS = void 0; + var _utils = requireUtils(); + const PLACEHOLDERS = placeholders.PLACEHOLDERS = ["Identifier", "StringLiteral", "Expression", "Statement", "Declaration", "BlockStatement", "ClassBody", "Pattern"]; + const PLACEHOLDERS_ALIAS = placeholders.PLACEHOLDERS_ALIAS = { + Declaration: ["Statement"], + Pattern: ["PatternLike", "LVal"] + }; + for (const type of PLACEHOLDERS) { + const alias = _utils.ALIAS_KEYS[type]; + if (alias != null && alias.length) PLACEHOLDERS_ALIAS[type] = alias; + } + const PLACEHOLDERS_FLIPPED_ALIAS = placeholders.PLACEHOLDERS_FLIPPED_ALIAS = {}; + Object.keys(PLACEHOLDERS_ALIAS).forEach(type => { + PLACEHOLDERS_ALIAS[type].forEach(alias => { + if (!hasOwnProperty.call(PLACEHOLDERS_FLIPPED_ALIAS, alias)) { + PLACEHOLDERS_FLIPPED_ALIAS[alias] = []; + } + PLACEHOLDERS_FLIPPED_ALIAS[alias].push(type); + }); + }); + + + return placeholders; +} + +var hasRequiredMisc; + +function requireMisc () { + if (hasRequiredMisc) return misc; + hasRequiredMisc = 1; + + var _utils = requireUtils(); + var _placeholders = requirePlaceholders(); + var _core = requireCore(); + const defineType = (0, _utils.defineAliasedType)("Miscellaneous"); + { + defineType("Noop", { + visitor: [] + }); + } + defineType("Placeholder", { + visitor: [], + builder: ["expectedNode", "name"], + fields: Object.assign({ + name: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + expectedNode: { + validate: (0, _utils.assertOneOf)(..._placeholders.PLACEHOLDERS) + } + }, (0, _core.patternLikeCommon)()) + }); + defineType("V8IntrinsicIdentifier", { + builder: ["name"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + + + return misc; +} + +var experimental = {}; + +var hasRequiredExperimental; + +function requireExperimental () { + if (hasRequiredExperimental) return experimental; + hasRequiredExperimental = 1; + + var _utils = requireUtils(); + (0, _utils.default)("ArgumentPlaceholder", {}); + (0, _utils.default)("BindExpression", { + visitor: ["object", "callee"], + aliases: ["Expression"], + fields: !process.env.BABEL_TYPES_8_BREAKING ? { + object: { + validate: Object.assign(() => {}, { + oneOfNodeTypes: ["Expression"] + }) + }, + callee: { + validate: Object.assign(() => {}, { + oneOfNodeTypes: ["Expression"] + }) + } + } : { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + callee: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + (0, _utils.default)("ImportAttribute", { + visitor: ["key", "value"], + fields: { + key: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + value: { + validate: (0, _utils.assertNodeType)("StringLiteral") + } + } + }); + (0, _utils.default)("Decorator", { + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + (0, _utils.default)("DoExpression", { + visitor: ["body"], + builder: ["body", "async"], + aliases: ["Expression"], + fields: { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + async: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + } + } + }); + (0, _utils.default)("ExportDefaultSpecifier", { + visitor: ["exported"], + aliases: ["ModuleSpecifier"], + fields: { + exported: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + (0, _utils.default)("RecordExpression", { + visitor: ["properties"], + aliases: ["Expression"], + fields: { + properties: (0, _utils.validateArrayOfType)("ObjectProperty", "SpreadElement") + } + }); + (0, _utils.default)("TupleExpression", { + fields: { + elements: { + validate: (0, _utils.arrayOfType)("Expression", "SpreadElement"), + default: [] + } + }, + visitor: ["elements"], + aliases: ["Expression"] + }); + { + (0, _utils.default)("DecimalLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + } + (0, _utils.default)("ModuleExpression", { + visitor: ["body"], + fields: { + body: { + validate: (0, _utils.assertNodeType)("Program") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("TopicReference", { + aliases: ["Expression"] + }); + (0, _utils.default)("PipelineTopicExpression", { + builder: ["expression"], + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("PipelineBareFunction", { + builder: ["callee"], + visitor: ["callee"], + fields: { + callee: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("PipelinePrimaryTopicReference", { + aliases: ["Expression"] + }); + + + return experimental; +} + +var typescript$1 = {}; + +var hasRequiredTypescript$1; + +function requireTypescript$1 () { + if (hasRequiredTypescript$1) return typescript$1; + hasRequiredTypescript$1 = 1; + + var _utils = requireUtils(); + var _core = requireCore(); + var _is = requireIs(); + const defineType = (0, _utils.defineAliasedType)("TypeScript"); + const bool = (0, _utils.assertValueType)("boolean"); + const tSFunctionTypeAnnotationCommon = () => ({ + returnType: { + validate: (0, _utils.assertNodeType)("TSTypeAnnotation", "Noop"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration", "Noop"), + optional: true + } + }); + defineType("TSParameterProperty", { + aliases: ["LVal"], + visitor: ["parameter"], + fields: { + accessibility: { + validate: (0, _utils.assertOneOf)("public", "private", "protected"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + parameter: { + validate: (0, _utils.assertNodeType)("Identifier", "AssignmentPattern") + }, + override: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + } + }); + defineType("TSDeclareFunction", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "params", "returnType"], + fields: Object.assign({}, (0, _core.functionDeclarationCommon)(), tSFunctionTypeAnnotationCommon()) + }); + defineType("TSDeclareMethod", { + visitor: ["decorators", "key", "typeParameters", "params", "returnType"], + fields: Object.assign({}, (0, _core.classMethodOrDeclareMethodCommon)(), tSFunctionTypeAnnotationCommon()) + }); + defineType("TSQualifiedName", { + aliases: ["TSEntityName"], + visitor: ["left", "right"], + fields: { + left: (0, _utils.validateType)("TSEntityName"), + right: (0, _utils.validateType)("Identifier") + } + }); + const signatureDeclarationCommon = () => ({ + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + ["parameters"]: (0, _utils.validateArrayOfType)("ArrayPattern", "Identifier", "ObjectPattern", "RestElement"), + ["typeAnnotation"]: (0, _utils.validateOptionalType)("TSTypeAnnotation") + }); + const callConstructSignatureDeclaration = { + aliases: ["TSTypeElement"], + visitor: ["typeParameters", "parameters", "typeAnnotation"], + fields: signatureDeclarationCommon() + }; + defineType("TSCallSignatureDeclaration", callConstructSignatureDeclaration); + defineType("TSConstructSignatureDeclaration", callConstructSignatureDeclaration); + const namedTypeElementCommon = () => ({ + key: (0, _utils.validateType)("Expression"), + computed: { + default: false + }, + optional: (0, _utils.validateOptional)(bool) + }); + defineType("TSPropertySignature", { + aliases: ["TSTypeElement"], + visitor: ["key", "typeAnnotation"], + fields: Object.assign({}, namedTypeElementCommon(), { + readonly: (0, _utils.validateOptional)(bool), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"), + kind: { + validate: (0, _utils.assertOneOf)("get", "set") + } + }) + }); + defineType("TSMethodSignature", { + aliases: ["TSTypeElement"], + visitor: ["key", "typeParameters", "parameters", "typeAnnotation"], + fields: Object.assign({}, signatureDeclarationCommon(), namedTypeElementCommon(), { + kind: { + validate: (0, _utils.assertOneOf)("method", "get", "set") + } + }) + }); + defineType("TSIndexSignature", { + aliases: ["TSTypeElement"], + visitor: ["parameters", "typeAnnotation"], + fields: { + readonly: (0, _utils.validateOptional)(bool), + static: (0, _utils.validateOptional)(bool), + parameters: (0, _utils.validateArrayOfType)("Identifier"), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation") + } + }); + const tsKeywordTypes = ["TSAnyKeyword", "TSBooleanKeyword", "TSBigIntKeyword", "TSIntrinsicKeyword", "TSNeverKeyword", "TSNullKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSUndefinedKeyword", "TSUnknownKeyword", "TSVoidKeyword"]; + for (const type of tsKeywordTypes) { + defineType(type, { + aliases: ["TSType", "TSBaseType"], + visitor: [], + fields: {} + }); + } + defineType("TSThisType", { + aliases: ["TSType", "TSBaseType"], + visitor: [], + fields: {} + }); + const fnOrCtrBase = { + aliases: ["TSType"], + visitor: ["typeParameters", "parameters", "typeAnnotation"] + }; + defineType("TSFunctionType", Object.assign({}, fnOrCtrBase, { + fields: signatureDeclarationCommon() + })); + defineType("TSConstructorType", Object.assign({}, fnOrCtrBase, { + fields: Object.assign({}, signatureDeclarationCommon(), { + abstract: (0, _utils.validateOptional)(bool) + }) + })); + defineType("TSTypeReference", { + aliases: ["TSType"], + visitor: ["typeName", "typeParameters"], + fields: { + typeName: (0, _utils.validateType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + defineType("TSTypePredicate", { + aliases: ["TSType"], + visitor: ["parameterName", "typeAnnotation"], + builder: ["parameterName", "typeAnnotation", "asserts"], + fields: { + parameterName: (0, _utils.validateType)("Identifier", "TSThisType"), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"), + asserts: (0, _utils.validateOptional)(bool) + } + }); + defineType("TSTypeQuery", { + aliases: ["TSType"], + visitor: ["exprName", "typeParameters"], + fields: { + exprName: (0, _utils.validateType)("TSEntityName", "TSImportType"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + defineType("TSTypeLiteral", { + aliases: ["TSType"], + visitor: ["members"], + fields: { + members: (0, _utils.validateArrayOfType)("TSTypeElement") + } + }); + defineType("TSArrayType", { + aliases: ["TSType"], + visitor: ["elementType"], + fields: { + elementType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSTupleType", { + aliases: ["TSType"], + visitor: ["elementTypes"], + fields: { + elementTypes: (0, _utils.validateArrayOfType)("TSType", "TSNamedTupleMember") + } + }); + defineType("TSOptionalType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSRestType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSNamedTupleMember", { + visitor: ["label", "elementType"], + builder: ["label", "elementType", "optional"], + fields: { + label: (0, _utils.validateType)("Identifier"), + optional: { + validate: bool, + default: false + }, + elementType: (0, _utils.validateType)("TSType") + } + }); + const unionOrIntersection = { + aliases: ["TSType"], + visitor: ["types"], + fields: { + types: (0, _utils.validateArrayOfType)("TSType") + } + }; + defineType("TSUnionType", unionOrIntersection); + defineType("TSIntersectionType", unionOrIntersection); + defineType("TSConditionalType", { + aliases: ["TSType"], + visitor: ["checkType", "extendsType", "trueType", "falseType"], + fields: { + checkType: (0, _utils.validateType)("TSType"), + extendsType: (0, _utils.validateType)("TSType"), + trueType: (0, _utils.validateType)("TSType"), + falseType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSInferType", { + aliases: ["TSType"], + visitor: ["typeParameter"], + fields: { + typeParameter: (0, _utils.validateType)("TSTypeParameter") + } + }); + defineType("TSParenthesizedType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSTypeOperator", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + operator: (0, _utils.validate)((0, _utils.assertValueType)("string")), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSIndexedAccessType", { + aliases: ["TSType"], + visitor: ["objectType", "indexType"], + fields: { + objectType: (0, _utils.validateType)("TSType"), + indexType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSMappedType", { + aliases: ["TSType"], + visitor: ["typeParameter", "nameType", "typeAnnotation"], + builder: ["typeParameter", "typeAnnotation", "nameType"], + fields: Object.assign({}, { + typeParameter: (0, _utils.validateType)("TSTypeParameter") + }, { + readonly: (0, _utils.validateOptional)((0, _utils.assertOneOf)(true, false, "+", "-")), + optional: (0, _utils.validateOptional)((0, _utils.assertOneOf)(true, false, "+", "-")), + typeAnnotation: (0, _utils.validateOptionalType)("TSType"), + nameType: (0, _utils.validateOptionalType)("TSType") + }) + }); + defineType("TSLiteralType", { + aliases: ["TSType", "TSBaseType"], + visitor: ["literal"], + fields: { + literal: { + validate: function () { + const unaryExpression = (0, _utils.assertNodeType)("NumericLiteral", "BigIntLiteral"); + const unaryOperator = (0, _utils.assertOneOf)("-"); + const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral"); + function validator(parent, key, node) { + if ((0, _is.default)("UnaryExpression", node)) { + unaryOperator(node, "operator", node.operator); + unaryExpression(node, "argument", node.argument); + } else { + literal(parent, key, node); + } + } + validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral", "UnaryExpression"]; + return validator; + }() + } + } + }); + const expressionWithTypeArguments = { + aliases: ["TSType"], + visitor: ["expression", "typeParameters"], + fields: { + expression: (0, _utils.validateType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }; + { + defineType("TSExpressionWithTypeArguments", expressionWithTypeArguments); + } + defineType("TSInterfaceDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "extends", "body"], + fields: { + declare: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("TSExpressionWithTypeArguments")), + body: (0, _utils.validateType)("TSInterfaceBody") + } + }); + defineType("TSInterfaceBody", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("TSTypeElement") + } + }); + defineType("TSTypeAliasDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "typeAnnotation"], + fields: { + declare: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSInstantiationExpression", { + aliases: ["Expression"], + visitor: ["expression", "typeParameters"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + const TSTypeExpression = { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["expression", "typeAnnotation"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }; + defineType("TSAsExpression", TSTypeExpression); + defineType("TSSatisfiesExpression", TSTypeExpression); + defineType("TSTypeAssertion", { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["typeAnnotation", "expression"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType"), + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSEnumDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "members"], + fields: { + declare: (0, _utils.validateOptional)(bool), + const: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + members: (0, _utils.validateArrayOfType)("TSEnumMember"), + initializer: (0, _utils.validateOptionalType)("Expression") + } + }); + defineType("TSEnumMember", { + visitor: ["id", "initializer"], + fields: { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + initializer: (0, _utils.validateOptionalType)("Expression") + } + }); + defineType("TSModuleDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "body"], + fields: Object.assign({ + kind: { + validate: (0, _utils.assertOneOf)("global", "module", "namespace") + }, + declare: (0, _utils.validateOptional)(bool) + }, { + global: (0, _utils.validateOptional)(bool) + }, { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + body: (0, _utils.validateType)("TSModuleBlock", "TSModuleDeclaration") + }) + }); + defineType("TSModuleBlock", { + aliases: ["Scopable", "Block", "BlockParent", "FunctionParent"], + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("Statement") + } + }); + defineType("TSImportType", { + aliases: ["TSType"], + visitor: ["argument", "qualifier", "typeParameters"], + fields: { + argument: (0, _utils.validateType)("StringLiteral"), + qualifier: (0, _utils.validateOptionalType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation"), + options: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("TSImportEqualsDeclaration", { + aliases: ["Statement"], + visitor: ["id", "moduleReference"], + fields: { + isExport: (0, _utils.validate)(bool), + id: (0, _utils.validateType)("Identifier"), + moduleReference: (0, _utils.validateType)("TSEntityName", "TSExternalModuleReference"), + importKind: { + validate: (0, _utils.assertOneOf)("type", "value"), + optional: true + } + } + }); + defineType("TSExternalModuleReference", { + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("StringLiteral") + } + }); + defineType("TSNonNullExpression", { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSExportAssignment", { + aliases: ["Statement"], + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSNamespaceExportDeclaration", { + aliases: ["Statement"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("TSTypeAnnotation", { + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TSType") + } + } + }); + defineType("TSTypeParameterInstantiation", { + visitor: ["params"], + fields: { + params: (0, _utils.validateArrayOfType)("TSType") + } + }); + defineType("TSTypeParameterDeclaration", { + visitor: ["params"], + fields: { + params: (0, _utils.validateArrayOfType)("TSTypeParameter") + } + }); + defineType("TSTypeParameter", { + builder: ["constraint", "default", "name"], + visitor: ["constraint", "default"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + }, + in: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + out: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + const: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + constraint: { + validate: (0, _utils.assertNodeType)("TSType"), + optional: true + }, + default: { + validate: (0, _utils.assertNodeType)("TSType"), + optional: true + } + } + }); + + + return typescript$1; +} + +var deprecatedAliases = {}; + +var hasRequiredDeprecatedAliases; + +function requireDeprecatedAliases () { + if (hasRequiredDeprecatedAliases) return deprecatedAliases; + hasRequiredDeprecatedAliases = 1; + + Object.defineProperty(deprecatedAliases, "__esModule", { + value: true + }); + deprecatedAliases.DEPRECATED_ALIASES = void 0; + deprecatedAliases.DEPRECATED_ALIASES = { + ModuleDeclaration: "ImportOrExportDeclaration" + }; + + + return deprecatedAliases; +} + +var hasRequiredDefinitions; + +function requireDefinitions () { + if (hasRequiredDefinitions) return definitions; + hasRequiredDefinitions = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "ALIAS_KEYS", { + enumerable: true, + get: function () { + return _utils.ALIAS_KEYS; + } + }); + Object.defineProperty(exports, "BUILDER_KEYS", { + enumerable: true, + get: function () { + return _utils.BUILDER_KEYS; + } + }); + Object.defineProperty(exports, "DEPRECATED_ALIASES", { + enumerable: true, + get: function () { + return _deprecatedAliases.DEPRECATED_ALIASES; + } + }); + Object.defineProperty(exports, "DEPRECATED_KEYS", { + enumerable: true, + get: function () { + return _utils.DEPRECATED_KEYS; + } + }); + Object.defineProperty(exports, "FLIPPED_ALIAS_KEYS", { + enumerable: true, + get: function () { + return _utils.FLIPPED_ALIAS_KEYS; + } + }); + Object.defineProperty(exports, "NODE_FIELDS", { + enumerable: true, + get: function () { + return _utils.NODE_FIELDS; + } + }); + Object.defineProperty(exports, "NODE_PARENT_VALIDATIONS", { + enumerable: true, + get: function () { + return _utils.NODE_PARENT_VALIDATIONS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_ALIAS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS_FLIPPED_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_FLIPPED_ALIAS; + } + }); + exports.TYPES = void 0; + Object.defineProperty(exports, "VISITOR_KEYS", { + enumerable: true, + get: function () { + return _utils.VISITOR_KEYS; + } + }); + requireCore(); + requireFlow$1(); + requireJsx$1(); + requireMisc(); + requireExperimental(); + requireTypescript$1(); + var _utils = requireUtils(); + var _placeholders = requirePlaceholders(); + var _deprecatedAliases = requireDeprecatedAliases(); + Object.keys(_deprecatedAliases.DEPRECATED_ALIASES).forEach(deprecatedAlias => { + _utils.FLIPPED_ALIAS_KEYS[deprecatedAlias] = _utils.FLIPPED_ALIAS_KEYS[_deprecatedAliases.DEPRECATED_ALIASES[deprecatedAlias]]; + }); + exports.TYPES = [].concat(Object.keys(_utils.VISITOR_KEYS), Object.keys(_utils.FLIPPED_ALIAS_KEYS), Object.keys(_utils.DEPRECATED_KEYS)); + + +} (definitions)); + return definitions; +} + +var hasRequiredValidate; + +function requireValidate () { + if (hasRequiredValidate) return validate$1; + hasRequiredValidate = 1; + + Object.defineProperty(validate$1, "__esModule", { + value: true + }); + validate$1.default = validate; + validate$1.validateChild = validateChild; + validate$1.validateField = validateField; + validate$1.validateInternal = validateInternal; + var _index = requireDefinitions(); + function validate(node, key, val) { + if (!node) return; + const fields = _index.NODE_FIELDS[node.type]; + if (!fields) return; + const field = fields[key]; + validateField(node, key, val, field); + validateChild(node, key, val); + } + function validateInternal(field, node, key, val, maybeNode) { + if (!(field != null && field.validate)) return; + if (field.optional && val == null) return; + field.validate(node, key, val); + if (maybeNode) { + var _NODE_PARENT_VALIDATI; + const type = val.type; + if (type == null) return; + (_NODE_PARENT_VALIDATI = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI.call(_index.NODE_PARENT_VALIDATIONS, node, key, val); + } + } + function validateField(node, key, val, field) { + if (!(field != null && field.validate)) return; + if (field.optional && val == null) return; + field.validate(node, key, val); + } + function validateChild(node, key, val) { + var _NODE_PARENT_VALIDATI2; + const type = val == null ? void 0 : val.type; + if (type == null) return; + (_NODE_PARENT_VALIDATI2 = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI2.call(_index.NODE_PARENT_VALIDATIONS, node, key, val); + } + + + return validate$1; +} + +var hasRequiredGenerated$2; + +function requireGenerated$2 () { + if (hasRequiredGenerated$2) return generated$2; + hasRequiredGenerated$2 = 1; + + Object.defineProperty(generated$2, "__esModule", { + value: true + }); + generated$2.anyTypeAnnotation = anyTypeAnnotation; + generated$2.argumentPlaceholder = argumentPlaceholder; + generated$2.arrayExpression = arrayExpression; + generated$2.arrayPattern = arrayPattern; + generated$2.arrayTypeAnnotation = arrayTypeAnnotation; + generated$2.arrowFunctionExpression = arrowFunctionExpression; + generated$2.assignmentExpression = assignmentExpression; + generated$2.assignmentPattern = assignmentPattern; + generated$2.awaitExpression = awaitExpression; + generated$2.bigIntLiteral = bigIntLiteral; + generated$2.binaryExpression = binaryExpression; + generated$2.bindExpression = bindExpression; + generated$2.blockStatement = blockStatement; + generated$2.booleanLiteral = booleanLiteral; + generated$2.booleanLiteralTypeAnnotation = booleanLiteralTypeAnnotation; + generated$2.booleanTypeAnnotation = booleanTypeAnnotation; + generated$2.breakStatement = breakStatement; + generated$2.callExpression = callExpression; + generated$2.catchClause = catchClause; + generated$2.classAccessorProperty = classAccessorProperty; + generated$2.classBody = classBody; + generated$2.classDeclaration = classDeclaration; + generated$2.classExpression = classExpression; + generated$2.classImplements = classImplements; + generated$2.classMethod = classMethod; + generated$2.classPrivateMethod = classPrivateMethod; + generated$2.classPrivateProperty = classPrivateProperty; + generated$2.classProperty = classProperty; + generated$2.conditionalExpression = conditionalExpression; + generated$2.continueStatement = continueStatement; + generated$2.debuggerStatement = debuggerStatement; + generated$2.decimalLiteral = decimalLiteral; + generated$2.declareClass = declareClass; + generated$2.declareExportAllDeclaration = declareExportAllDeclaration; + generated$2.declareExportDeclaration = declareExportDeclaration; + generated$2.declareFunction = declareFunction; + generated$2.declareInterface = declareInterface; + generated$2.declareModule = declareModule; + generated$2.declareModuleExports = declareModuleExports; + generated$2.declareOpaqueType = declareOpaqueType; + generated$2.declareTypeAlias = declareTypeAlias; + generated$2.declareVariable = declareVariable; + generated$2.declaredPredicate = declaredPredicate; + generated$2.decorator = decorator; + generated$2.directive = directive; + generated$2.directiveLiteral = directiveLiteral; + generated$2.doExpression = doExpression; + generated$2.doWhileStatement = doWhileStatement; + generated$2.emptyStatement = emptyStatement; + generated$2.emptyTypeAnnotation = emptyTypeAnnotation; + generated$2.enumBooleanBody = enumBooleanBody; + generated$2.enumBooleanMember = enumBooleanMember; + generated$2.enumDeclaration = enumDeclaration; + generated$2.enumDefaultedMember = enumDefaultedMember; + generated$2.enumNumberBody = enumNumberBody; + generated$2.enumNumberMember = enumNumberMember; + generated$2.enumStringBody = enumStringBody; + generated$2.enumStringMember = enumStringMember; + generated$2.enumSymbolBody = enumSymbolBody; + generated$2.existsTypeAnnotation = existsTypeAnnotation; + generated$2.exportAllDeclaration = exportAllDeclaration; + generated$2.exportDefaultDeclaration = exportDefaultDeclaration; + generated$2.exportDefaultSpecifier = exportDefaultSpecifier; + generated$2.exportNamedDeclaration = exportNamedDeclaration; + generated$2.exportNamespaceSpecifier = exportNamespaceSpecifier; + generated$2.exportSpecifier = exportSpecifier; + generated$2.expressionStatement = expressionStatement; + generated$2.file = file; + generated$2.forInStatement = forInStatement; + generated$2.forOfStatement = forOfStatement; + generated$2.forStatement = forStatement; + generated$2.functionDeclaration = functionDeclaration; + generated$2.functionExpression = functionExpression; + generated$2.functionTypeAnnotation = functionTypeAnnotation; + generated$2.functionTypeParam = functionTypeParam; + generated$2.genericTypeAnnotation = genericTypeAnnotation; + generated$2.identifier = identifier; + generated$2.ifStatement = ifStatement; + generated$2.import = _import; + generated$2.importAttribute = importAttribute; + generated$2.importDeclaration = importDeclaration; + generated$2.importDefaultSpecifier = importDefaultSpecifier; + generated$2.importExpression = importExpression; + generated$2.importNamespaceSpecifier = importNamespaceSpecifier; + generated$2.importSpecifier = importSpecifier; + generated$2.indexedAccessType = indexedAccessType; + generated$2.inferredPredicate = inferredPredicate; + generated$2.interfaceDeclaration = interfaceDeclaration; + generated$2.interfaceExtends = interfaceExtends; + generated$2.interfaceTypeAnnotation = interfaceTypeAnnotation; + generated$2.interpreterDirective = interpreterDirective; + generated$2.intersectionTypeAnnotation = intersectionTypeAnnotation; + generated$2.jSXAttribute = generated$2.jsxAttribute = jsxAttribute; + generated$2.jSXClosingElement = generated$2.jsxClosingElement = jsxClosingElement; + generated$2.jSXClosingFragment = generated$2.jsxClosingFragment = jsxClosingFragment; + generated$2.jSXElement = generated$2.jsxElement = jsxElement; + generated$2.jSXEmptyExpression = generated$2.jsxEmptyExpression = jsxEmptyExpression; + generated$2.jSXExpressionContainer = generated$2.jsxExpressionContainer = jsxExpressionContainer; + generated$2.jSXFragment = generated$2.jsxFragment = jsxFragment; + generated$2.jSXIdentifier = generated$2.jsxIdentifier = jsxIdentifier; + generated$2.jSXMemberExpression = generated$2.jsxMemberExpression = jsxMemberExpression; + generated$2.jSXNamespacedName = generated$2.jsxNamespacedName = jsxNamespacedName; + generated$2.jSXOpeningElement = generated$2.jsxOpeningElement = jsxOpeningElement; + generated$2.jSXOpeningFragment = generated$2.jsxOpeningFragment = jsxOpeningFragment; + generated$2.jSXSpreadAttribute = generated$2.jsxSpreadAttribute = jsxSpreadAttribute; + generated$2.jSXSpreadChild = generated$2.jsxSpreadChild = jsxSpreadChild; + generated$2.jSXText = generated$2.jsxText = jsxText; + generated$2.labeledStatement = labeledStatement; + generated$2.logicalExpression = logicalExpression; + generated$2.memberExpression = memberExpression; + generated$2.metaProperty = metaProperty; + generated$2.mixedTypeAnnotation = mixedTypeAnnotation; + generated$2.moduleExpression = moduleExpression; + generated$2.newExpression = newExpression; + generated$2.noop = noop; + generated$2.nullLiteral = nullLiteral; + generated$2.nullLiteralTypeAnnotation = nullLiteralTypeAnnotation; + generated$2.nullableTypeAnnotation = nullableTypeAnnotation; + generated$2.numberLiteral = NumberLiteral; + generated$2.numberLiteralTypeAnnotation = numberLiteralTypeAnnotation; + generated$2.numberTypeAnnotation = numberTypeAnnotation; + generated$2.numericLiteral = numericLiteral; + generated$2.objectExpression = objectExpression; + generated$2.objectMethod = objectMethod; + generated$2.objectPattern = objectPattern; + generated$2.objectProperty = objectProperty; + generated$2.objectTypeAnnotation = objectTypeAnnotation; + generated$2.objectTypeCallProperty = objectTypeCallProperty; + generated$2.objectTypeIndexer = objectTypeIndexer; + generated$2.objectTypeInternalSlot = objectTypeInternalSlot; + generated$2.objectTypeProperty = objectTypeProperty; + generated$2.objectTypeSpreadProperty = objectTypeSpreadProperty; + generated$2.opaqueType = opaqueType; + generated$2.optionalCallExpression = optionalCallExpression; + generated$2.optionalIndexedAccessType = optionalIndexedAccessType; + generated$2.optionalMemberExpression = optionalMemberExpression; + generated$2.parenthesizedExpression = parenthesizedExpression; + generated$2.pipelineBareFunction = pipelineBareFunction; + generated$2.pipelinePrimaryTopicReference = pipelinePrimaryTopicReference; + generated$2.pipelineTopicExpression = pipelineTopicExpression; + generated$2.placeholder = placeholder; + generated$2.privateName = privateName; + generated$2.program = program; + generated$2.qualifiedTypeIdentifier = qualifiedTypeIdentifier; + generated$2.recordExpression = recordExpression; + generated$2.regExpLiteral = regExpLiteral; + generated$2.regexLiteral = RegexLiteral; + generated$2.restElement = restElement; + generated$2.restProperty = RestProperty; + generated$2.returnStatement = returnStatement; + generated$2.sequenceExpression = sequenceExpression; + generated$2.spreadElement = spreadElement; + generated$2.spreadProperty = SpreadProperty; + generated$2.staticBlock = staticBlock; + generated$2.stringLiteral = stringLiteral; + generated$2.stringLiteralTypeAnnotation = stringLiteralTypeAnnotation; + generated$2.stringTypeAnnotation = stringTypeAnnotation; + generated$2.super = _super; + generated$2.switchCase = switchCase; + generated$2.switchStatement = switchStatement; + generated$2.symbolTypeAnnotation = symbolTypeAnnotation; + generated$2.taggedTemplateExpression = taggedTemplateExpression; + generated$2.templateElement = templateElement; + generated$2.templateLiteral = templateLiteral; + generated$2.thisExpression = thisExpression; + generated$2.thisTypeAnnotation = thisTypeAnnotation; + generated$2.throwStatement = throwStatement; + generated$2.topicReference = topicReference; + generated$2.tryStatement = tryStatement; + generated$2.tSAnyKeyword = generated$2.tsAnyKeyword = tsAnyKeyword; + generated$2.tSArrayType = generated$2.tsArrayType = tsArrayType; + generated$2.tSAsExpression = generated$2.tsAsExpression = tsAsExpression; + generated$2.tSBigIntKeyword = generated$2.tsBigIntKeyword = tsBigIntKeyword; + generated$2.tSBooleanKeyword = generated$2.tsBooleanKeyword = tsBooleanKeyword; + generated$2.tSCallSignatureDeclaration = generated$2.tsCallSignatureDeclaration = tsCallSignatureDeclaration; + generated$2.tSConditionalType = generated$2.tsConditionalType = tsConditionalType; + generated$2.tSConstructSignatureDeclaration = generated$2.tsConstructSignatureDeclaration = tsConstructSignatureDeclaration; + generated$2.tSConstructorType = generated$2.tsConstructorType = tsConstructorType; + generated$2.tSDeclareFunction = generated$2.tsDeclareFunction = tsDeclareFunction; + generated$2.tSDeclareMethod = generated$2.tsDeclareMethod = tsDeclareMethod; + generated$2.tSEnumDeclaration = generated$2.tsEnumDeclaration = tsEnumDeclaration; + generated$2.tSEnumMember = generated$2.tsEnumMember = tsEnumMember; + generated$2.tSExportAssignment = generated$2.tsExportAssignment = tsExportAssignment; + generated$2.tSExpressionWithTypeArguments = generated$2.tsExpressionWithTypeArguments = tsExpressionWithTypeArguments; + generated$2.tSExternalModuleReference = generated$2.tsExternalModuleReference = tsExternalModuleReference; + generated$2.tSFunctionType = generated$2.tsFunctionType = tsFunctionType; + generated$2.tSImportEqualsDeclaration = generated$2.tsImportEqualsDeclaration = tsImportEqualsDeclaration; + generated$2.tSImportType = generated$2.tsImportType = tsImportType; + generated$2.tSIndexSignature = generated$2.tsIndexSignature = tsIndexSignature; + generated$2.tSIndexedAccessType = generated$2.tsIndexedAccessType = tsIndexedAccessType; + generated$2.tSInferType = generated$2.tsInferType = tsInferType; + generated$2.tSInstantiationExpression = generated$2.tsInstantiationExpression = tsInstantiationExpression; + generated$2.tSInterfaceBody = generated$2.tsInterfaceBody = tsInterfaceBody; + generated$2.tSInterfaceDeclaration = generated$2.tsInterfaceDeclaration = tsInterfaceDeclaration; + generated$2.tSIntersectionType = generated$2.tsIntersectionType = tsIntersectionType; + generated$2.tSIntrinsicKeyword = generated$2.tsIntrinsicKeyword = tsIntrinsicKeyword; + generated$2.tSLiteralType = generated$2.tsLiteralType = tsLiteralType; + generated$2.tSMappedType = generated$2.tsMappedType = tsMappedType; + generated$2.tSMethodSignature = generated$2.tsMethodSignature = tsMethodSignature; + generated$2.tSModuleBlock = generated$2.tsModuleBlock = tsModuleBlock; + generated$2.tSModuleDeclaration = generated$2.tsModuleDeclaration = tsModuleDeclaration; + generated$2.tSNamedTupleMember = generated$2.tsNamedTupleMember = tsNamedTupleMember; + generated$2.tSNamespaceExportDeclaration = generated$2.tsNamespaceExportDeclaration = tsNamespaceExportDeclaration; + generated$2.tSNeverKeyword = generated$2.tsNeverKeyword = tsNeverKeyword; + generated$2.tSNonNullExpression = generated$2.tsNonNullExpression = tsNonNullExpression; + generated$2.tSNullKeyword = generated$2.tsNullKeyword = tsNullKeyword; + generated$2.tSNumberKeyword = generated$2.tsNumberKeyword = tsNumberKeyword; + generated$2.tSObjectKeyword = generated$2.tsObjectKeyword = tsObjectKeyword; + generated$2.tSOptionalType = generated$2.tsOptionalType = tsOptionalType; + generated$2.tSParameterProperty = generated$2.tsParameterProperty = tsParameterProperty; + generated$2.tSParenthesizedType = generated$2.tsParenthesizedType = tsParenthesizedType; + generated$2.tSPropertySignature = generated$2.tsPropertySignature = tsPropertySignature; + generated$2.tSQualifiedName = generated$2.tsQualifiedName = tsQualifiedName; + generated$2.tSRestType = generated$2.tsRestType = tsRestType; + generated$2.tSSatisfiesExpression = generated$2.tsSatisfiesExpression = tsSatisfiesExpression; + generated$2.tSStringKeyword = generated$2.tsStringKeyword = tsStringKeyword; + generated$2.tSSymbolKeyword = generated$2.tsSymbolKeyword = tsSymbolKeyword; + generated$2.tSThisType = generated$2.tsThisType = tsThisType; + generated$2.tSTupleType = generated$2.tsTupleType = tsTupleType; + generated$2.tSTypeAliasDeclaration = generated$2.tsTypeAliasDeclaration = tsTypeAliasDeclaration; + generated$2.tSTypeAnnotation = generated$2.tsTypeAnnotation = tsTypeAnnotation; + generated$2.tSTypeAssertion = generated$2.tsTypeAssertion = tsTypeAssertion; + generated$2.tSTypeLiteral = generated$2.tsTypeLiteral = tsTypeLiteral; + generated$2.tSTypeOperator = generated$2.tsTypeOperator = tsTypeOperator; + generated$2.tSTypeParameter = generated$2.tsTypeParameter = tsTypeParameter; + generated$2.tSTypeParameterDeclaration = generated$2.tsTypeParameterDeclaration = tsTypeParameterDeclaration; + generated$2.tSTypeParameterInstantiation = generated$2.tsTypeParameterInstantiation = tsTypeParameterInstantiation; + generated$2.tSTypePredicate = generated$2.tsTypePredicate = tsTypePredicate; + generated$2.tSTypeQuery = generated$2.tsTypeQuery = tsTypeQuery; + generated$2.tSTypeReference = generated$2.tsTypeReference = tsTypeReference; + generated$2.tSUndefinedKeyword = generated$2.tsUndefinedKeyword = tsUndefinedKeyword; + generated$2.tSUnionType = generated$2.tsUnionType = tsUnionType; + generated$2.tSUnknownKeyword = generated$2.tsUnknownKeyword = tsUnknownKeyword; + generated$2.tSVoidKeyword = generated$2.tsVoidKeyword = tsVoidKeyword; + generated$2.tupleExpression = tupleExpression; + generated$2.tupleTypeAnnotation = tupleTypeAnnotation; + generated$2.typeAlias = typeAlias; + generated$2.typeAnnotation = typeAnnotation; + generated$2.typeCastExpression = typeCastExpression; + generated$2.typeParameter = typeParameter; + generated$2.typeParameterDeclaration = typeParameterDeclaration; + generated$2.typeParameterInstantiation = typeParameterInstantiation; + generated$2.typeofTypeAnnotation = typeofTypeAnnotation; + generated$2.unaryExpression = unaryExpression; + generated$2.unionTypeAnnotation = unionTypeAnnotation; + generated$2.updateExpression = updateExpression; + generated$2.v8IntrinsicIdentifier = v8IntrinsicIdentifier; + generated$2.variableDeclaration = variableDeclaration; + generated$2.variableDeclarator = variableDeclarator; + generated$2.variance = variance; + generated$2.voidTypeAnnotation = voidTypeAnnotation; + generated$2.whileStatement = whileStatement; + generated$2.withStatement = withStatement; + generated$2.yieldExpression = yieldExpression; + var _validate = requireValidate(); + var _deprecationWarning = requireDeprecationWarning(); + var utils = requireUtils(); + const { + validateInternal: validate + } = _validate; + const { + NODE_FIELDS + } = utils; + function arrayExpression(elements = []) { + const node = { + type: "ArrayExpression", + elements + }; + const defs = NODE_FIELDS.ArrayExpression; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function assignmentExpression(operator, left, right) { + const node = { + type: "AssignmentExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.AssignmentExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function binaryExpression(operator, left, right) { + const node = { + type: "BinaryExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.BinaryExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function interpreterDirective(value) { + const node = { + type: "InterpreterDirective", + value + }; + const defs = NODE_FIELDS.InterpreterDirective; + validate(defs.value, node, "value", value); + return node; + } + function directive(value) { + const node = { + type: "Directive", + value + }; + const defs = NODE_FIELDS.Directive; + validate(defs.value, node, "value", value, 1); + return node; + } + function directiveLiteral(value) { + const node = { + type: "DirectiveLiteral", + value + }; + const defs = NODE_FIELDS.DirectiveLiteral; + validate(defs.value, node, "value", value); + return node; + } + function blockStatement(body, directives = []) { + const node = { + type: "BlockStatement", + body, + directives + }; + const defs = NODE_FIELDS.BlockStatement; + validate(defs.body, node, "body", body, 1); + validate(defs.directives, node, "directives", directives, 1); + return node; + } + function breakStatement(label = null) { + const node = { + type: "BreakStatement", + label + }; + const defs = NODE_FIELDS.BreakStatement; + validate(defs.label, node, "label", label, 1); + return node; + } + function callExpression(callee, _arguments) { + const node = { + type: "CallExpression", + callee, + arguments: _arguments + }; + const defs = NODE_FIELDS.CallExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + return node; + } + function catchClause(param = null, body) { + const node = { + type: "CatchClause", + param, + body + }; + const defs = NODE_FIELDS.CatchClause; + validate(defs.param, node, "param", param, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function conditionalExpression(test, consequent, alternate) { + const node = { + type: "ConditionalExpression", + test, + consequent, + alternate + }; + const defs = NODE_FIELDS.ConditionalExpression; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + validate(defs.alternate, node, "alternate", alternate, 1); + return node; + } + function continueStatement(label = null) { + const node = { + type: "ContinueStatement", + label + }; + const defs = NODE_FIELDS.ContinueStatement; + validate(defs.label, node, "label", label, 1); + return node; + } + function debuggerStatement() { + return { + type: "DebuggerStatement" + }; + } + function doWhileStatement(test, body) { + const node = { + type: "DoWhileStatement", + test, + body + }; + const defs = NODE_FIELDS.DoWhileStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function emptyStatement() { + return { + type: "EmptyStatement" + }; + } + function expressionStatement(expression) { + const node = { + type: "ExpressionStatement", + expression + }; + const defs = NODE_FIELDS.ExpressionStatement; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function file(program, comments = null, tokens = null) { + const node = { + type: "File", + program, + comments, + tokens + }; + const defs = NODE_FIELDS.File; + validate(defs.program, node, "program", program, 1); + validate(defs.comments, node, "comments", comments, 1); + validate(defs.tokens, node, "tokens", tokens); + return node; + } + function forInStatement(left, right, body) { + const node = { + type: "ForInStatement", + left, + right, + body + }; + const defs = NODE_FIELDS.ForInStatement; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function forStatement(init = null, test = null, update = null, body) { + const node = { + type: "ForStatement", + init, + test, + update, + body + }; + const defs = NODE_FIELDS.ForStatement; + validate(defs.init, node, "init", init, 1); + validate(defs.test, node, "test", test, 1); + validate(defs.update, node, "update", update, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function functionDeclaration(id = null, params, body, generator = false, async = false) { + const node = { + type: "FunctionDeclaration", + id, + params, + body, + generator, + async + }; + const defs = NODE_FIELDS.FunctionDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function functionExpression(id = null, params, body, generator = false, async = false) { + const node = { + type: "FunctionExpression", + id, + params, + body, + generator, + async + }; + const defs = NODE_FIELDS.FunctionExpression; + validate(defs.id, node, "id", id, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function identifier(name) { + const node = { + type: "Identifier", + name + }; + const defs = NODE_FIELDS.Identifier; + validate(defs.name, node, "name", name); + return node; + } + function ifStatement(test, consequent, alternate = null) { + const node = { + type: "IfStatement", + test, + consequent, + alternate + }; + const defs = NODE_FIELDS.IfStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + validate(defs.alternate, node, "alternate", alternate, 1); + return node; + } + function labeledStatement(label, body) { + const node = { + type: "LabeledStatement", + label, + body + }; + const defs = NODE_FIELDS.LabeledStatement; + validate(defs.label, node, "label", label, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function stringLiteral(value) { + const node = { + type: "StringLiteral", + value + }; + const defs = NODE_FIELDS.StringLiteral; + validate(defs.value, node, "value", value); + return node; + } + function numericLiteral(value) { + const node = { + type: "NumericLiteral", + value + }; + const defs = NODE_FIELDS.NumericLiteral; + validate(defs.value, node, "value", value); + return node; + } + function nullLiteral() { + return { + type: "NullLiteral" + }; + } + function booleanLiteral(value) { + const node = { + type: "BooleanLiteral", + value + }; + const defs = NODE_FIELDS.BooleanLiteral; + validate(defs.value, node, "value", value); + return node; + } + function regExpLiteral(pattern, flags = "") { + const node = { + type: "RegExpLiteral", + pattern, + flags + }; + const defs = NODE_FIELDS.RegExpLiteral; + validate(defs.pattern, node, "pattern", pattern); + validate(defs.flags, node, "flags", flags); + return node; + } + function logicalExpression(operator, left, right) { + const node = { + type: "LogicalExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.LogicalExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function memberExpression(object, property, computed = false, optional = null) { + const node = { + type: "MemberExpression", + object, + property, + computed, + optional + }; + const defs = NODE_FIELDS.MemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.optional, node, "optional", optional); + return node; + } + function newExpression(callee, _arguments) { + const node = { + type: "NewExpression", + callee, + arguments: _arguments + }; + const defs = NODE_FIELDS.NewExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + return node; + } + function program(body, directives = [], sourceType = "script", interpreter = null) { + const node = { + type: "Program", + body, + directives, + sourceType, + interpreter + }; + const defs = NODE_FIELDS.Program; + validate(defs.body, node, "body", body, 1); + validate(defs.directives, node, "directives", directives, 1); + validate(defs.sourceType, node, "sourceType", sourceType); + validate(defs.interpreter, node, "interpreter", interpreter, 1); + return node; + } + function objectExpression(properties) { + const node = { + type: "ObjectExpression", + properties + }; + const defs = NODE_FIELDS.ObjectExpression; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function objectMethod(kind = "method", key, params, body, computed = false, generator = false, async = false) { + const node = { + type: "ObjectMethod", + kind, + key, + params, + body, + computed, + generator, + async + }; + const defs = NODE_FIELDS.ObjectMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function objectProperty(key, value, computed = false, shorthand = false, decorators = null) { + const node = { + type: "ObjectProperty", + key, + value, + computed, + shorthand, + decorators + }; + const defs = NODE_FIELDS.ObjectProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.shorthand, node, "shorthand", shorthand); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function restElement(argument) { + const node = { + type: "RestElement", + argument + }; + const defs = NODE_FIELDS.RestElement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function returnStatement(argument = null) { + const node = { + type: "ReturnStatement", + argument + }; + const defs = NODE_FIELDS.ReturnStatement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function sequenceExpression(expressions) { + const node = { + type: "SequenceExpression", + expressions + }; + const defs = NODE_FIELDS.SequenceExpression; + validate(defs.expressions, node, "expressions", expressions, 1); + return node; + } + function parenthesizedExpression(expression) { + const node = { + type: "ParenthesizedExpression", + expression + }; + const defs = NODE_FIELDS.ParenthesizedExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function switchCase(test = null, consequent) { + const node = { + type: "SwitchCase", + test, + consequent + }; + const defs = NODE_FIELDS.SwitchCase; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + return node; + } + function switchStatement(discriminant, cases) { + const node = { + type: "SwitchStatement", + discriminant, + cases + }; + const defs = NODE_FIELDS.SwitchStatement; + validate(defs.discriminant, node, "discriminant", discriminant, 1); + validate(defs.cases, node, "cases", cases, 1); + return node; + } + function thisExpression() { + return { + type: "ThisExpression" + }; + } + function throwStatement(argument) { + const node = { + type: "ThrowStatement", + argument + }; + const defs = NODE_FIELDS.ThrowStatement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function tryStatement(block, handler = null, finalizer = null) { + const node = { + type: "TryStatement", + block, + handler, + finalizer + }; + const defs = NODE_FIELDS.TryStatement; + validate(defs.block, node, "block", block, 1); + validate(defs.handler, node, "handler", handler, 1); + validate(defs.finalizer, node, "finalizer", finalizer, 1); + return node; + } + function unaryExpression(operator, argument, prefix = true) { + const node = { + type: "UnaryExpression", + operator, + argument, + prefix + }; + const defs = NODE_FIELDS.UnaryExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.argument, node, "argument", argument, 1); + validate(defs.prefix, node, "prefix", prefix); + return node; + } + function updateExpression(operator, argument, prefix = false) { + const node = { + type: "UpdateExpression", + operator, + argument, + prefix + }; + const defs = NODE_FIELDS.UpdateExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.argument, node, "argument", argument, 1); + validate(defs.prefix, node, "prefix", prefix); + return node; + } + function variableDeclaration(kind, declarations) { + const node = { + type: "VariableDeclaration", + kind, + declarations + }; + const defs = NODE_FIELDS.VariableDeclaration; + validate(defs.kind, node, "kind", kind); + validate(defs.declarations, node, "declarations", declarations, 1); + return node; + } + function variableDeclarator(id, init = null) { + const node = { + type: "VariableDeclarator", + id, + init + }; + const defs = NODE_FIELDS.VariableDeclarator; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function whileStatement(test, body) { + const node = { + type: "WhileStatement", + test, + body + }; + const defs = NODE_FIELDS.WhileStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function withStatement(object, body) { + const node = { + type: "WithStatement", + object, + body + }; + const defs = NODE_FIELDS.WithStatement; + validate(defs.object, node, "object", object, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function assignmentPattern(left, right) { + const node = { + type: "AssignmentPattern", + left, + right + }; + const defs = NODE_FIELDS.AssignmentPattern; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function arrayPattern(elements) { + const node = { + type: "ArrayPattern", + elements + }; + const defs = NODE_FIELDS.ArrayPattern; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function arrowFunctionExpression(params, body, async = false) { + const node = { + type: "ArrowFunctionExpression", + params, + body, + async, + expression: null + }; + const defs = NODE_FIELDS.ArrowFunctionExpression; + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.async, node, "async", async); + return node; + } + function classBody(body) { + const node = { + type: "ClassBody", + body + }; + const defs = NODE_FIELDS.ClassBody; + validate(defs.body, node, "body", body, 1); + return node; + } + function classExpression(id = null, superClass = null, body, decorators = null) { + const node = { + type: "ClassExpression", + id, + superClass, + body, + decorators + }; + const defs = NODE_FIELDS.ClassExpression; + validate(defs.id, node, "id", id, 1); + validate(defs.superClass, node, "superClass", superClass, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function classDeclaration(id = null, superClass = null, body, decorators = null) { + const node = { + type: "ClassDeclaration", + id, + superClass, + body, + decorators + }; + const defs = NODE_FIELDS.ClassDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.superClass, node, "superClass", superClass, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function exportAllDeclaration(source) { + const node = { + type: "ExportAllDeclaration", + source + }; + const defs = NODE_FIELDS.ExportAllDeclaration; + validate(defs.source, node, "source", source, 1); + return node; + } + function exportDefaultDeclaration(declaration) { + const node = { + type: "ExportDefaultDeclaration", + declaration + }; + const defs = NODE_FIELDS.ExportDefaultDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + return node; + } + function exportNamedDeclaration(declaration = null, specifiers = [], source = null) { + const node = { + type: "ExportNamedDeclaration", + declaration, + specifiers, + source + }; + const defs = NODE_FIELDS.ExportNamedDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + return node; + } + function exportSpecifier(local, exported) { + const node = { + type: "ExportSpecifier", + local, + exported + }; + const defs = NODE_FIELDS.ExportSpecifier; + validate(defs.local, node, "local", local, 1); + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function forOfStatement(left, right, body, _await = false) { + const node = { + type: "ForOfStatement", + left, + right, + body, + await: _await + }; + const defs = NODE_FIELDS.ForOfStatement; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.await, node, "await", _await); + return node; + } + function importDeclaration(specifiers, source) { + const node = { + type: "ImportDeclaration", + specifiers, + source + }; + const defs = NODE_FIELDS.ImportDeclaration; + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + return node; + } + function importDefaultSpecifier(local) { + const node = { + type: "ImportDefaultSpecifier", + local + }; + const defs = NODE_FIELDS.ImportDefaultSpecifier; + validate(defs.local, node, "local", local, 1); + return node; + } + function importNamespaceSpecifier(local) { + const node = { + type: "ImportNamespaceSpecifier", + local + }; + const defs = NODE_FIELDS.ImportNamespaceSpecifier; + validate(defs.local, node, "local", local, 1); + return node; + } + function importSpecifier(local, imported) { + const node = { + type: "ImportSpecifier", + local, + imported + }; + const defs = NODE_FIELDS.ImportSpecifier; + validate(defs.local, node, "local", local, 1); + validate(defs.imported, node, "imported", imported, 1); + return node; + } + function importExpression(source, options = null) { + const node = { + type: "ImportExpression", + source, + options + }; + const defs = NODE_FIELDS.ImportExpression; + validate(defs.source, node, "source", source, 1); + validate(defs.options, node, "options", options, 1); + return node; + } + function metaProperty(meta, property) { + const node = { + type: "MetaProperty", + meta, + property + }; + const defs = NODE_FIELDS.MetaProperty; + validate(defs.meta, node, "meta", meta, 1); + validate(defs.property, node, "property", property, 1); + return node; + } + function classMethod(kind = "method", key, params, body, computed = false, _static = false, generator = false, async = false) { + const node = { + type: "ClassMethod", + kind, + key, + params, + body, + computed, + static: _static, + generator, + async + }; + const defs = NODE_FIELDS.ClassMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function objectPattern(properties) { + const node = { + type: "ObjectPattern", + properties + }; + const defs = NODE_FIELDS.ObjectPattern; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function spreadElement(argument) { + const node = { + type: "SpreadElement", + argument + }; + const defs = NODE_FIELDS.SpreadElement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function _super() { + return { + type: "Super" + }; + } + function taggedTemplateExpression(tag, quasi) { + const node = { + type: "TaggedTemplateExpression", + tag, + quasi + }; + const defs = NODE_FIELDS.TaggedTemplateExpression; + validate(defs.tag, node, "tag", tag, 1); + validate(defs.quasi, node, "quasi", quasi, 1); + return node; + } + function templateElement(value, tail = false) { + const node = { + type: "TemplateElement", + value, + tail + }; + const defs = NODE_FIELDS.TemplateElement; + validate(defs.value, node, "value", value); + validate(defs.tail, node, "tail", tail); + return node; + } + function templateLiteral(quasis, expressions) { + const node = { + type: "TemplateLiteral", + quasis, + expressions + }; + const defs = NODE_FIELDS.TemplateLiteral; + validate(defs.quasis, node, "quasis", quasis, 1); + validate(defs.expressions, node, "expressions", expressions, 1); + return node; + } + function yieldExpression(argument = null, delegate = false) { + const node = { + type: "YieldExpression", + argument, + delegate + }; + const defs = NODE_FIELDS.YieldExpression; + validate(defs.argument, node, "argument", argument, 1); + validate(defs.delegate, node, "delegate", delegate); + return node; + } + function awaitExpression(argument) { + const node = { + type: "AwaitExpression", + argument + }; + const defs = NODE_FIELDS.AwaitExpression; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function _import() { + return { + type: "Import" + }; + } + function bigIntLiteral(value) { + const node = { + type: "BigIntLiteral", + value + }; + const defs = NODE_FIELDS.BigIntLiteral; + validate(defs.value, node, "value", value); + return node; + } + function exportNamespaceSpecifier(exported) { + const node = { + type: "ExportNamespaceSpecifier", + exported + }; + const defs = NODE_FIELDS.ExportNamespaceSpecifier; + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function optionalMemberExpression(object, property, computed = false, optional) { + const node = { + type: "OptionalMemberExpression", + object, + property, + computed, + optional + }; + const defs = NODE_FIELDS.OptionalMemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.optional, node, "optional", optional); + return node; + } + function optionalCallExpression(callee, _arguments, optional) { + const node = { + type: "OptionalCallExpression", + callee, + arguments: _arguments, + optional + }; + const defs = NODE_FIELDS.OptionalCallExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + validate(defs.optional, node, "optional", optional); + return node; + } + function classProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { + const node = { + type: "ClassProperty", + key, + value, + typeAnnotation, + decorators, + computed, + static: _static + }; + const defs = NODE_FIELDS.ClassProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + return node; + } + function classAccessorProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { + const node = { + type: "ClassAccessorProperty", + key, + value, + typeAnnotation, + decorators, + computed, + static: _static + }; + const defs = NODE_FIELDS.ClassAccessorProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + return node; + } + function classPrivateProperty(key, value = null, decorators = null, _static = false) { + const node = { + type: "ClassPrivateProperty", + key, + value, + decorators, + static: _static + }; + const defs = NODE_FIELDS.ClassPrivateProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.static, node, "static", _static); + return node; + } + function classPrivateMethod(kind = "method", key, params, body, _static = false) { + const node = { + type: "ClassPrivateMethod", + kind, + key, + params, + body, + static: _static + }; + const defs = NODE_FIELDS.ClassPrivateMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.static, node, "static", _static); + return node; + } + function privateName(id) { + const node = { + type: "PrivateName", + id + }; + const defs = NODE_FIELDS.PrivateName; + validate(defs.id, node, "id", id, 1); + return node; + } + function staticBlock(body) { + const node = { + type: "StaticBlock", + body + }; + const defs = NODE_FIELDS.StaticBlock; + validate(defs.body, node, "body", body, 1); + return node; + } + function anyTypeAnnotation() { + return { + type: "AnyTypeAnnotation" + }; + } + function arrayTypeAnnotation(elementType) { + const node = { + type: "ArrayTypeAnnotation", + elementType + }; + const defs = NODE_FIELDS.ArrayTypeAnnotation; + validate(defs.elementType, node, "elementType", elementType, 1); + return node; + } + function booleanTypeAnnotation() { + return { + type: "BooleanTypeAnnotation" + }; + } + function booleanLiteralTypeAnnotation(value) { + const node = { + type: "BooleanLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.BooleanLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function nullLiteralTypeAnnotation() { + return { + type: "NullLiteralTypeAnnotation" + }; + } + function classImplements(id, typeParameters = null) { + const node = { + type: "ClassImplements", + id, + typeParameters + }; + const defs = NODE_FIELDS.ClassImplements; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function declareClass(id, typeParameters = null, _extends = null, body) { + const node = { + type: "DeclareClass", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.DeclareClass; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function declareFunction(id) { + const node = { + type: "DeclareFunction", + id + }; + const defs = NODE_FIELDS.DeclareFunction; + validate(defs.id, node, "id", id, 1); + return node; + } + function declareInterface(id, typeParameters = null, _extends = null, body) { + const node = { + type: "DeclareInterface", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.DeclareInterface; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function declareModule(id, body, kind = null) { + const node = { + type: "DeclareModule", + id, + body, + kind + }; + const defs = NODE_FIELDS.DeclareModule; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.kind, node, "kind", kind); + return node; + } + function declareModuleExports(typeAnnotation) { + const node = { + type: "DeclareModuleExports", + typeAnnotation + }; + const defs = NODE_FIELDS.DeclareModuleExports; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function declareTypeAlias(id, typeParameters = null, right) { + const node = { + type: "DeclareTypeAlias", + id, + typeParameters, + right + }; + const defs = NODE_FIELDS.DeclareTypeAlias; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function declareOpaqueType(id, typeParameters = null, supertype = null) { + const node = { + type: "DeclareOpaqueType", + id, + typeParameters, + supertype + }; + const defs = NODE_FIELDS.DeclareOpaqueType; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.supertype, node, "supertype", supertype, 1); + return node; + } + function declareVariable(id) { + const node = { + type: "DeclareVariable", + id + }; + const defs = NODE_FIELDS.DeclareVariable; + validate(defs.id, node, "id", id, 1); + return node; + } + function declareExportDeclaration(declaration = null, specifiers = null, source = null, attributes = null) { + const node = { + type: "DeclareExportDeclaration", + declaration, + specifiers, + source, + attributes + }; + const defs = NODE_FIELDS.DeclareExportDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + return node; + } + function declareExportAllDeclaration(source, attributes = null) { + const node = { + type: "DeclareExportAllDeclaration", + source, + attributes + }; + const defs = NODE_FIELDS.DeclareExportAllDeclaration; + validate(defs.source, node, "source", source, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + return node; + } + function declaredPredicate(value) { + const node = { + type: "DeclaredPredicate", + value + }; + const defs = NODE_FIELDS.DeclaredPredicate; + validate(defs.value, node, "value", value, 1); + return node; + } + function existsTypeAnnotation() { + return { + type: "ExistsTypeAnnotation" + }; + } + function functionTypeAnnotation(typeParameters = null, params, rest = null, returnType) { + const node = { + type: "FunctionTypeAnnotation", + typeParameters, + params, + rest, + returnType + }; + const defs = NODE_FIELDS.FunctionTypeAnnotation; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.rest, node, "rest", rest, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function functionTypeParam(name = null, typeAnnotation) { + const node = { + type: "FunctionTypeParam", + name, + typeAnnotation + }; + const defs = NODE_FIELDS.FunctionTypeParam; + validate(defs.name, node, "name", name, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function genericTypeAnnotation(id, typeParameters = null) { + const node = { + type: "GenericTypeAnnotation", + id, + typeParameters + }; + const defs = NODE_FIELDS.GenericTypeAnnotation; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function inferredPredicate() { + return { + type: "InferredPredicate" + }; + } + function interfaceExtends(id, typeParameters = null) { + const node = { + type: "InterfaceExtends", + id, + typeParameters + }; + const defs = NODE_FIELDS.InterfaceExtends; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function interfaceDeclaration(id, typeParameters = null, _extends = null, body) { + const node = { + type: "InterfaceDeclaration", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.InterfaceDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function interfaceTypeAnnotation(_extends = null, body) { + const node = { + type: "InterfaceTypeAnnotation", + extends: _extends, + body + }; + const defs = NODE_FIELDS.InterfaceTypeAnnotation; + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function intersectionTypeAnnotation(types) { + const node = { + type: "IntersectionTypeAnnotation", + types + }; + const defs = NODE_FIELDS.IntersectionTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function mixedTypeAnnotation() { + return { + type: "MixedTypeAnnotation" + }; + } + function emptyTypeAnnotation() { + return { + type: "EmptyTypeAnnotation" + }; + } + function nullableTypeAnnotation(typeAnnotation) { + const node = { + type: "NullableTypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.NullableTypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function numberLiteralTypeAnnotation(value) { + const node = { + type: "NumberLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.NumberLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function numberTypeAnnotation() { + return { + type: "NumberTypeAnnotation" + }; + } + function objectTypeAnnotation(properties, indexers = [], callProperties = [], internalSlots = [], exact = false) { + const node = { + type: "ObjectTypeAnnotation", + properties, + indexers, + callProperties, + internalSlots, + exact + }; + const defs = NODE_FIELDS.ObjectTypeAnnotation; + validate(defs.properties, node, "properties", properties, 1); + validate(defs.indexers, node, "indexers", indexers, 1); + validate(defs.callProperties, node, "callProperties", callProperties, 1); + validate(defs.internalSlots, node, "internalSlots", internalSlots, 1); + validate(defs.exact, node, "exact", exact); + return node; + } + function objectTypeInternalSlot(id, value, optional, _static, method) { + const node = { + type: "ObjectTypeInternalSlot", + id, + value, + optional, + static: _static, + method + }; + const defs = NODE_FIELDS.ObjectTypeInternalSlot; + validate(defs.id, node, "id", id, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.optional, node, "optional", optional); + validate(defs.static, node, "static", _static); + validate(defs.method, node, "method", method); + return node; + } + function objectTypeCallProperty(value) { + const node = { + type: "ObjectTypeCallProperty", + value, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeCallProperty; + validate(defs.value, node, "value", value, 1); + return node; + } + function objectTypeIndexer(id = null, key, value, variance = null) { + const node = { + type: "ObjectTypeIndexer", + id, + key, + value, + variance, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeIndexer; + validate(defs.id, node, "id", id, 1); + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function objectTypeProperty(key, value, variance = null) { + const node = { + type: "ObjectTypeProperty", + key, + value, + variance, + kind: null, + method: null, + optional: null, + proto: null, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function objectTypeSpreadProperty(argument) { + const node = { + type: "ObjectTypeSpreadProperty", + argument + }; + const defs = NODE_FIELDS.ObjectTypeSpreadProperty; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function opaqueType(id, typeParameters = null, supertype = null, impltype) { + const node = { + type: "OpaqueType", + id, + typeParameters, + supertype, + impltype + }; + const defs = NODE_FIELDS.OpaqueType; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.supertype, node, "supertype", supertype, 1); + validate(defs.impltype, node, "impltype", impltype, 1); + return node; + } + function qualifiedTypeIdentifier(id, qualification) { + const node = { + type: "QualifiedTypeIdentifier", + id, + qualification + }; + const defs = NODE_FIELDS.QualifiedTypeIdentifier; + validate(defs.id, node, "id", id, 1); + validate(defs.qualification, node, "qualification", qualification, 1); + return node; + } + function stringLiteralTypeAnnotation(value) { + const node = { + type: "StringLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.StringLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function stringTypeAnnotation() { + return { + type: "StringTypeAnnotation" + }; + } + function symbolTypeAnnotation() { + return { + type: "SymbolTypeAnnotation" + }; + } + function thisTypeAnnotation() { + return { + type: "ThisTypeAnnotation" + }; + } + function tupleTypeAnnotation(types) { + const node = { + type: "TupleTypeAnnotation", + types + }; + const defs = NODE_FIELDS.TupleTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function typeofTypeAnnotation(argument) { + const node = { + type: "TypeofTypeAnnotation", + argument + }; + const defs = NODE_FIELDS.TypeofTypeAnnotation; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function typeAlias(id, typeParameters = null, right) { + const node = { + type: "TypeAlias", + id, + typeParameters, + right + }; + const defs = NODE_FIELDS.TypeAlias; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function typeAnnotation(typeAnnotation) { + const node = { + type: "TypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.TypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function typeCastExpression(expression, typeAnnotation) { + const node = { + type: "TypeCastExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TypeCastExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function typeParameter(bound = null, _default = null, variance = null) { + const node = { + type: "TypeParameter", + bound, + default: _default, + variance, + name: null + }; + const defs = NODE_FIELDS.TypeParameter; + validate(defs.bound, node, "bound", bound, 1); + validate(defs.default, node, "default", _default, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function typeParameterDeclaration(params) { + const node = { + type: "TypeParameterDeclaration", + params + }; + const defs = NODE_FIELDS.TypeParameterDeclaration; + validate(defs.params, node, "params", params, 1); + return node; + } + function typeParameterInstantiation(params) { + const node = { + type: "TypeParameterInstantiation", + params + }; + const defs = NODE_FIELDS.TypeParameterInstantiation; + validate(defs.params, node, "params", params, 1); + return node; + } + function unionTypeAnnotation(types) { + const node = { + type: "UnionTypeAnnotation", + types + }; + const defs = NODE_FIELDS.UnionTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function variance(kind) { + const node = { + type: "Variance", + kind + }; + const defs = NODE_FIELDS.Variance; + validate(defs.kind, node, "kind", kind); + return node; + } + function voidTypeAnnotation() { + return { + type: "VoidTypeAnnotation" + }; + } + function enumDeclaration(id, body) { + const node = { + type: "EnumDeclaration", + id, + body + }; + const defs = NODE_FIELDS.EnumDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function enumBooleanBody(members) { + const node = { + type: "EnumBooleanBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumBooleanBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumNumberBody(members) { + const node = { + type: "EnumNumberBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumNumberBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumStringBody(members) { + const node = { + type: "EnumStringBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumStringBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumSymbolBody(members) { + const node = { + type: "EnumSymbolBody", + members, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumSymbolBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumBooleanMember(id) { + const node = { + type: "EnumBooleanMember", + id, + init: null + }; + const defs = NODE_FIELDS.EnumBooleanMember; + validate(defs.id, node, "id", id, 1); + return node; + } + function enumNumberMember(id, init) { + const node = { + type: "EnumNumberMember", + id, + init + }; + const defs = NODE_FIELDS.EnumNumberMember; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function enumStringMember(id, init) { + const node = { + type: "EnumStringMember", + id, + init + }; + const defs = NODE_FIELDS.EnumStringMember; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function enumDefaultedMember(id) { + const node = { + type: "EnumDefaultedMember", + id + }; + const defs = NODE_FIELDS.EnumDefaultedMember; + validate(defs.id, node, "id", id, 1); + return node; + } + function indexedAccessType(objectType, indexType) { + const node = { + type: "IndexedAccessType", + objectType, + indexType + }; + const defs = NODE_FIELDS.IndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function optionalIndexedAccessType(objectType, indexType) { + const node = { + type: "OptionalIndexedAccessType", + objectType, + indexType, + optional: null + }; + const defs = NODE_FIELDS.OptionalIndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function jsxAttribute(name, value = null) { + const node = { + type: "JSXAttribute", + name, + value + }; + const defs = NODE_FIELDS.JSXAttribute; + validate(defs.name, node, "name", name, 1); + validate(defs.value, node, "value", value, 1); + return node; + } + function jsxClosingElement(name) { + const node = { + type: "JSXClosingElement", + name + }; + const defs = NODE_FIELDS.JSXClosingElement; + validate(defs.name, node, "name", name, 1); + return node; + } + function jsxElement(openingElement, closingElement = null, children, selfClosing = null) { + const node = { + type: "JSXElement", + openingElement, + closingElement, + children, + selfClosing + }; + const defs = NODE_FIELDS.JSXElement; + validate(defs.openingElement, node, "openingElement", openingElement, 1); + validate(defs.closingElement, node, "closingElement", closingElement, 1); + validate(defs.children, node, "children", children, 1); + validate(defs.selfClosing, node, "selfClosing", selfClosing); + return node; + } + function jsxEmptyExpression() { + return { + type: "JSXEmptyExpression" + }; + } + function jsxExpressionContainer(expression) { + const node = { + type: "JSXExpressionContainer", + expression + }; + const defs = NODE_FIELDS.JSXExpressionContainer; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function jsxSpreadChild(expression) { + const node = { + type: "JSXSpreadChild", + expression + }; + const defs = NODE_FIELDS.JSXSpreadChild; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function jsxIdentifier(name) { + const node = { + type: "JSXIdentifier", + name + }; + const defs = NODE_FIELDS.JSXIdentifier; + validate(defs.name, node, "name", name); + return node; + } + function jsxMemberExpression(object, property) { + const node = { + type: "JSXMemberExpression", + object, + property + }; + const defs = NODE_FIELDS.JSXMemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + return node; + } + function jsxNamespacedName(namespace, name) { + const node = { + type: "JSXNamespacedName", + namespace, + name + }; + const defs = NODE_FIELDS.JSXNamespacedName; + validate(defs.namespace, node, "namespace", namespace, 1); + validate(defs.name, node, "name", name, 1); + return node; + } + function jsxOpeningElement(name, attributes, selfClosing = false) { + const node = { + type: "JSXOpeningElement", + name, + attributes, + selfClosing + }; + const defs = NODE_FIELDS.JSXOpeningElement; + validate(defs.name, node, "name", name, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + validate(defs.selfClosing, node, "selfClosing", selfClosing); + return node; + } + function jsxSpreadAttribute(argument) { + const node = { + type: "JSXSpreadAttribute", + argument + }; + const defs = NODE_FIELDS.JSXSpreadAttribute; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function jsxText(value) { + const node = { + type: "JSXText", + value + }; + const defs = NODE_FIELDS.JSXText; + validate(defs.value, node, "value", value); + return node; + } + function jsxFragment(openingFragment, closingFragment, children) { + const node = { + type: "JSXFragment", + openingFragment, + closingFragment, + children + }; + const defs = NODE_FIELDS.JSXFragment; + validate(defs.openingFragment, node, "openingFragment", openingFragment, 1); + validate(defs.closingFragment, node, "closingFragment", closingFragment, 1); + validate(defs.children, node, "children", children, 1); + return node; + } + function jsxOpeningFragment() { + return { + type: "JSXOpeningFragment" + }; + } + function jsxClosingFragment() { + return { + type: "JSXClosingFragment" + }; + } + function noop() { + return { + type: "Noop" + }; + } + function placeholder(expectedNode, name) { + const node = { + type: "Placeholder", + expectedNode, + name + }; + const defs = NODE_FIELDS.Placeholder; + validate(defs.expectedNode, node, "expectedNode", expectedNode); + validate(defs.name, node, "name", name, 1); + return node; + } + function v8IntrinsicIdentifier(name) { + const node = { + type: "V8IntrinsicIdentifier", + name + }; + const defs = NODE_FIELDS.V8IntrinsicIdentifier; + validate(defs.name, node, "name", name); + return node; + } + function argumentPlaceholder() { + return { + type: "ArgumentPlaceholder" + }; + } + function bindExpression(object, callee) { + const node = { + type: "BindExpression", + object, + callee + }; + const defs = NODE_FIELDS.BindExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.callee, node, "callee", callee, 1); + return node; + } + function importAttribute(key, value) { + const node = { + type: "ImportAttribute", + key, + value + }; + const defs = NODE_FIELDS.ImportAttribute; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + return node; + } + function decorator(expression) { + const node = { + type: "Decorator", + expression + }; + const defs = NODE_FIELDS.Decorator; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function doExpression(body, async = false) { + const node = { + type: "DoExpression", + body, + async + }; + const defs = NODE_FIELDS.DoExpression; + validate(defs.body, node, "body", body, 1); + validate(defs.async, node, "async", async); + return node; + } + function exportDefaultSpecifier(exported) { + const node = { + type: "ExportDefaultSpecifier", + exported + }; + const defs = NODE_FIELDS.ExportDefaultSpecifier; + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function recordExpression(properties) { + const node = { + type: "RecordExpression", + properties + }; + const defs = NODE_FIELDS.RecordExpression; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function tupleExpression(elements = []) { + const node = { + type: "TupleExpression", + elements + }; + const defs = NODE_FIELDS.TupleExpression; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function decimalLiteral(value) { + const node = { + type: "DecimalLiteral", + value + }; + const defs = NODE_FIELDS.DecimalLiteral; + validate(defs.value, node, "value", value); + return node; + } + function moduleExpression(body) { + const node = { + type: "ModuleExpression", + body + }; + const defs = NODE_FIELDS.ModuleExpression; + validate(defs.body, node, "body", body, 1); + return node; + } + function topicReference() { + return { + type: "TopicReference" + }; + } + function pipelineTopicExpression(expression) { + const node = { + type: "PipelineTopicExpression", + expression + }; + const defs = NODE_FIELDS.PipelineTopicExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function pipelineBareFunction(callee) { + const node = { + type: "PipelineBareFunction", + callee + }; + const defs = NODE_FIELDS.PipelineBareFunction; + validate(defs.callee, node, "callee", callee, 1); + return node; + } + function pipelinePrimaryTopicReference() { + return { + type: "PipelinePrimaryTopicReference" + }; + } + function tsParameterProperty(parameter) { + const node = { + type: "TSParameterProperty", + parameter + }; + const defs = NODE_FIELDS.TSParameterProperty; + validate(defs.parameter, node, "parameter", parameter, 1); + return node; + } + function tsDeclareFunction(id = null, typeParameters = null, params, returnType = null) { + const node = { + type: "TSDeclareFunction", + id, + typeParameters, + params, + returnType + }; + const defs = NODE_FIELDS.TSDeclareFunction; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function tsDeclareMethod(decorators = null, key, typeParameters = null, params, returnType = null) { + const node = { + type: "TSDeclareMethod", + decorators, + key, + typeParameters, + params, + returnType + }; + const defs = NODE_FIELDS.TSDeclareMethod; + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.key, node, "key", key, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function tsQualifiedName(left, right) { + const node = { + type: "TSQualifiedName", + left, + right + }; + const defs = NODE_FIELDS.TSQualifiedName; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function tsCallSignatureDeclaration(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSCallSignatureDeclaration", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSCallSignatureDeclaration; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsConstructSignatureDeclaration(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSConstructSignatureDeclaration", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSConstructSignatureDeclaration; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsPropertySignature(key, typeAnnotation = null) { + const node = { + type: "TSPropertySignature", + key, + typeAnnotation, + kind: null + }; + const defs = NODE_FIELDS.TSPropertySignature; + validate(defs.key, node, "key", key, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsMethodSignature(key, typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSMethodSignature", + key, + typeParameters, + parameters, + typeAnnotation, + kind: null + }; + const defs = NODE_FIELDS.TSMethodSignature; + validate(defs.key, node, "key", key, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsIndexSignature(parameters, typeAnnotation = null) { + const node = { + type: "TSIndexSignature", + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSIndexSignature; + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsAnyKeyword() { + return { + type: "TSAnyKeyword" + }; + } + function tsBooleanKeyword() { + return { + type: "TSBooleanKeyword" + }; + } + function tsBigIntKeyword() { + return { + type: "TSBigIntKeyword" + }; + } + function tsIntrinsicKeyword() { + return { + type: "TSIntrinsicKeyword" + }; + } + function tsNeverKeyword() { + return { + type: "TSNeverKeyword" + }; + } + function tsNullKeyword() { + return { + type: "TSNullKeyword" + }; + } + function tsNumberKeyword() { + return { + type: "TSNumberKeyword" + }; + } + function tsObjectKeyword() { + return { + type: "TSObjectKeyword" + }; + } + function tsStringKeyword() { + return { + type: "TSStringKeyword" + }; + } + function tsSymbolKeyword() { + return { + type: "TSSymbolKeyword" + }; + } + function tsUndefinedKeyword() { + return { + type: "TSUndefinedKeyword" + }; + } + function tsUnknownKeyword() { + return { + type: "TSUnknownKeyword" + }; + } + function tsVoidKeyword() { + return { + type: "TSVoidKeyword" + }; + } + function tsThisType() { + return { + type: "TSThisType" + }; + } + function tsFunctionType(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSFunctionType", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSFunctionType; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsConstructorType(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSConstructorType", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSConstructorType; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeReference(typeName, typeParameters = null) { + const node = { + type: "TSTypeReference", + typeName, + typeParameters + }; + const defs = NODE_FIELDS.TSTypeReference; + validate(defs.typeName, node, "typeName", typeName, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsTypePredicate(parameterName, typeAnnotation = null, asserts = null) { + const node = { + type: "TSTypePredicate", + parameterName, + typeAnnotation, + asserts + }; + const defs = NODE_FIELDS.TSTypePredicate; + validate(defs.parameterName, node, "parameterName", parameterName, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.asserts, node, "asserts", asserts); + return node; + } + function tsTypeQuery(exprName, typeParameters = null) { + const node = { + type: "TSTypeQuery", + exprName, + typeParameters + }; + const defs = NODE_FIELDS.TSTypeQuery; + validate(defs.exprName, node, "exprName", exprName, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsTypeLiteral(members) { + const node = { + type: "TSTypeLiteral", + members + }; + const defs = NODE_FIELDS.TSTypeLiteral; + validate(defs.members, node, "members", members, 1); + return node; + } + function tsArrayType(elementType) { + const node = { + type: "TSArrayType", + elementType + }; + const defs = NODE_FIELDS.TSArrayType; + validate(defs.elementType, node, "elementType", elementType, 1); + return node; + } + function tsTupleType(elementTypes) { + const node = { + type: "TSTupleType", + elementTypes + }; + const defs = NODE_FIELDS.TSTupleType; + validate(defs.elementTypes, node, "elementTypes", elementTypes, 1); + return node; + } + function tsOptionalType(typeAnnotation) { + const node = { + type: "TSOptionalType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSOptionalType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsRestType(typeAnnotation) { + const node = { + type: "TSRestType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSRestType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsNamedTupleMember(label, elementType, optional = false) { + const node = { + type: "TSNamedTupleMember", + label, + elementType, + optional + }; + const defs = NODE_FIELDS.TSNamedTupleMember; + validate(defs.label, node, "label", label, 1); + validate(defs.elementType, node, "elementType", elementType, 1); + validate(defs.optional, node, "optional", optional); + return node; + } + function tsUnionType(types) { + const node = { + type: "TSUnionType", + types + }; + const defs = NODE_FIELDS.TSUnionType; + validate(defs.types, node, "types", types, 1); + return node; + } + function tsIntersectionType(types) { + const node = { + type: "TSIntersectionType", + types + }; + const defs = NODE_FIELDS.TSIntersectionType; + validate(defs.types, node, "types", types, 1); + return node; + } + function tsConditionalType(checkType, extendsType, trueType, falseType) { + const node = { + type: "TSConditionalType", + checkType, + extendsType, + trueType, + falseType + }; + const defs = NODE_FIELDS.TSConditionalType; + validate(defs.checkType, node, "checkType", checkType, 1); + validate(defs.extendsType, node, "extendsType", extendsType, 1); + validate(defs.trueType, node, "trueType", trueType, 1); + validate(defs.falseType, node, "falseType", falseType, 1); + return node; + } + function tsInferType(typeParameter) { + const node = { + type: "TSInferType", + typeParameter + }; + const defs = NODE_FIELDS.TSInferType; + validate(defs.typeParameter, node, "typeParameter", typeParameter, 1); + return node; + } + function tsParenthesizedType(typeAnnotation) { + const node = { + type: "TSParenthesizedType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSParenthesizedType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeOperator(typeAnnotation) { + const node = { + type: "TSTypeOperator", + typeAnnotation, + operator: null + }; + const defs = NODE_FIELDS.TSTypeOperator; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsIndexedAccessType(objectType, indexType) { + const node = { + type: "TSIndexedAccessType", + objectType, + indexType + }; + const defs = NODE_FIELDS.TSIndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function tsMappedType(typeParameter, typeAnnotation = null, nameType = null) { + const node = { + type: "TSMappedType", + typeParameter, + typeAnnotation, + nameType + }; + const defs = NODE_FIELDS.TSMappedType; + validate(defs.typeParameter, node, "typeParameter", typeParameter, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.nameType, node, "nameType", nameType, 1); + return node; + } + function tsLiteralType(literal) { + const node = { + type: "TSLiteralType", + literal + }; + const defs = NODE_FIELDS.TSLiteralType; + validate(defs.literal, node, "literal", literal, 1); + return node; + } + function tsExpressionWithTypeArguments(expression, typeParameters = null) { + const node = { + type: "TSExpressionWithTypeArguments", + expression, + typeParameters + }; + const defs = NODE_FIELDS.TSExpressionWithTypeArguments; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsInterfaceDeclaration(id, typeParameters = null, _extends = null, body) { + const node = { + type: "TSInterfaceDeclaration", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.TSInterfaceDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function tsInterfaceBody(body) { + const node = { + type: "TSInterfaceBody", + body + }; + const defs = NODE_FIELDS.TSInterfaceBody; + validate(defs.body, node, "body", body, 1); + return node; + } + function tsTypeAliasDeclaration(id, typeParameters = null, typeAnnotation) { + const node = { + type: "TSTypeAliasDeclaration", + id, + typeParameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSTypeAliasDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsInstantiationExpression(expression, typeParameters = null) { + const node = { + type: "TSInstantiationExpression", + expression, + typeParameters + }; + const defs = NODE_FIELDS.TSInstantiationExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsAsExpression(expression, typeAnnotation) { + const node = { + type: "TSAsExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TSAsExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsSatisfiesExpression(expression, typeAnnotation) { + const node = { + type: "TSSatisfiesExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TSSatisfiesExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeAssertion(typeAnnotation, expression) { + const node = { + type: "TSTypeAssertion", + typeAnnotation, + expression + }; + const defs = NODE_FIELDS.TSTypeAssertion; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsEnumDeclaration(id, members) { + const node = { + type: "TSEnumDeclaration", + id, + members + }; + const defs = NODE_FIELDS.TSEnumDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.members, node, "members", members, 1); + return node; + } + function tsEnumMember(id, initializer = null) { + const node = { + type: "TSEnumMember", + id, + initializer + }; + const defs = NODE_FIELDS.TSEnumMember; + validate(defs.id, node, "id", id, 1); + validate(defs.initializer, node, "initializer", initializer, 1); + return node; + } + function tsModuleDeclaration(id, body) { + const node = { + type: "TSModuleDeclaration", + id, + body, + kind: null + }; + const defs = NODE_FIELDS.TSModuleDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function tsModuleBlock(body) { + const node = { + type: "TSModuleBlock", + body + }; + const defs = NODE_FIELDS.TSModuleBlock; + validate(defs.body, node, "body", body, 1); + return node; + } + function tsImportType(argument, qualifier = null, typeParameters = null) { + const node = { + type: "TSImportType", + argument, + qualifier, + typeParameters + }; + const defs = NODE_FIELDS.TSImportType; + validate(defs.argument, node, "argument", argument, 1); + validate(defs.qualifier, node, "qualifier", qualifier, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsImportEqualsDeclaration(id, moduleReference) { + const node = { + type: "TSImportEqualsDeclaration", + id, + moduleReference, + isExport: null + }; + const defs = NODE_FIELDS.TSImportEqualsDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.moduleReference, node, "moduleReference", moduleReference, 1); + return node; + } + function tsExternalModuleReference(expression) { + const node = { + type: "TSExternalModuleReference", + expression + }; + const defs = NODE_FIELDS.TSExternalModuleReference; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsNonNullExpression(expression) { + const node = { + type: "TSNonNullExpression", + expression + }; + const defs = NODE_FIELDS.TSNonNullExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsExportAssignment(expression) { + const node = { + type: "TSExportAssignment", + expression + }; + const defs = NODE_FIELDS.TSExportAssignment; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsNamespaceExportDeclaration(id) { + const node = { + type: "TSNamespaceExportDeclaration", + id + }; + const defs = NODE_FIELDS.TSNamespaceExportDeclaration; + validate(defs.id, node, "id", id, 1); + return node; + } + function tsTypeAnnotation(typeAnnotation) { + const node = { + type: "TSTypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.TSTypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeParameterInstantiation(params) { + const node = { + type: "TSTypeParameterInstantiation", + params + }; + const defs = NODE_FIELDS.TSTypeParameterInstantiation; + validate(defs.params, node, "params", params, 1); + return node; + } + function tsTypeParameterDeclaration(params) { + const node = { + type: "TSTypeParameterDeclaration", + params + }; + const defs = NODE_FIELDS.TSTypeParameterDeclaration; + validate(defs.params, node, "params", params, 1); + return node; + } + function tsTypeParameter(constraint = null, _default = null, name) { + const node = { + type: "TSTypeParameter", + constraint, + default: _default, + name + }; + const defs = NODE_FIELDS.TSTypeParameter; + validate(defs.constraint, node, "constraint", constraint, 1); + validate(defs.default, node, "default", _default, 1); + validate(defs.name, node, "name", name); + return node; + } + function NumberLiteral(value) { + (0, _deprecationWarning.default)("NumberLiteral", "NumericLiteral", "The node type "); + return numericLiteral(value); + } + function RegexLiteral(pattern, flags = "") { + (0, _deprecationWarning.default)("RegexLiteral", "RegExpLiteral", "The node type "); + return regExpLiteral(pattern, flags); + } + function RestProperty(argument) { + (0, _deprecationWarning.default)("RestProperty", "RestElement", "The node type "); + return restElement(argument); + } + function SpreadProperty(argument) { + (0, _deprecationWarning.default)("SpreadProperty", "SpreadElement", "The node type "); + return spreadElement(argument); + } + + + return generated$2; +} + +var hasRequiredCleanJSXElementLiteralChild; + +function requireCleanJSXElementLiteralChild () { + if (hasRequiredCleanJSXElementLiteralChild) return cleanJSXElementLiteralChild; + hasRequiredCleanJSXElementLiteralChild = 1; + + Object.defineProperty(cleanJSXElementLiteralChild, "__esModule", { + value: true + }); + cleanJSXElementLiteralChild.default = cleanJSXElementLiteralChild$1; + var _index = requireGenerated$2(); + var _index2 = requireLib$1(); + function cleanJSXElementLiteralChild$1(child, args) { + const lines = child.value.split(/\r\n|\n|\r/); + let lastNonEmptyLine = 0; + for (let i = 0; i < lines.length; i++) { + if (/[^ \t]/.exec(lines[i])) { + lastNonEmptyLine = i; + } + } + let str = ""; + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + const isFirstLine = i === 0; + const isLastLine = i === lines.length - 1; + const isLastNonEmptyLine = i === lastNonEmptyLine; + let trimmedLine = line.replace(/\t/g, " "); + if (!isFirstLine) { + trimmedLine = trimmedLine.replace(/^ +/, ""); + } + if (!isLastLine) { + trimmedLine = trimmedLine.replace(/ +$/, ""); + } + if (trimmedLine) { + if (!isLastNonEmptyLine) { + trimmedLine += " "; + } + str += trimmedLine; + } + } + if (str) args.push((0, _index2.inherits)((0, _index.stringLiteral)(str), child)); + } + + + return cleanJSXElementLiteralChild; +} + +var hasRequiredBuildChildren; + +function requireBuildChildren () { + if (hasRequiredBuildChildren) return buildChildren; + hasRequiredBuildChildren = 1; + + Object.defineProperty(buildChildren, "__esModule", { + value: true + }); + buildChildren.default = buildChildren$1; + var _index = requireGenerated$3(); + var _cleanJSXElementLiteralChild = requireCleanJSXElementLiteralChild(); + function buildChildren$1(node) { + const elements = []; + for (let i = 0; i < node.children.length; i++) { + let child = node.children[i]; + if ((0, _index.isJSXText)(child)) { + (0, _cleanJSXElementLiteralChild.default)(child, elements); + continue; + } + if ((0, _index.isJSXExpressionContainer)(child)) child = child.expression; + if ((0, _index.isJSXEmptyExpression)(child)) continue; + elements.push(child); + } + return elements; + } + + + return buildChildren; +} + +var assertNode = {}; + +var isNode = {}; + +var hasRequiredIsNode; + +function requireIsNode () { + if (hasRequiredIsNode) return isNode; + hasRequiredIsNode = 1; + + Object.defineProperty(isNode, "__esModule", { + value: true + }); + isNode.default = isNode$1; + var _index = requireDefinitions(); + function isNode$1(node) { + return !!(node && _index.VISITOR_KEYS[node.type]); + } + + + return isNode; +} + +var hasRequiredAssertNode; + +function requireAssertNode () { + if (hasRequiredAssertNode) return assertNode; + hasRequiredAssertNode = 1; + + Object.defineProperty(assertNode, "__esModule", { + value: true + }); + assertNode.default = assertNode$1; + var _isNode = requireIsNode(); + function assertNode$1(node) { + if (!(0, _isNode.default)(node)) { + var _node$type; + const type = (_node$type = node == null ? void 0 : node.type) != null ? _node$type : JSON.stringify(node); + throw new TypeError(`Not a valid node of type "${type}"`); + } + } + + + return assertNode; +} + +var generated$1 = {}; + +var hasRequiredGenerated$1; + +function requireGenerated$1 () { + if (hasRequiredGenerated$1) return generated$1; + hasRequiredGenerated$1 = 1; + + Object.defineProperty(generated$1, "__esModule", { + value: true + }); + generated$1.assertAccessor = assertAccessor; + generated$1.assertAnyTypeAnnotation = assertAnyTypeAnnotation; + generated$1.assertArgumentPlaceholder = assertArgumentPlaceholder; + generated$1.assertArrayExpression = assertArrayExpression; + generated$1.assertArrayPattern = assertArrayPattern; + generated$1.assertArrayTypeAnnotation = assertArrayTypeAnnotation; + generated$1.assertArrowFunctionExpression = assertArrowFunctionExpression; + generated$1.assertAssignmentExpression = assertAssignmentExpression; + generated$1.assertAssignmentPattern = assertAssignmentPattern; + generated$1.assertAwaitExpression = assertAwaitExpression; + generated$1.assertBigIntLiteral = assertBigIntLiteral; + generated$1.assertBinary = assertBinary; + generated$1.assertBinaryExpression = assertBinaryExpression; + generated$1.assertBindExpression = assertBindExpression; + generated$1.assertBlock = assertBlock; + generated$1.assertBlockParent = assertBlockParent; + generated$1.assertBlockStatement = assertBlockStatement; + generated$1.assertBooleanLiteral = assertBooleanLiteral; + generated$1.assertBooleanLiteralTypeAnnotation = assertBooleanLiteralTypeAnnotation; + generated$1.assertBooleanTypeAnnotation = assertBooleanTypeAnnotation; + generated$1.assertBreakStatement = assertBreakStatement; + generated$1.assertCallExpression = assertCallExpression; + generated$1.assertCatchClause = assertCatchClause; + generated$1.assertClass = assertClass; + generated$1.assertClassAccessorProperty = assertClassAccessorProperty; + generated$1.assertClassBody = assertClassBody; + generated$1.assertClassDeclaration = assertClassDeclaration; + generated$1.assertClassExpression = assertClassExpression; + generated$1.assertClassImplements = assertClassImplements; + generated$1.assertClassMethod = assertClassMethod; + generated$1.assertClassPrivateMethod = assertClassPrivateMethod; + generated$1.assertClassPrivateProperty = assertClassPrivateProperty; + generated$1.assertClassProperty = assertClassProperty; + generated$1.assertCompletionStatement = assertCompletionStatement; + generated$1.assertConditional = assertConditional; + generated$1.assertConditionalExpression = assertConditionalExpression; + generated$1.assertContinueStatement = assertContinueStatement; + generated$1.assertDebuggerStatement = assertDebuggerStatement; + generated$1.assertDecimalLiteral = assertDecimalLiteral; + generated$1.assertDeclaration = assertDeclaration; + generated$1.assertDeclareClass = assertDeclareClass; + generated$1.assertDeclareExportAllDeclaration = assertDeclareExportAllDeclaration; + generated$1.assertDeclareExportDeclaration = assertDeclareExportDeclaration; + generated$1.assertDeclareFunction = assertDeclareFunction; + generated$1.assertDeclareInterface = assertDeclareInterface; + generated$1.assertDeclareModule = assertDeclareModule; + generated$1.assertDeclareModuleExports = assertDeclareModuleExports; + generated$1.assertDeclareOpaqueType = assertDeclareOpaqueType; + generated$1.assertDeclareTypeAlias = assertDeclareTypeAlias; + generated$1.assertDeclareVariable = assertDeclareVariable; + generated$1.assertDeclaredPredicate = assertDeclaredPredicate; + generated$1.assertDecorator = assertDecorator; + generated$1.assertDirective = assertDirective; + generated$1.assertDirectiveLiteral = assertDirectiveLiteral; + generated$1.assertDoExpression = assertDoExpression; + generated$1.assertDoWhileStatement = assertDoWhileStatement; + generated$1.assertEmptyStatement = assertEmptyStatement; + generated$1.assertEmptyTypeAnnotation = assertEmptyTypeAnnotation; + generated$1.assertEnumBody = assertEnumBody; + generated$1.assertEnumBooleanBody = assertEnumBooleanBody; + generated$1.assertEnumBooleanMember = assertEnumBooleanMember; + generated$1.assertEnumDeclaration = assertEnumDeclaration; + generated$1.assertEnumDefaultedMember = assertEnumDefaultedMember; + generated$1.assertEnumMember = assertEnumMember; + generated$1.assertEnumNumberBody = assertEnumNumberBody; + generated$1.assertEnumNumberMember = assertEnumNumberMember; + generated$1.assertEnumStringBody = assertEnumStringBody; + generated$1.assertEnumStringMember = assertEnumStringMember; + generated$1.assertEnumSymbolBody = assertEnumSymbolBody; + generated$1.assertExistsTypeAnnotation = assertExistsTypeAnnotation; + generated$1.assertExportAllDeclaration = assertExportAllDeclaration; + generated$1.assertExportDeclaration = assertExportDeclaration; + generated$1.assertExportDefaultDeclaration = assertExportDefaultDeclaration; + generated$1.assertExportDefaultSpecifier = assertExportDefaultSpecifier; + generated$1.assertExportNamedDeclaration = assertExportNamedDeclaration; + generated$1.assertExportNamespaceSpecifier = assertExportNamespaceSpecifier; + generated$1.assertExportSpecifier = assertExportSpecifier; + generated$1.assertExpression = assertExpression; + generated$1.assertExpressionStatement = assertExpressionStatement; + generated$1.assertExpressionWrapper = assertExpressionWrapper; + generated$1.assertFile = assertFile; + generated$1.assertFlow = assertFlow; + generated$1.assertFlowBaseAnnotation = assertFlowBaseAnnotation; + generated$1.assertFlowDeclaration = assertFlowDeclaration; + generated$1.assertFlowPredicate = assertFlowPredicate; + generated$1.assertFlowType = assertFlowType; + generated$1.assertFor = assertFor; + generated$1.assertForInStatement = assertForInStatement; + generated$1.assertForOfStatement = assertForOfStatement; + generated$1.assertForStatement = assertForStatement; + generated$1.assertForXStatement = assertForXStatement; + generated$1.assertFunction = assertFunction; + generated$1.assertFunctionDeclaration = assertFunctionDeclaration; + generated$1.assertFunctionExpression = assertFunctionExpression; + generated$1.assertFunctionParent = assertFunctionParent; + generated$1.assertFunctionTypeAnnotation = assertFunctionTypeAnnotation; + generated$1.assertFunctionTypeParam = assertFunctionTypeParam; + generated$1.assertGenericTypeAnnotation = assertGenericTypeAnnotation; + generated$1.assertIdentifier = assertIdentifier; + generated$1.assertIfStatement = assertIfStatement; + generated$1.assertImmutable = assertImmutable; + generated$1.assertImport = assertImport; + generated$1.assertImportAttribute = assertImportAttribute; + generated$1.assertImportDeclaration = assertImportDeclaration; + generated$1.assertImportDefaultSpecifier = assertImportDefaultSpecifier; + generated$1.assertImportExpression = assertImportExpression; + generated$1.assertImportNamespaceSpecifier = assertImportNamespaceSpecifier; + generated$1.assertImportOrExportDeclaration = assertImportOrExportDeclaration; + generated$1.assertImportSpecifier = assertImportSpecifier; + generated$1.assertIndexedAccessType = assertIndexedAccessType; + generated$1.assertInferredPredicate = assertInferredPredicate; + generated$1.assertInterfaceDeclaration = assertInterfaceDeclaration; + generated$1.assertInterfaceExtends = assertInterfaceExtends; + generated$1.assertInterfaceTypeAnnotation = assertInterfaceTypeAnnotation; + generated$1.assertInterpreterDirective = assertInterpreterDirective; + generated$1.assertIntersectionTypeAnnotation = assertIntersectionTypeAnnotation; + generated$1.assertJSX = assertJSX; + generated$1.assertJSXAttribute = assertJSXAttribute; + generated$1.assertJSXClosingElement = assertJSXClosingElement; + generated$1.assertJSXClosingFragment = assertJSXClosingFragment; + generated$1.assertJSXElement = assertJSXElement; + generated$1.assertJSXEmptyExpression = assertJSXEmptyExpression; + generated$1.assertJSXExpressionContainer = assertJSXExpressionContainer; + generated$1.assertJSXFragment = assertJSXFragment; + generated$1.assertJSXIdentifier = assertJSXIdentifier; + generated$1.assertJSXMemberExpression = assertJSXMemberExpression; + generated$1.assertJSXNamespacedName = assertJSXNamespacedName; + generated$1.assertJSXOpeningElement = assertJSXOpeningElement; + generated$1.assertJSXOpeningFragment = assertJSXOpeningFragment; + generated$1.assertJSXSpreadAttribute = assertJSXSpreadAttribute; + generated$1.assertJSXSpreadChild = assertJSXSpreadChild; + generated$1.assertJSXText = assertJSXText; + generated$1.assertLVal = assertLVal; + generated$1.assertLabeledStatement = assertLabeledStatement; + generated$1.assertLiteral = assertLiteral; + generated$1.assertLogicalExpression = assertLogicalExpression; + generated$1.assertLoop = assertLoop; + generated$1.assertMemberExpression = assertMemberExpression; + generated$1.assertMetaProperty = assertMetaProperty; + generated$1.assertMethod = assertMethod; + generated$1.assertMiscellaneous = assertMiscellaneous; + generated$1.assertMixedTypeAnnotation = assertMixedTypeAnnotation; + generated$1.assertModuleDeclaration = assertModuleDeclaration; + generated$1.assertModuleExpression = assertModuleExpression; + generated$1.assertModuleSpecifier = assertModuleSpecifier; + generated$1.assertNewExpression = assertNewExpression; + generated$1.assertNoop = assertNoop; + generated$1.assertNullLiteral = assertNullLiteral; + generated$1.assertNullLiteralTypeAnnotation = assertNullLiteralTypeAnnotation; + generated$1.assertNullableTypeAnnotation = assertNullableTypeAnnotation; + generated$1.assertNumberLiteral = assertNumberLiteral; + generated$1.assertNumberLiteralTypeAnnotation = assertNumberLiteralTypeAnnotation; + generated$1.assertNumberTypeAnnotation = assertNumberTypeAnnotation; + generated$1.assertNumericLiteral = assertNumericLiteral; + generated$1.assertObjectExpression = assertObjectExpression; + generated$1.assertObjectMember = assertObjectMember; + generated$1.assertObjectMethod = assertObjectMethod; + generated$1.assertObjectPattern = assertObjectPattern; + generated$1.assertObjectProperty = assertObjectProperty; + generated$1.assertObjectTypeAnnotation = assertObjectTypeAnnotation; + generated$1.assertObjectTypeCallProperty = assertObjectTypeCallProperty; + generated$1.assertObjectTypeIndexer = assertObjectTypeIndexer; + generated$1.assertObjectTypeInternalSlot = assertObjectTypeInternalSlot; + generated$1.assertObjectTypeProperty = assertObjectTypeProperty; + generated$1.assertObjectTypeSpreadProperty = assertObjectTypeSpreadProperty; + generated$1.assertOpaqueType = assertOpaqueType; + generated$1.assertOptionalCallExpression = assertOptionalCallExpression; + generated$1.assertOptionalIndexedAccessType = assertOptionalIndexedAccessType; + generated$1.assertOptionalMemberExpression = assertOptionalMemberExpression; + generated$1.assertParenthesizedExpression = assertParenthesizedExpression; + generated$1.assertPattern = assertPattern; + generated$1.assertPatternLike = assertPatternLike; + generated$1.assertPipelineBareFunction = assertPipelineBareFunction; + generated$1.assertPipelinePrimaryTopicReference = assertPipelinePrimaryTopicReference; + generated$1.assertPipelineTopicExpression = assertPipelineTopicExpression; + generated$1.assertPlaceholder = assertPlaceholder; + generated$1.assertPrivate = assertPrivate; + generated$1.assertPrivateName = assertPrivateName; + generated$1.assertProgram = assertProgram; + generated$1.assertProperty = assertProperty; + generated$1.assertPureish = assertPureish; + generated$1.assertQualifiedTypeIdentifier = assertQualifiedTypeIdentifier; + generated$1.assertRecordExpression = assertRecordExpression; + generated$1.assertRegExpLiteral = assertRegExpLiteral; + generated$1.assertRegexLiteral = assertRegexLiteral; + generated$1.assertRestElement = assertRestElement; + generated$1.assertRestProperty = assertRestProperty; + generated$1.assertReturnStatement = assertReturnStatement; + generated$1.assertScopable = assertScopable; + generated$1.assertSequenceExpression = assertSequenceExpression; + generated$1.assertSpreadElement = assertSpreadElement; + generated$1.assertSpreadProperty = assertSpreadProperty; + generated$1.assertStandardized = assertStandardized; + generated$1.assertStatement = assertStatement; + generated$1.assertStaticBlock = assertStaticBlock; + generated$1.assertStringLiteral = assertStringLiteral; + generated$1.assertStringLiteralTypeAnnotation = assertStringLiteralTypeAnnotation; + generated$1.assertStringTypeAnnotation = assertStringTypeAnnotation; + generated$1.assertSuper = assertSuper; + generated$1.assertSwitchCase = assertSwitchCase; + generated$1.assertSwitchStatement = assertSwitchStatement; + generated$1.assertSymbolTypeAnnotation = assertSymbolTypeAnnotation; + generated$1.assertTSAnyKeyword = assertTSAnyKeyword; + generated$1.assertTSArrayType = assertTSArrayType; + generated$1.assertTSAsExpression = assertTSAsExpression; + generated$1.assertTSBaseType = assertTSBaseType; + generated$1.assertTSBigIntKeyword = assertTSBigIntKeyword; + generated$1.assertTSBooleanKeyword = assertTSBooleanKeyword; + generated$1.assertTSCallSignatureDeclaration = assertTSCallSignatureDeclaration; + generated$1.assertTSConditionalType = assertTSConditionalType; + generated$1.assertTSConstructSignatureDeclaration = assertTSConstructSignatureDeclaration; + generated$1.assertTSConstructorType = assertTSConstructorType; + generated$1.assertTSDeclareFunction = assertTSDeclareFunction; + generated$1.assertTSDeclareMethod = assertTSDeclareMethod; + generated$1.assertTSEntityName = assertTSEntityName; + generated$1.assertTSEnumDeclaration = assertTSEnumDeclaration; + generated$1.assertTSEnumMember = assertTSEnumMember; + generated$1.assertTSExportAssignment = assertTSExportAssignment; + generated$1.assertTSExpressionWithTypeArguments = assertTSExpressionWithTypeArguments; + generated$1.assertTSExternalModuleReference = assertTSExternalModuleReference; + generated$1.assertTSFunctionType = assertTSFunctionType; + generated$1.assertTSImportEqualsDeclaration = assertTSImportEqualsDeclaration; + generated$1.assertTSImportType = assertTSImportType; + generated$1.assertTSIndexSignature = assertTSIndexSignature; + generated$1.assertTSIndexedAccessType = assertTSIndexedAccessType; + generated$1.assertTSInferType = assertTSInferType; + generated$1.assertTSInstantiationExpression = assertTSInstantiationExpression; + generated$1.assertTSInterfaceBody = assertTSInterfaceBody; + generated$1.assertTSInterfaceDeclaration = assertTSInterfaceDeclaration; + generated$1.assertTSIntersectionType = assertTSIntersectionType; + generated$1.assertTSIntrinsicKeyword = assertTSIntrinsicKeyword; + generated$1.assertTSLiteralType = assertTSLiteralType; + generated$1.assertTSMappedType = assertTSMappedType; + generated$1.assertTSMethodSignature = assertTSMethodSignature; + generated$1.assertTSModuleBlock = assertTSModuleBlock; + generated$1.assertTSModuleDeclaration = assertTSModuleDeclaration; + generated$1.assertTSNamedTupleMember = assertTSNamedTupleMember; + generated$1.assertTSNamespaceExportDeclaration = assertTSNamespaceExportDeclaration; + generated$1.assertTSNeverKeyword = assertTSNeverKeyword; + generated$1.assertTSNonNullExpression = assertTSNonNullExpression; + generated$1.assertTSNullKeyword = assertTSNullKeyword; + generated$1.assertTSNumberKeyword = assertTSNumberKeyword; + generated$1.assertTSObjectKeyword = assertTSObjectKeyword; + generated$1.assertTSOptionalType = assertTSOptionalType; + generated$1.assertTSParameterProperty = assertTSParameterProperty; + generated$1.assertTSParenthesizedType = assertTSParenthesizedType; + generated$1.assertTSPropertySignature = assertTSPropertySignature; + generated$1.assertTSQualifiedName = assertTSQualifiedName; + generated$1.assertTSRestType = assertTSRestType; + generated$1.assertTSSatisfiesExpression = assertTSSatisfiesExpression; + generated$1.assertTSStringKeyword = assertTSStringKeyword; + generated$1.assertTSSymbolKeyword = assertTSSymbolKeyword; + generated$1.assertTSThisType = assertTSThisType; + generated$1.assertTSTupleType = assertTSTupleType; + generated$1.assertTSType = assertTSType; + generated$1.assertTSTypeAliasDeclaration = assertTSTypeAliasDeclaration; + generated$1.assertTSTypeAnnotation = assertTSTypeAnnotation; + generated$1.assertTSTypeAssertion = assertTSTypeAssertion; + generated$1.assertTSTypeElement = assertTSTypeElement; + generated$1.assertTSTypeLiteral = assertTSTypeLiteral; + generated$1.assertTSTypeOperator = assertTSTypeOperator; + generated$1.assertTSTypeParameter = assertTSTypeParameter; + generated$1.assertTSTypeParameterDeclaration = assertTSTypeParameterDeclaration; + generated$1.assertTSTypeParameterInstantiation = assertTSTypeParameterInstantiation; + generated$1.assertTSTypePredicate = assertTSTypePredicate; + generated$1.assertTSTypeQuery = assertTSTypeQuery; + generated$1.assertTSTypeReference = assertTSTypeReference; + generated$1.assertTSUndefinedKeyword = assertTSUndefinedKeyword; + generated$1.assertTSUnionType = assertTSUnionType; + generated$1.assertTSUnknownKeyword = assertTSUnknownKeyword; + generated$1.assertTSVoidKeyword = assertTSVoidKeyword; + generated$1.assertTaggedTemplateExpression = assertTaggedTemplateExpression; + generated$1.assertTemplateElement = assertTemplateElement; + generated$1.assertTemplateLiteral = assertTemplateLiteral; + generated$1.assertTerminatorless = assertTerminatorless; + generated$1.assertThisExpression = assertThisExpression; + generated$1.assertThisTypeAnnotation = assertThisTypeAnnotation; + generated$1.assertThrowStatement = assertThrowStatement; + generated$1.assertTopicReference = assertTopicReference; + generated$1.assertTryStatement = assertTryStatement; + generated$1.assertTupleExpression = assertTupleExpression; + generated$1.assertTupleTypeAnnotation = assertTupleTypeAnnotation; + generated$1.assertTypeAlias = assertTypeAlias; + generated$1.assertTypeAnnotation = assertTypeAnnotation; + generated$1.assertTypeCastExpression = assertTypeCastExpression; + generated$1.assertTypeParameter = assertTypeParameter; + generated$1.assertTypeParameterDeclaration = assertTypeParameterDeclaration; + generated$1.assertTypeParameterInstantiation = assertTypeParameterInstantiation; + generated$1.assertTypeScript = assertTypeScript; + generated$1.assertTypeofTypeAnnotation = assertTypeofTypeAnnotation; + generated$1.assertUnaryExpression = assertUnaryExpression; + generated$1.assertUnaryLike = assertUnaryLike; + generated$1.assertUnionTypeAnnotation = assertUnionTypeAnnotation; + generated$1.assertUpdateExpression = assertUpdateExpression; + generated$1.assertUserWhitespacable = assertUserWhitespacable; + generated$1.assertV8IntrinsicIdentifier = assertV8IntrinsicIdentifier; + generated$1.assertVariableDeclaration = assertVariableDeclaration; + generated$1.assertVariableDeclarator = assertVariableDeclarator; + generated$1.assertVariance = assertVariance; + generated$1.assertVoidTypeAnnotation = assertVoidTypeAnnotation; + generated$1.assertWhile = assertWhile; + generated$1.assertWhileStatement = assertWhileStatement; + generated$1.assertWithStatement = assertWithStatement; + generated$1.assertYieldExpression = assertYieldExpression; + var _is = requireIs(); + var _deprecationWarning = requireDeprecationWarning(); + function assert(type, node, opts) { + if (!(0, _is.default)(type, node, opts)) { + throw new Error(`Expected type "${type}" with option ${JSON.stringify(opts)}, ` + `but instead got "${node.type}".`); + } + } + function assertArrayExpression(node, opts) { + assert("ArrayExpression", node, opts); + } + function assertAssignmentExpression(node, opts) { + assert("AssignmentExpression", node, opts); + } + function assertBinaryExpression(node, opts) { + assert("BinaryExpression", node, opts); + } + function assertInterpreterDirective(node, opts) { + assert("InterpreterDirective", node, opts); + } + function assertDirective(node, opts) { + assert("Directive", node, opts); + } + function assertDirectiveLiteral(node, opts) { + assert("DirectiveLiteral", node, opts); + } + function assertBlockStatement(node, opts) { + assert("BlockStatement", node, opts); + } + function assertBreakStatement(node, opts) { + assert("BreakStatement", node, opts); + } + function assertCallExpression(node, opts) { + assert("CallExpression", node, opts); + } + function assertCatchClause(node, opts) { + assert("CatchClause", node, opts); + } + function assertConditionalExpression(node, opts) { + assert("ConditionalExpression", node, opts); + } + function assertContinueStatement(node, opts) { + assert("ContinueStatement", node, opts); + } + function assertDebuggerStatement(node, opts) { + assert("DebuggerStatement", node, opts); + } + function assertDoWhileStatement(node, opts) { + assert("DoWhileStatement", node, opts); + } + function assertEmptyStatement(node, opts) { + assert("EmptyStatement", node, opts); + } + function assertExpressionStatement(node, opts) { + assert("ExpressionStatement", node, opts); + } + function assertFile(node, opts) { + assert("File", node, opts); + } + function assertForInStatement(node, opts) { + assert("ForInStatement", node, opts); + } + function assertForStatement(node, opts) { + assert("ForStatement", node, opts); + } + function assertFunctionDeclaration(node, opts) { + assert("FunctionDeclaration", node, opts); + } + function assertFunctionExpression(node, opts) { + assert("FunctionExpression", node, opts); + } + function assertIdentifier(node, opts) { + assert("Identifier", node, opts); + } + function assertIfStatement(node, opts) { + assert("IfStatement", node, opts); + } + function assertLabeledStatement(node, opts) { + assert("LabeledStatement", node, opts); + } + function assertStringLiteral(node, opts) { + assert("StringLiteral", node, opts); + } + function assertNumericLiteral(node, opts) { + assert("NumericLiteral", node, opts); + } + function assertNullLiteral(node, opts) { + assert("NullLiteral", node, opts); + } + function assertBooleanLiteral(node, opts) { + assert("BooleanLiteral", node, opts); + } + function assertRegExpLiteral(node, opts) { + assert("RegExpLiteral", node, opts); + } + function assertLogicalExpression(node, opts) { + assert("LogicalExpression", node, opts); + } + function assertMemberExpression(node, opts) { + assert("MemberExpression", node, opts); + } + function assertNewExpression(node, opts) { + assert("NewExpression", node, opts); + } + function assertProgram(node, opts) { + assert("Program", node, opts); + } + function assertObjectExpression(node, opts) { + assert("ObjectExpression", node, opts); + } + function assertObjectMethod(node, opts) { + assert("ObjectMethod", node, opts); + } + function assertObjectProperty(node, opts) { + assert("ObjectProperty", node, opts); + } + function assertRestElement(node, opts) { + assert("RestElement", node, opts); + } + function assertReturnStatement(node, opts) { + assert("ReturnStatement", node, opts); + } + function assertSequenceExpression(node, opts) { + assert("SequenceExpression", node, opts); + } + function assertParenthesizedExpression(node, opts) { + assert("ParenthesizedExpression", node, opts); + } + function assertSwitchCase(node, opts) { + assert("SwitchCase", node, opts); + } + function assertSwitchStatement(node, opts) { + assert("SwitchStatement", node, opts); + } + function assertThisExpression(node, opts) { + assert("ThisExpression", node, opts); + } + function assertThrowStatement(node, opts) { + assert("ThrowStatement", node, opts); + } + function assertTryStatement(node, opts) { + assert("TryStatement", node, opts); + } + function assertUnaryExpression(node, opts) { + assert("UnaryExpression", node, opts); + } + function assertUpdateExpression(node, opts) { + assert("UpdateExpression", node, opts); + } + function assertVariableDeclaration(node, opts) { + assert("VariableDeclaration", node, opts); + } + function assertVariableDeclarator(node, opts) { + assert("VariableDeclarator", node, opts); + } + function assertWhileStatement(node, opts) { + assert("WhileStatement", node, opts); + } + function assertWithStatement(node, opts) { + assert("WithStatement", node, opts); + } + function assertAssignmentPattern(node, opts) { + assert("AssignmentPattern", node, opts); + } + function assertArrayPattern(node, opts) { + assert("ArrayPattern", node, opts); + } + function assertArrowFunctionExpression(node, opts) { + assert("ArrowFunctionExpression", node, opts); + } + function assertClassBody(node, opts) { + assert("ClassBody", node, opts); + } + function assertClassExpression(node, opts) { + assert("ClassExpression", node, opts); + } + function assertClassDeclaration(node, opts) { + assert("ClassDeclaration", node, opts); + } + function assertExportAllDeclaration(node, opts) { + assert("ExportAllDeclaration", node, opts); + } + function assertExportDefaultDeclaration(node, opts) { + assert("ExportDefaultDeclaration", node, opts); + } + function assertExportNamedDeclaration(node, opts) { + assert("ExportNamedDeclaration", node, opts); + } + function assertExportSpecifier(node, opts) { + assert("ExportSpecifier", node, opts); + } + function assertForOfStatement(node, opts) { + assert("ForOfStatement", node, opts); + } + function assertImportDeclaration(node, opts) { + assert("ImportDeclaration", node, opts); + } + function assertImportDefaultSpecifier(node, opts) { + assert("ImportDefaultSpecifier", node, opts); + } + function assertImportNamespaceSpecifier(node, opts) { + assert("ImportNamespaceSpecifier", node, opts); + } + function assertImportSpecifier(node, opts) { + assert("ImportSpecifier", node, opts); + } + function assertImportExpression(node, opts) { + assert("ImportExpression", node, opts); + } + function assertMetaProperty(node, opts) { + assert("MetaProperty", node, opts); + } + function assertClassMethod(node, opts) { + assert("ClassMethod", node, opts); + } + function assertObjectPattern(node, opts) { + assert("ObjectPattern", node, opts); + } + function assertSpreadElement(node, opts) { + assert("SpreadElement", node, opts); + } + function assertSuper(node, opts) { + assert("Super", node, opts); + } + function assertTaggedTemplateExpression(node, opts) { + assert("TaggedTemplateExpression", node, opts); + } + function assertTemplateElement(node, opts) { + assert("TemplateElement", node, opts); + } + function assertTemplateLiteral(node, opts) { + assert("TemplateLiteral", node, opts); + } + function assertYieldExpression(node, opts) { + assert("YieldExpression", node, opts); + } + function assertAwaitExpression(node, opts) { + assert("AwaitExpression", node, opts); + } + function assertImport(node, opts) { + assert("Import", node, opts); + } + function assertBigIntLiteral(node, opts) { + assert("BigIntLiteral", node, opts); + } + function assertExportNamespaceSpecifier(node, opts) { + assert("ExportNamespaceSpecifier", node, opts); + } + function assertOptionalMemberExpression(node, opts) { + assert("OptionalMemberExpression", node, opts); + } + function assertOptionalCallExpression(node, opts) { + assert("OptionalCallExpression", node, opts); + } + function assertClassProperty(node, opts) { + assert("ClassProperty", node, opts); + } + function assertClassAccessorProperty(node, opts) { + assert("ClassAccessorProperty", node, opts); + } + function assertClassPrivateProperty(node, opts) { + assert("ClassPrivateProperty", node, opts); + } + function assertClassPrivateMethod(node, opts) { + assert("ClassPrivateMethod", node, opts); + } + function assertPrivateName(node, opts) { + assert("PrivateName", node, opts); + } + function assertStaticBlock(node, opts) { + assert("StaticBlock", node, opts); + } + function assertAnyTypeAnnotation(node, opts) { + assert("AnyTypeAnnotation", node, opts); + } + function assertArrayTypeAnnotation(node, opts) { + assert("ArrayTypeAnnotation", node, opts); + } + function assertBooleanTypeAnnotation(node, opts) { + assert("BooleanTypeAnnotation", node, opts); + } + function assertBooleanLiteralTypeAnnotation(node, opts) { + assert("BooleanLiteralTypeAnnotation", node, opts); + } + function assertNullLiteralTypeAnnotation(node, opts) { + assert("NullLiteralTypeAnnotation", node, opts); + } + function assertClassImplements(node, opts) { + assert("ClassImplements", node, opts); + } + function assertDeclareClass(node, opts) { + assert("DeclareClass", node, opts); + } + function assertDeclareFunction(node, opts) { + assert("DeclareFunction", node, opts); + } + function assertDeclareInterface(node, opts) { + assert("DeclareInterface", node, opts); + } + function assertDeclareModule(node, opts) { + assert("DeclareModule", node, opts); + } + function assertDeclareModuleExports(node, opts) { + assert("DeclareModuleExports", node, opts); + } + function assertDeclareTypeAlias(node, opts) { + assert("DeclareTypeAlias", node, opts); + } + function assertDeclareOpaqueType(node, opts) { + assert("DeclareOpaqueType", node, opts); + } + function assertDeclareVariable(node, opts) { + assert("DeclareVariable", node, opts); + } + function assertDeclareExportDeclaration(node, opts) { + assert("DeclareExportDeclaration", node, opts); + } + function assertDeclareExportAllDeclaration(node, opts) { + assert("DeclareExportAllDeclaration", node, opts); + } + function assertDeclaredPredicate(node, opts) { + assert("DeclaredPredicate", node, opts); + } + function assertExistsTypeAnnotation(node, opts) { + assert("ExistsTypeAnnotation", node, opts); + } + function assertFunctionTypeAnnotation(node, opts) { + assert("FunctionTypeAnnotation", node, opts); + } + function assertFunctionTypeParam(node, opts) { + assert("FunctionTypeParam", node, opts); + } + function assertGenericTypeAnnotation(node, opts) { + assert("GenericTypeAnnotation", node, opts); + } + function assertInferredPredicate(node, opts) { + assert("InferredPredicate", node, opts); + } + function assertInterfaceExtends(node, opts) { + assert("InterfaceExtends", node, opts); + } + function assertInterfaceDeclaration(node, opts) { + assert("InterfaceDeclaration", node, opts); + } + function assertInterfaceTypeAnnotation(node, opts) { + assert("InterfaceTypeAnnotation", node, opts); + } + function assertIntersectionTypeAnnotation(node, opts) { + assert("IntersectionTypeAnnotation", node, opts); + } + function assertMixedTypeAnnotation(node, opts) { + assert("MixedTypeAnnotation", node, opts); + } + function assertEmptyTypeAnnotation(node, opts) { + assert("EmptyTypeAnnotation", node, opts); + } + function assertNullableTypeAnnotation(node, opts) { + assert("NullableTypeAnnotation", node, opts); + } + function assertNumberLiteralTypeAnnotation(node, opts) { + assert("NumberLiteralTypeAnnotation", node, opts); + } + function assertNumberTypeAnnotation(node, opts) { + assert("NumberTypeAnnotation", node, opts); + } + function assertObjectTypeAnnotation(node, opts) { + assert("ObjectTypeAnnotation", node, opts); + } + function assertObjectTypeInternalSlot(node, opts) { + assert("ObjectTypeInternalSlot", node, opts); + } + function assertObjectTypeCallProperty(node, opts) { + assert("ObjectTypeCallProperty", node, opts); + } + function assertObjectTypeIndexer(node, opts) { + assert("ObjectTypeIndexer", node, opts); + } + function assertObjectTypeProperty(node, opts) { + assert("ObjectTypeProperty", node, opts); + } + function assertObjectTypeSpreadProperty(node, opts) { + assert("ObjectTypeSpreadProperty", node, opts); + } + function assertOpaqueType(node, opts) { + assert("OpaqueType", node, opts); + } + function assertQualifiedTypeIdentifier(node, opts) { + assert("QualifiedTypeIdentifier", node, opts); + } + function assertStringLiteralTypeAnnotation(node, opts) { + assert("StringLiteralTypeAnnotation", node, opts); + } + function assertStringTypeAnnotation(node, opts) { + assert("StringTypeAnnotation", node, opts); + } + function assertSymbolTypeAnnotation(node, opts) { + assert("SymbolTypeAnnotation", node, opts); + } + function assertThisTypeAnnotation(node, opts) { + assert("ThisTypeAnnotation", node, opts); + } + function assertTupleTypeAnnotation(node, opts) { + assert("TupleTypeAnnotation", node, opts); + } + function assertTypeofTypeAnnotation(node, opts) { + assert("TypeofTypeAnnotation", node, opts); + } + function assertTypeAlias(node, opts) { + assert("TypeAlias", node, opts); + } + function assertTypeAnnotation(node, opts) { + assert("TypeAnnotation", node, opts); + } + function assertTypeCastExpression(node, opts) { + assert("TypeCastExpression", node, opts); + } + function assertTypeParameter(node, opts) { + assert("TypeParameter", node, opts); + } + function assertTypeParameterDeclaration(node, opts) { + assert("TypeParameterDeclaration", node, opts); + } + function assertTypeParameterInstantiation(node, opts) { + assert("TypeParameterInstantiation", node, opts); + } + function assertUnionTypeAnnotation(node, opts) { + assert("UnionTypeAnnotation", node, opts); + } + function assertVariance(node, opts) { + assert("Variance", node, opts); + } + function assertVoidTypeAnnotation(node, opts) { + assert("VoidTypeAnnotation", node, opts); + } + function assertEnumDeclaration(node, opts) { + assert("EnumDeclaration", node, opts); + } + function assertEnumBooleanBody(node, opts) { + assert("EnumBooleanBody", node, opts); + } + function assertEnumNumberBody(node, opts) { + assert("EnumNumberBody", node, opts); + } + function assertEnumStringBody(node, opts) { + assert("EnumStringBody", node, opts); + } + function assertEnumSymbolBody(node, opts) { + assert("EnumSymbolBody", node, opts); + } + function assertEnumBooleanMember(node, opts) { + assert("EnumBooleanMember", node, opts); + } + function assertEnumNumberMember(node, opts) { + assert("EnumNumberMember", node, opts); + } + function assertEnumStringMember(node, opts) { + assert("EnumStringMember", node, opts); + } + function assertEnumDefaultedMember(node, opts) { + assert("EnumDefaultedMember", node, opts); + } + function assertIndexedAccessType(node, opts) { + assert("IndexedAccessType", node, opts); + } + function assertOptionalIndexedAccessType(node, opts) { + assert("OptionalIndexedAccessType", node, opts); + } + function assertJSXAttribute(node, opts) { + assert("JSXAttribute", node, opts); + } + function assertJSXClosingElement(node, opts) { + assert("JSXClosingElement", node, opts); + } + function assertJSXElement(node, opts) { + assert("JSXElement", node, opts); + } + function assertJSXEmptyExpression(node, opts) { + assert("JSXEmptyExpression", node, opts); + } + function assertJSXExpressionContainer(node, opts) { + assert("JSXExpressionContainer", node, opts); + } + function assertJSXSpreadChild(node, opts) { + assert("JSXSpreadChild", node, opts); + } + function assertJSXIdentifier(node, opts) { + assert("JSXIdentifier", node, opts); + } + function assertJSXMemberExpression(node, opts) { + assert("JSXMemberExpression", node, opts); + } + function assertJSXNamespacedName(node, opts) { + assert("JSXNamespacedName", node, opts); + } + function assertJSXOpeningElement(node, opts) { + assert("JSXOpeningElement", node, opts); + } + function assertJSXSpreadAttribute(node, opts) { + assert("JSXSpreadAttribute", node, opts); + } + function assertJSXText(node, opts) { + assert("JSXText", node, opts); + } + function assertJSXFragment(node, opts) { + assert("JSXFragment", node, opts); + } + function assertJSXOpeningFragment(node, opts) { + assert("JSXOpeningFragment", node, opts); + } + function assertJSXClosingFragment(node, opts) { + assert("JSXClosingFragment", node, opts); + } + function assertNoop(node, opts) { + assert("Noop", node, opts); + } + function assertPlaceholder(node, opts) { + assert("Placeholder", node, opts); + } + function assertV8IntrinsicIdentifier(node, opts) { + assert("V8IntrinsicIdentifier", node, opts); + } + function assertArgumentPlaceholder(node, opts) { + assert("ArgumentPlaceholder", node, opts); + } + function assertBindExpression(node, opts) { + assert("BindExpression", node, opts); + } + function assertImportAttribute(node, opts) { + assert("ImportAttribute", node, opts); + } + function assertDecorator(node, opts) { + assert("Decorator", node, opts); + } + function assertDoExpression(node, opts) { + assert("DoExpression", node, opts); + } + function assertExportDefaultSpecifier(node, opts) { + assert("ExportDefaultSpecifier", node, opts); + } + function assertRecordExpression(node, opts) { + assert("RecordExpression", node, opts); + } + function assertTupleExpression(node, opts) { + assert("TupleExpression", node, opts); + } + function assertDecimalLiteral(node, opts) { + assert("DecimalLiteral", node, opts); + } + function assertModuleExpression(node, opts) { + assert("ModuleExpression", node, opts); + } + function assertTopicReference(node, opts) { + assert("TopicReference", node, opts); + } + function assertPipelineTopicExpression(node, opts) { + assert("PipelineTopicExpression", node, opts); + } + function assertPipelineBareFunction(node, opts) { + assert("PipelineBareFunction", node, opts); + } + function assertPipelinePrimaryTopicReference(node, opts) { + assert("PipelinePrimaryTopicReference", node, opts); + } + function assertTSParameterProperty(node, opts) { + assert("TSParameterProperty", node, opts); + } + function assertTSDeclareFunction(node, opts) { + assert("TSDeclareFunction", node, opts); + } + function assertTSDeclareMethod(node, opts) { + assert("TSDeclareMethod", node, opts); + } + function assertTSQualifiedName(node, opts) { + assert("TSQualifiedName", node, opts); + } + function assertTSCallSignatureDeclaration(node, opts) { + assert("TSCallSignatureDeclaration", node, opts); + } + function assertTSConstructSignatureDeclaration(node, opts) { + assert("TSConstructSignatureDeclaration", node, opts); + } + function assertTSPropertySignature(node, opts) { + assert("TSPropertySignature", node, opts); + } + function assertTSMethodSignature(node, opts) { + assert("TSMethodSignature", node, opts); + } + function assertTSIndexSignature(node, opts) { + assert("TSIndexSignature", node, opts); + } + function assertTSAnyKeyword(node, opts) { + assert("TSAnyKeyword", node, opts); + } + function assertTSBooleanKeyword(node, opts) { + assert("TSBooleanKeyword", node, opts); + } + function assertTSBigIntKeyword(node, opts) { + assert("TSBigIntKeyword", node, opts); + } + function assertTSIntrinsicKeyword(node, opts) { + assert("TSIntrinsicKeyword", node, opts); + } + function assertTSNeverKeyword(node, opts) { + assert("TSNeverKeyword", node, opts); + } + function assertTSNullKeyword(node, opts) { + assert("TSNullKeyword", node, opts); + } + function assertTSNumberKeyword(node, opts) { + assert("TSNumberKeyword", node, opts); + } + function assertTSObjectKeyword(node, opts) { + assert("TSObjectKeyword", node, opts); + } + function assertTSStringKeyword(node, opts) { + assert("TSStringKeyword", node, opts); + } + function assertTSSymbolKeyword(node, opts) { + assert("TSSymbolKeyword", node, opts); + } + function assertTSUndefinedKeyword(node, opts) { + assert("TSUndefinedKeyword", node, opts); + } + function assertTSUnknownKeyword(node, opts) { + assert("TSUnknownKeyword", node, opts); + } + function assertTSVoidKeyword(node, opts) { + assert("TSVoidKeyword", node, opts); + } + function assertTSThisType(node, opts) { + assert("TSThisType", node, opts); + } + function assertTSFunctionType(node, opts) { + assert("TSFunctionType", node, opts); + } + function assertTSConstructorType(node, opts) { + assert("TSConstructorType", node, opts); + } + function assertTSTypeReference(node, opts) { + assert("TSTypeReference", node, opts); + } + function assertTSTypePredicate(node, opts) { + assert("TSTypePredicate", node, opts); + } + function assertTSTypeQuery(node, opts) { + assert("TSTypeQuery", node, opts); + } + function assertTSTypeLiteral(node, opts) { + assert("TSTypeLiteral", node, opts); + } + function assertTSArrayType(node, opts) { + assert("TSArrayType", node, opts); + } + function assertTSTupleType(node, opts) { + assert("TSTupleType", node, opts); + } + function assertTSOptionalType(node, opts) { + assert("TSOptionalType", node, opts); + } + function assertTSRestType(node, opts) { + assert("TSRestType", node, opts); + } + function assertTSNamedTupleMember(node, opts) { + assert("TSNamedTupleMember", node, opts); + } + function assertTSUnionType(node, opts) { + assert("TSUnionType", node, opts); + } + function assertTSIntersectionType(node, opts) { + assert("TSIntersectionType", node, opts); + } + function assertTSConditionalType(node, opts) { + assert("TSConditionalType", node, opts); + } + function assertTSInferType(node, opts) { + assert("TSInferType", node, opts); + } + function assertTSParenthesizedType(node, opts) { + assert("TSParenthesizedType", node, opts); + } + function assertTSTypeOperator(node, opts) { + assert("TSTypeOperator", node, opts); + } + function assertTSIndexedAccessType(node, opts) { + assert("TSIndexedAccessType", node, opts); + } + function assertTSMappedType(node, opts) { + assert("TSMappedType", node, opts); + } + function assertTSLiteralType(node, opts) { + assert("TSLiteralType", node, opts); + } + function assertTSExpressionWithTypeArguments(node, opts) { + assert("TSExpressionWithTypeArguments", node, opts); + } + function assertTSInterfaceDeclaration(node, opts) { + assert("TSInterfaceDeclaration", node, opts); + } + function assertTSInterfaceBody(node, opts) { + assert("TSInterfaceBody", node, opts); + } + function assertTSTypeAliasDeclaration(node, opts) { + assert("TSTypeAliasDeclaration", node, opts); + } + function assertTSInstantiationExpression(node, opts) { + assert("TSInstantiationExpression", node, opts); + } + function assertTSAsExpression(node, opts) { + assert("TSAsExpression", node, opts); + } + function assertTSSatisfiesExpression(node, opts) { + assert("TSSatisfiesExpression", node, opts); + } + function assertTSTypeAssertion(node, opts) { + assert("TSTypeAssertion", node, opts); + } + function assertTSEnumDeclaration(node, opts) { + assert("TSEnumDeclaration", node, opts); + } + function assertTSEnumMember(node, opts) { + assert("TSEnumMember", node, opts); + } + function assertTSModuleDeclaration(node, opts) { + assert("TSModuleDeclaration", node, opts); + } + function assertTSModuleBlock(node, opts) { + assert("TSModuleBlock", node, opts); + } + function assertTSImportType(node, opts) { + assert("TSImportType", node, opts); + } + function assertTSImportEqualsDeclaration(node, opts) { + assert("TSImportEqualsDeclaration", node, opts); + } + function assertTSExternalModuleReference(node, opts) { + assert("TSExternalModuleReference", node, opts); + } + function assertTSNonNullExpression(node, opts) { + assert("TSNonNullExpression", node, opts); + } + function assertTSExportAssignment(node, opts) { + assert("TSExportAssignment", node, opts); + } + function assertTSNamespaceExportDeclaration(node, opts) { + assert("TSNamespaceExportDeclaration", node, opts); + } + function assertTSTypeAnnotation(node, opts) { + assert("TSTypeAnnotation", node, opts); + } + function assertTSTypeParameterInstantiation(node, opts) { + assert("TSTypeParameterInstantiation", node, opts); + } + function assertTSTypeParameterDeclaration(node, opts) { + assert("TSTypeParameterDeclaration", node, opts); + } + function assertTSTypeParameter(node, opts) { + assert("TSTypeParameter", node, opts); + } + function assertStandardized(node, opts) { + assert("Standardized", node, opts); + } + function assertExpression(node, opts) { + assert("Expression", node, opts); + } + function assertBinary(node, opts) { + assert("Binary", node, opts); + } + function assertScopable(node, opts) { + assert("Scopable", node, opts); + } + function assertBlockParent(node, opts) { + assert("BlockParent", node, opts); + } + function assertBlock(node, opts) { + assert("Block", node, opts); + } + function assertStatement(node, opts) { + assert("Statement", node, opts); + } + function assertTerminatorless(node, opts) { + assert("Terminatorless", node, opts); + } + function assertCompletionStatement(node, opts) { + assert("CompletionStatement", node, opts); + } + function assertConditional(node, opts) { + assert("Conditional", node, opts); + } + function assertLoop(node, opts) { + assert("Loop", node, opts); + } + function assertWhile(node, opts) { + assert("While", node, opts); + } + function assertExpressionWrapper(node, opts) { + assert("ExpressionWrapper", node, opts); + } + function assertFor(node, opts) { + assert("For", node, opts); + } + function assertForXStatement(node, opts) { + assert("ForXStatement", node, opts); + } + function assertFunction(node, opts) { + assert("Function", node, opts); + } + function assertFunctionParent(node, opts) { + assert("FunctionParent", node, opts); + } + function assertPureish(node, opts) { + assert("Pureish", node, opts); + } + function assertDeclaration(node, opts) { + assert("Declaration", node, opts); + } + function assertPatternLike(node, opts) { + assert("PatternLike", node, opts); + } + function assertLVal(node, opts) { + assert("LVal", node, opts); + } + function assertTSEntityName(node, opts) { + assert("TSEntityName", node, opts); + } + function assertLiteral(node, opts) { + assert("Literal", node, opts); + } + function assertImmutable(node, opts) { + assert("Immutable", node, opts); + } + function assertUserWhitespacable(node, opts) { + assert("UserWhitespacable", node, opts); + } + function assertMethod(node, opts) { + assert("Method", node, opts); + } + function assertObjectMember(node, opts) { + assert("ObjectMember", node, opts); + } + function assertProperty(node, opts) { + assert("Property", node, opts); + } + function assertUnaryLike(node, opts) { + assert("UnaryLike", node, opts); + } + function assertPattern(node, opts) { + assert("Pattern", node, opts); + } + function assertClass(node, opts) { + assert("Class", node, opts); + } + function assertImportOrExportDeclaration(node, opts) { + assert("ImportOrExportDeclaration", node, opts); + } + function assertExportDeclaration(node, opts) { + assert("ExportDeclaration", node, opts); + } + function assertModuleSpecifier(node, opts) { + assert("ModuleSpecifier", node, opts); + } + function assertAccessor(node, opts) { + assert("Accessor", node, opts); + } + function assertPrivate(node, opts) { + assert("Private", node, opts); + } + function assertFlow(node, opts) { + assert("Flow", node, opts); + } + function assertFlowType(node, opts) { + assert("FlowType", node, opts); + } + function assertFlowBaseAnnotation(node, opts) { + assert("FlowBaseAnnotation", node, opts); + } + function assertFlowDeclaration(node, opts) { + assert("FlowDeclaration", node, opts); + } + function assertFlowPredicate(node, opts) { + assert("FlowPredicate", node, opts); + } + function assertEnumBody(node, opts) { + assert("EnumBody", node, opts); + } + function assertEnumMember(node, opts) { + assert("EnumMember", node, opts); + } + function assertJSX(node, opts) { + assert("JSX", node, opts); + } + function assertMiscellaneous(node, opts) { + assert("Miscellaneous", node, opts); + } + function assertTypeScript(node, opts) { + assert("TypeScript", node, opts); + } + function assertTSTypeElement(node, opts) { + assert("TSTypeElement", node, opts); + } + function assertTSType(node, opts) { + assert("TSType", node, opts); + } + function assertTSBaseType(node, opts) { + assert("TSBaseType", node, opts); + } + function assertNumberLiteral(node, opts) { + (0, _deprecationWarning.default)("assertNumberLiteral", "assertNumericLiteral"); + assert("NumberLiteral", node, opts); + } + function assertRegexLiteral(node, opts) { + (0, _deprecationWarning.default)("assertRegexLiteral", "assertRegExpLiteral"); + assert("RegexLiteral", node, opts); + } + function assertRestProperty(node, opts) { + (0, _deprecationWarning.default)("assertRestProperty", "assertRestElement"); + assert("RestProperty", node, opts); + } + function assertSpreadProperty(node, opts) { + (0, _deprecationWarning.default)("assertSpreadProperty", "assertSpreadElement"); + assert("SpreadProperty", node, opts); + } + function assertModuleDeclaration(node, opts) { + (0, _deprecationWarning.default)("assertModuleDeclaration", "assertImportOrExportDeclaration"); + assert("ModuleDeclaration", node, opts); + } + + + return generated$1; +} + +var createTypeAnnotationBasedOnTypeof = {}; + +var hasRequiredCreateTypeAnnotationBasedOnTypeof; + +function requireCreateTypeAnnotationBasedOnTypeof () { + if (hasRequiredCreateTypeAnnotationBasedOnTypeof) return createTypeAnnotationBasedOnTypeof; + hasRequiredCreateTypeAnnotationBasedOnTypeof = 1; + + Object.defineProperty(createTypeAnnotationBasedOnTypeof, "__esModule", { + value: true + }); + createTypeAnnotationBasedOnTypeof.default = void 0; + var _index = requireGenerated$2(); + createTypeAnnotationBasedOnTypeof.default = createTypeAnnotationBasedOnTypeof$1; + function createTypeAnnotationBasedOnTypeof$1(type) { + switch (type) { + case "string": + return (0, _index.stringTypeAnnotation)(); + case "number": + return (0, _index.numberTypeAnnotation)(); + case "undefined": + return (0, _index.voidTypeAnnotation)(); + case "boolean": + return (0, _index.booleanTypeAnnotation)(); + case "function": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Function")); + case "object": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Object")); + case "symbol": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Symbol")); + case "bigint": + return (0, _index.anyTypeAnnotation)(); + } + throw new Error("Invalid typeof value: " + type); + } + + + return createTypeAnnotationBasedOnTypeof; +} + +var createFlowUnionType = {}; + +var removeTypeDuplicates$1 = {}; + +var hasRequiredRemoveTypeDuplicates$1; + +function requireRemoveTypeDuplicates$1 () { + if (hasRequiredRemoveTypeDuplicates$1) return removeTypeDuplicates$1; + hasRequiredRemoveTypeDuplicates$1 = 1; + + Object.defineProperty(removeTypeDuplicates$1, "__esModule", { + value: true + }); + removeTypeDuplicates$1.default = removeTypeDuplicates; + var _index = requireGenerated$3(); + function getQualifiedName(node) { + return (0, _index.isIdentifier)(node) ? node.name : `${node.id.name}.${getQualifiedName(node.qualification)}`; + } + function removeTypeDuplicates(nodesIn) { + const nodes = Array.from(nodesIn); + const generics = new Map(); + const bases = new Map(); + const typeGroups = new Set(); + const types = []; + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + if (!node) continue; + if (types.includes(node)) { + continue; + } + if ((0, _index.isAnyTypeAnnotation)(node)) { + return [node]; + } + if ((0, _index.isFlowBaseAnnotation)(node)) { + bases.set(node.type, node); + continue; + } + if ((0, _index.isUnionTypeAnnotation)(node)) { + if (!typeGroups.has(node.types)) { + nodes.push(...node.types); + typeGroups.add(node.types); + } + continue; + } + if ((0, _index.isGenericTypeAnnotation)(node)) { + const name = getQualifiedName(node.id); + if (generics.has(name)) { + let existing = generics.get(name); + if (existing.typeParameters) { + if (node.typeParameters) { + existing.typeParameters.params.push(...node.typeParameters.params); + existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params); + } + } else { + existing = node.typeParameters; + } + } else { + generics.set(name, node); + } + continue; + } + types.push(node); + } + for (const [, baseType] of bases) { + types.push(baseType); + } + for (const [, genericName] of generics) { + types.push(genericName); + } + return types; + } + + + return removeTypeDuplicates$1; +} + +var hasRequiredCreateFlowUnionType; + +function requireCreateFlowUnionType () { + if (hasRequiredCreateFlowUnionType) return createFlowUnionType; + hasRequiredCreateFlowUnionType = 1; + + Object.defineProperty(createFlowUnionType, "__esModule", { + value: true + }); + createFlowUnionType.default = createFlowUnionType$1; + var _index = requireGenerated$2(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates$1(); + function createFlowUnionType$1(types) { + const flattened = (0, _removeTypeDuplicates.default)(types); + if (flattened.length === 1) { + return flattened[0]; + } else { + return (0, _index.unionTypeAnnotation)(flattened); + } + } + + + return createFlowUnionType; +} + +var createTSUnionType = {}; + +var removeTypeDuplicates = {}; + +var hasRequiredRemoveTypeDuplicates; + +function requireRemoveTypeDuplicates () { + if (hasRequiredRemoveTypeDuplicates) return removeTypeDuplicates; + hasRequiredRemoveTypeDuplicates = 1; + + Object.defineProperty(removeTypeDuplicates, "__esModule", { + value: true + }); + removeTypeDuplicates.default = removeTypeDuplicates$1; + var _index = requireGenerated$3(); + function getQualifiedName(node) { + return (0, _index.isIdentifier)(node) ? node.name : `${node.right.name}.${getQualifiedName(node.left)}`; + } + function removeTypeDuplicates$1(nodesIn) { + const nodes = Array.from(nodesIn); + const generics = new Map(); + const bases = new Map(); + const typeGroups = new Set(); + const types = []; + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + if (!node) continue; + if (types.includes(node)) { + continue; + } + if ((0, _index.isTSAnyKeyword)(node)) { + return [node]; + } + if ((0, _index.isTSBaseType)(node)) { + bases.set(node.type, node); + continue; + } + if ((0, _index.isTSUnionType)(node)) { + if (!typeGroups.has(node.types)) { + nodes.push(...node.types); + typeGroups.add(node.types); + } + continue; + } + if ((0, _index.isTSTypeReference)(node) && node.typeParameters) { + const name = getQualifiedName(node.typeName); + if (generics.has(name)) { + let existing = generics.get(name); + if (existing.typeParameters) { + if (node.typeParameters) { + existing.typeParameters.params.push(...node.typeParameters.params); + existing.typeParameters.params = removeTypeDuplicates$1(existing.typeParameters.params); + } + } else { + existing = node.typeParameters; + } + } else { + generics.set(name, node); + } + continue; + } + types.push(node); + } + for (const [, baseType] of bases) { + types.push(baseType); + } + for (const [, genericName] of generics) { + types.push(genericName); + } + return types; + } + + + return removeTypeDuplicates; +} + +var hasRequiredCreateTSUnionType; + +function requireCreateTSUnionType () { + if (hasRequiredCreateTSUnionType) return createTSUnionType; + hasRequiredCreateTSUnionType = 1; + + Object.defineProperty(createTSUnionType, "__esModule", { + value: true + }); + createTSUnionType.default = createTSUnionType$1; + var _index = requireGenerated$2(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates(); + var _index2 = requireGenerated$3(); + function createTSUnionType$1(typeAnnotations) { + const types = typeAnnotations.map(type => { + return (0, _index2.isTSTypeAnnotation)(type) ? type.typeAnnotation : type; + }); + const flattened = (0, _removeTypeDuplicates.default)(types); + if (flattened.length === 1) { + return flattened[0]; + } else { + return (0, _index.tsUnionType)(flattened); + } + } + + + return createTSUnionType; +} + +var uppercase = {}; + +var hasRequiredUppercase; + +function requireUppercase () { + if (hasRequiredUppercase) return uppercase; + hasRequiredUppercase = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "AnyTypeAnnotation", { + enumerable: true, + get: function () { + return _index.anyTypeAnnotation; + } + }); + Object.defineProperty(exports, "ArgumentPlaceholder", { + enumerable: true, + get: function () { + return _index.argumentPlaceholder; + } + }); + Object.defineProperty(exports, "ArrayExpression", { + enumerable: true, + get: function () { + return _index.arrayExpression; + } + }); + Object.defineProperty(exports, "ArrayPattern", { + enumerable: true, + get: function () { + return _index.arrayPattern; + } + }); + Object.defineProperty(exports, "ArrayTypeAnnotation", { + enumerable: true, + get: function () { + return _index.arrayTypeAnnotation; + } + }); + Object.defineProperty(exports, "ArrowFunctionExpression", { + enumerable: true, + get: function () { + return _index.arrowFunctionExpression; + } + }); + Object.defineProperty(exports, "AssignmentExpression", { + enumerable: true, + get: function () { + return _index.assignmentExpression; + } + }); + Object.defineProperty(exports, "AssignmentPattern", { + enumerable: true, + get: function () { + return _index.assignmentPattern; + } + }); + Object.defineProperty(exports, "AwaitExpression", { + enumerable: true, + get: function () { + return _index.awaitExpression; + } + }); + Object.defineProperty(exports, "BigIntLiteral", { + enumerable: true, + get: function () { + return _index.bigIntLiteral; + } + }); + Object.defineProperty(exports, "BinaryExpression", { + enumerable: true, + get: function () { + return _index.binaryExpression; + } + }); + Object.defineProperty(exports, "BindExpression", { + enumerable: true, + get: function () { + return _index.bindExpression; + } + }); + Object.defineProperty(exports, "BlockStatement", { + enumerable: true, + get: function () { + return _index.blockStatement; + } + }); + Object.defineProperty(exports, "BooleanLiteral", { + enumerable: true, + get: function () { + return _index.booleanLiteral; + } + }); + Object.defineProperty(exports, "BooleanLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.booleanLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "BooleanTypeAnnotation", { + enumerable: true, + get: function () { + return _index.booleanTypeAnnotation; + } + }); + Object.defineProperty(exports, "BreakStatement", { + enumerable: true, + get: function () { + return _index.breakStatement; + } + }); + Object.defineProperty(exports, "CallExpression", { + enumerable: true, + get: function () { + return _index.callExpression; + } + }); + Object.defineProperty(exports, "CatchClause", { + enumerable: true, + get: function () { + return _index.catchClause; + } + }); + Object.defineProperty(exports, "ClassAccessorProperty", { + enumerable: true, + get: function () { + return _index.classAccessorProperty; + } + }); + Object.defineProperty(exports, "ClassBody", { + enumerable: true, + get: function () { + return _index.classBody; + } + }); + Object.defineProperty(exports, "ClassDeclaration", { + enumerable: true, + get: function () { + return _index.classDeclaration; + } + }); + Object.defineProperty(exports, "ClassExpression", { + enumerable: true, + get: function () { + return _index.classExpression; + } + }); + Object.defineProperty(exports, "ClassImplements", { + enumerable: true, + get: function () { + return _index.classImplements; + } + }); + Object.defineProperty(exports, "ClassMethod", { + enumerable: true, + get: function () { + return _index.classMethod; + } + }); + Object.defineProperty(exports, "ClassPrivateMethod", { + enumerable: true, + get: function () { + return _index.classPrivateMethod; + } + }); + Object.defineProperty(exports, "ClassPrivateProperty", { + enumerable: true, + get: function () { + return _index.classPrivateProperty; + } + }); + Object.defineProperty(exports, "ClassProperty", { + enumerable: true, + get: function () { + return _index.classProperty; + } + }); + Object.defineProperty(exports, "ConditionalExpression", { + enumerable: true, + get: function () { + return _index.conditionalExpression; + } + }); + Object.defineProperty(exports, "ContinueStatement", { + enumerable: true, + get: function () { + return _index.continueStatement; + } + }); + Object.defineProperty(exports, "DebuggerStatement", { + enumerable: true, + get: function () { + return _index.debuggerStatement; + } + }); + Object.defineProperty(exports, "DecimalLiteral", { + enumerable: true, + get: function () { + return _index.decimalLiteral; + } + }); + Object.defineProperty(exports, "DeclareClass", { + enumerable: true, + get: function () { + return _index.declareClass; + } + }); + Object.defineProperty(exports, "DeclareExportAllDeclaration", { + enumerable: true, + get: function () { + return _index.declareExportAllDeclaration; + } + }); + Object.defineProperty(exports, "DeclareExportDeclaration", { + enumerable: true, + get: function () { + return _index.declareExportDeclaration; + } + }); + Object.defineProperty(exports, "DeclareFunction", { + enumerable: true, + get: function () { + return _index.declareFunction; + } + }); + Object.defineProperty(exports, "DeclareInterface", { + enumerable: true, + get: function () { + return _index.declareInterface; + } + }); + Object.defineProperty(exports, "DeclareModule", { + enumerable: true, + get: function () { + return _index.declareModule; + } + }); + Object.defineProperty(exports, "DeclareModuleExports", { + enumerable: true, + get: function () { + return _index.declareModuleExports; + } + }); + Object.defineProperty(exports, "DeclareOpaqueType", { + enumerable: true, + get: function () { + return _index.declareOpaqueType; + } + }); + Object.defineProperty(exports, "DeclareTypeAlias", { + enumerable: true, + get: function () { + return _index.declareTypeAlias; + } + }); + Object.defineProperty(exports, "DeclareVariable", { + enumerable: true, + get: function () { + return _index.declareVariable; + } + }); + Object.defineProperty(exports, "DeclaredPredicate", { + enumerable: true, + get: function () { + return _index.declaredPredicate; + } + }); + Object.defineProperty(exports, "Decorator", { + enumerable: true, + get: function () { + return _index.decorator; + } + }); + Object.defineProperty(exports, "Directive", { + enumerable: true, + get: function () { + return _index.directive; + } + }); + Object.defineProperty(exports, "DirectiveLiteral", { + enumerable: true, + get: function () { + return _index.directiveLiteral; + } + }); + Object.defineProperty(exports, "DoExpression", { + enumerable: true, + get: function () { + return _index.doExpression; + } + }); + Object.defineProperty(exports, "DoWhileStatement", { + enumerable: true, + get: function () { + return _index.doWhileStatement; + } + }); + Object.defineProperty(exports, "EmptyStatement", { + enumerable: true, + get: function () { + return _index.emptyStatement; + } + }); + Object.defineProperty(exports, "EmptyTypeAnnotation", { + enumerable: true, + get: function () { + return _index.emptyTypeAnnotation; + } + }); + Object.defineProperty(exports, "EnumBooleanBody", { + enumerable: true, + get: function () { + return _index.enumBooleanBody; + } + }); + Object.defineProperty(exports, "EnumBooleanMember", { + enumerable: true, + get: function () { + return _index.enumBooleanMember; + } + }); + Object.defineProperty(exports, "EnumDeclaration", { + enumerable: true, + get: function () { + return _index.enumDeclaration; + } + }); + Object.defineProperty(exports, "EnumDefaultedMember", { + enumerable: true, + get: function () { + return _index.enumDefaultedMember; + } + }); + Object.defineProperty(exports, "EnumNumberBody", { + enumerable: true, + get: function () { + return _index.enumNumberBody; + } + }); + Object.defineProperty(exports, "EnumNumberMember", { + enumerable: true, + get: function () { + return _index.enumNumberMember; + } + }); + Object.defineProperty(exports, "EnumStringBody", { + enumerable: true, + get: function () { + return _index.enumStringBody; + } + }); + Object.defineProperty(exports, "EnumStringMember", { + enumerable: true, + get: function () { + return _index.enumStringMember; + } + }); + Object.defineProperty(exports, "EnumSymbolBody", { + enumerable: true, + get: function () { + return _index.enumSymbolBody; + } + }); + Object.defineProperty(exports, "ExistsTypeAnnotation", { + enumerable: true, + get: function () { + return _index.existsTypeAnnotation; + } + }); + Object.defineProperty(exports, "ExportAllDeclaration", { + enumerable: true, + get: function () { + return _index.exportAllDeclaration; + } + }); + Object.defineProperty(exports, "ExportDefaultDeclaration", { + enumerable: true, + get: function () { + return _index.exportDefaultDeclaration; + } + }); + Object.defineProperty(exports, "ExportDefaultSpecifier", { + enumerable: true, + get: function () { + return _index.exportDefaultSpecifier; + } + }); + Object.defineProperty(exports, "ExportNamedDeclaration", { + enumerable: true, + get: function () { + return _index.exportNamedDeclaration; + } + }); + Object.defineProperty(exports, "ExportNamespaceSpecifier", { + enumerable: true, + get: function () { + return _index.exportNamespaceSpecifier; + } + }); + Object.defineProperty(exports, "ExportSpecifier", { + enumerable: true, + get: function () { + return _index.exportSpecifier; + } + }); + Object.defineProperty(exports, "ExpressionStatement", { + enumerable: true, + get: function () { + return _index.expressionStatement; + } + }); + Object.defineProperty(exports, "File", { + enumerable: true, + get: function () { + return _index.file; + } + }); + Object.defineProperty(exports, "ForInStatement", { + enumerable: true, + get: function () { + return _index.forInStatement; + } + }); + Object.defineProperty(exports, "ForOfStatement", { + enumerable: true, + get: function () { + return _index.forOfStatement; + } + }); + Object.defineProperty(exports, "ForStatement", { + enumerable: true, + get: function () { + return _index.forStatement; + } + }); + Object.defineProperty(exports, "FunctionDeclaration", { + enumerable: true, + get: function () { + return _index.functionDeclaration; + } + }); + Object.defineProperty(exports, "FunctionExpression", { + enumerable: true, + get: function () { + return _index.functionExpression; + } + }); + Object.defineProperty(exports, "FunctionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.functionTypeAnnotation; + } + }); + Object.defineProperty(exports, "FunctionTypeParam", { + enumerable: true, + get: function () { + return _index.functionTypeParam; + } + }); + Object.defineProperty(exports, "GenericTypeAnnotation", { + enumerable: true, + get: function () { + return _index.genericTypeAnnotation; + } + }); + Object.defineProperty(exports, "Identifier", { + enumerable: true, + get: function () { + return _index.identifier; + } + }); + Object.defineProperty(exports, "IfStatement", { + enumerable: true, + get: function () { + return _index.ifStatement; + } + }); + Object.defineProperty(exports, "Import", { + enumerable: true, + get: function () { + return _index.import; + } + }); + Object.defineProperty(exports, "ImportAttribute", { + enumerable: true, + get: function () { + return _index.importAttribute; + } + }); + Object.defineProperty(exports, "ImportDeclaration", { + enumerable: true, + get: function () { + return _index.importDeclaration; + } + }); + Object.defineProperty(exports, "ImportDefaultSpecifier", { + enumerable: true, + get: function () { + return _index.importDefaultSpecifier; + } + }); + Object.defineProperty(exports, "ImportExpression", { + enumerable: true, + get: function () { + return _index.importExpression; + } + }); + Object.defineProperty(exports, "ImportNamespaceSpecifier", { + enumerable: true, + get: function () { + return _index.importNamespaceSpecifier; + } + }); + Object.defineProperty(exports, "ImportSpecifier", { + enumerable: true, + get: function () { + return _index.importSpecifier; + } + }); + Object.defineProperty(exports, "IndexedAccessType", { + enumerable: true, + get: function () { + return _index.indexedAccessType; + } + }); + Object.defineProperty(exports, "InferredPredicate", { + enumerable: true, + get: function () { + return _index.inferredPredicate; + } + }); + Object.defineProperty(exports, "InterfaceDeclaration", { + enumerable: true, + get: function () { + return _index.interfaceDeclaration; + } + }); + Object.defineProperty(exports, "InterfaceExtends", { + enumerable: true, + get: function () { + return _index.interfaceExtends; + } + }); + Object.defineProperty(exports, "InterfaceTypeAnnotation", { + enumerable: true, + get: function () { + return _index.interfaceTypeAnnotation; + } + }); + Object.defineProperty(exports, "InterpreterDirective", { + enumerable: true, + get: function () { + return _index.interpreterDirective; + } + }); + Object.defineProperty(exports, "IntersectionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.intersectionTypeAnnotation; + } + }); + Object.defineProperty(exports, "JSXAttribute", { + enumerable: true, + get: function () { + return _index.jsxAttribute; + } + }); + Object.defineProperty(exports, "JSXClosingElement", { + enumerable: true, + get: function () { + return _index.jsxClosingElement; + } + }); + Object.defineProperty(exports, "JSXClosingFragment", { + enumerable: true, + get: function () { + return _index.jsxClosingFragment; + } + }); + Object.defineProperty(exports, "JSXElement", { + enumerable: true, + get: function () { + return _index.jsxElement; + } + }); + Object.defineProperty(exports, "JSXEmptyExpression", { + enumerable: true, + get: function () { + return _index.jsxEmptyExpression; + } + }); + Object.defineProperty(exports, "JSXExpressionContainer", { + enumerable: true, + get: function () { + return _index.jsxExpressionContainer; + } + }); + Object.defineProperty(exports, "JSXFragment", { + enumerable: true, + get: function () { + return _index.jsxFragment; + } + }); + Object.defineProperty(exports, "JSXIdentifier", { + enumerable: true, + get: function () { + return _index.jsxIdentifier; + } + }); + Object.defineProperty(exports, "JSXMemberExpression", { + enumerable: true, + get: function () { + return _index.jsxMemberExpression; + } + }); + Object.defineProperty(exports, "JSXNamespacedName", { + enumerable: true, + get: function () { + return _index.jsxNamespacedName; + } + }); + Object.defineProperty(exports, "JSXOpeningElement", { + enumerable: true, + get: function () { + return _index.jsxOpeningElement; + } + }); + Object.defineProperty(exports, "JSXOpeningFragment", { + enumerable: true, + get: function () { + return _index.jsxOpeningFragment; + } + }); + Object.defineProperty(exports, "JSXSpreadAttribute", { + enumerable: true, + get: function () { + return _index.jsxSpreadAttribute; + } + }); + Object.defineProperty(exports, "JSXSpreadChild", { + enumerable: true, + get: function () { + return _index.jsxSpreadChild; + } + }); + Object.defineProperty(exports, "JSXText", { + enumerable: true, + get: function () { + return _index.jsxText; + } + }); + Object.defineProperty(exports, "LabeledStatement", { + enumerable: true, + get: function () { + return _index.labeledStatement; + } + }); + Object.defineProperty(exports, "LogicalExpression", { + enumerable: true, + get: function () { + return _index.logicalExpression; + } + }); + Object.defineProperty(exports, "MemberExpression", { + enumerable: true, + get: function () { + return _index.memberExpression; + } + }); + Object.defineProperty(exports, "MetaProperty", { + enumerable: true, + get: function () { + return _index.metaProperty; + } + }); + Object.defineProperty(exports, "MixedTypeAnnotation", { + enumerable: true, + get: function () { + return _index.mixedTypeAnnotation; + } + }); + Object.defineProperty(exports, "ModuleExpression", { + enumerable: true, + get: function () { + return _index.moduleExpression; + } + }); + Object.defineProperty(exports, "NewExpression", { + enumerable: true, + get: function () { + return _index.newExpression; + } + }); + Object.defineProperty(exports, "Noop", { + enumerable: true, + get: function () { + return _index.noop; + } + }); + Object.defineProperty(exports, "NullLiteral", { + enumerable: true, + get: function () { + return _index.nullLiteral; + } + }); + Object.defineProperty(exports, "NullLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.nullLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "NullableTypeAnnotation", { + enumerable: true, + get: function () { + return _index.nullableTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumberLiteral", { + enumerable: true, + get: function () { + return _index.numberLiteral; + } + }); + Object.defineProperty(exports, "NumberLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.numberLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumberTypeAnnotation", { + enumerable: true, + get: function () { + return _index.numberTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumericLiteral", { + enumerable: true, + get: function () { + return _index.numericLiteral; + } + }); + Object.defineProperty(exports, "ObjectExpression", { + enumerable: true, + get: function () { + return _index.objectExpression; + } + }); + Object.defineProperty(exports, "ObjectMethod", { + enumerable: true, + get: function () { + return _index.objectMethod; + } + }); + Object.defineProperty(exports, "ObjectPattern", { + enumerable: true, + get: function () { + return _index.objectPattern; + } + }); + Object.defineProperty(exports, "ObjectProperty", { + enumerable: true, + get: function () { + return _index.objectProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeAnnotation", { + enumerable: true, + get: function () { + return _index.objectTypeAnnotation; + } + }); + Object.defineProperty(exports, "ObjectTypeCallProperty", { + enumerable: true, + get: function () { + return _index.objectTypeCallProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeIndexer", { + enumerable: true, + get: function () { + return _index.objectTypeIndexer; + } + }); + Object.defineProperty(exports, "ObjectTypeInternalSlot", { + enumerable: true, + get: function () { + return _index.objectTypeInternalSlot; + } + }); + Object.defineProperty(exports, "ObjectTypeProperty", { + enumerable: true, + get: function () { + return _index.objectTypeProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeSpreadProperty", { + enumerable: true, + get: function () { + return _index.objectTypeSpreadProperty; + } + }); + Object.defineProperty(exports, "OpaqueType", { + enumerable: true, + get: function () { + return _index.opaqueType; + } + }); + Object.defineProperty(exports, "OptionalCallExpression", { + enumerable: true, + get: function () { + return _index.optionalCallExpression; + } + }); + Object.defineProperty(exports, "OptionalIndexedAccessType", { + enumerable: true, + get: function () { + return _index.optionalIndexedAccessType; + } + }); + Object.defineProperty(exports, "OptionalMemberExpression", { + enumerable: true, + get: function () { + return _index.optionalMemberExpression; + } + }); + Object.defineProperty(exports, "ParenthesizedExpression", { + enumerable: true, + get: function () { + return _index.parenthesizedExpression; + } + }); + Object.defineProperty(exports, "PipelineBareFunction", { + enumerable: true, + get: function () { + return _index.pipelineBareFunction; + } + }); + Object.defineProperty(exports, "PipelinePrimaryTopicReference", { + enumerable: true, + get: function () { + return _index.pipelinePrimaryTopicReference; + } + }); + Object.defineProperty(exports, "PipelineTopicExpression", { + enumerable: true, + get: function () { + return _index.pipelineTopicExpression; + } + }); + Object.defineProperty(exports, "Placeholder", { + enumerable: true, + get: function () { + return _index.placeholder; + } + }); + Object.defineProperty(exports, "PrivateName", { + enumerable: true, + get: function () { + return _index.privateName; + } + }); + Object.defineProperty(exports, "Program", { + enumerable: true, + get: function () { + return _index.program; + } + }); + Object.defineProperty(exports, "QualifiedTypeIdentifier", { + enumerable: true, + get: function () { + return _index.qualifiedTypeIdentifier; + } + }); + Object.defineProperty(exports, "RecordExpression", { + enumerable: true, + get: function () { + return _index.recordExpression; + } + }); + Object.defineProperty(exports, "RegExpLiteral", { + enumerable: true, + get: function () { + return _index.regExpLiteral; + } + }); + Object.defineProperty(exports, "RegexLiteral", { + enumerable: true, + get: function () { + return _index.regexLiteral; + } + }); + Object.defineProperty(exports, "RestElement", { + enumerable: true, + get: function () { + return _index.restElement; + } + }); + Object.defineProperty(exports, "RestProperty", { + enumerable: true, + get: function () { + return _index.restProperty; + } + }); + Object.defineProperty(exports, "ReturnStatement", { + enumerable: true, + get: function () { + return _index.returnStatement; + } + }); + Object.defineProperty(exports, "SequenceExpression", { + enumerable: true, + get: function () { + return _index.sequenceExpression; + } + }); + Object.defineProperty(exports, "SpreadElement", { + enumerable: true, + get: function () { + return _index.spreadElement; + } + }); + Object.defineProperty(exports, "SpreadProperty", { + enumerable: true, + get: function () { + return _index.spreadProperty; + } + }); + Object.defineProperty(exports, "StaticBlock", { + enumerable: true, + get: function () { + return _index.staticBlock; + } + }); + Object.defineProperty(exports, "StringLiteral", { + enumerable: true, + get: function () { + return _index.stringLiteral; + } + }); + Object.defineProperty(exports, "StringLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.stringLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "StringTypeAnnotation", { + enumerable: true, + get: function () { + return _index.stringTypeAnnotation; + } + }); + Object.defineProperty(exports, "Super", { + enumerable: true, + get: function () { + return _index.super; + } + }); + Object.defineProperty(exports, "SwitchCase", { + enumerable: true, + get: function () { + return _index.switchCase; + } + }); + Object.defineProperty(exports, "SwitchStatement", { + enumerable: true, + get: function () { + return _index.switchStatement; + } + }); + Object.defineProperty(exports, "SymbolTypeAnnotation", { + enumerable: true, + get: function () { + return _index.symbolTypeAnnotation; + } + }); + Object.defineProperty(exports, "TSAnyKeyword", { + enumerable: true, + get: function () { + return _index.tsAnyKeyword; + } + }); + Object.defineProperty(exports, "TSArrayType", { + enumerable: true, + get: function () { + return _index.tsArrayType; + } + }); + Object.defineProperty(exports, "TSAsExpression", { + enumerable: true, + get: function () { + return _index.tsAsExpression; + } + }); + Object.defineProperty(exports, "TSBigIntKeyword", { + enumerable: true, + get: function () { + return _index.tsBigIntKeyword; + } + }); + Object.defineProperty(exports, "TSBooleanKeyword", { + enumerable: true, + get: function () { + return _index.tsBooleanKeyword; + } + }); + Object.defineProperty(exports, "TSCallSignatureDeclaration", { + enumerable: true, + get: function () { + return _index.tsCallSignatureDeclaration; + } + }); + Object.defineProperty(exports, "TSConditionalType", { + enumerable: true, + get: function () { + return _index.tsConditionalType; + } + }); + Object.defineProperty(exports, "TSConstructSignatureDeclaration", { + enumerable: true, + get: function () { + return _index.tsConstructSignatureDeclaration; + } + }); + Object.defineProperty(exports, "TSConstructorType", { + enumerable: true, + get: function () { + return _index.tsConstructorType; + } + }); + Object.defineProperty(exports, "TSDeclareFunction", { + enumerable: true, + get: function () { + return _index.tsDeclareFunction; + } + }); + Object.defineProperty(exports, "TSDeclareMethod", { + enumerable: true, + get: function () { + return _index.tsDeclareMethod; + } + }); + Object.defineProperty(exports, "TSEnumDeclaration", { + enumerable: true, + get: function () { + return _index.tsEnumDeclaration; + } + }); + Object.defineProperty(exports, "TSEnumMember", { + enumerable: true, + get: function () { + return _index.tsEnumMember; + } + }); + Object.defineProperty(exports, "TSExportAssignment", { + enumerable: true, + get: function () { + return _index.tsExportAssignment; + } + }); + Object.defineProperty(exports, "TSExpressionWithTypeArguments", { + enumerable: true, + get: function () { + return _index.tsExpressionWithTypeArguments; + } + }); + Object.defineProperty(exports, "TSExternalModuleReference", { + enumerable: true, + get: function () { + return _index.tsExternalModuleReference; + } + }); + Object.defineProperty(exports, "TSFunctionType", { + enumerable: true, + get: function () { + return _index.tsFunctionType; + } + }); + Object.defineProperty(exports, "TSImportEqualsDeclaration", { + enumerable: true, + get: function () { + return _index.tsImportEqualsDeclaration; + } + }); + Object.defineProperty(exports, "TSImportType", { + enumerable: true, + get: function () { + return _index.tsImportType; + } + }); + Object.defineProperty(exports, "TSIndexSignature", { + enumerable: true, + get: function () { + return _index.tsIndexSignature; + } + }); + Object.defineProperty(exports, "TSIndexedAccessType", { + enumerable: true, + get: function () { + return _index.tsIndexedAccessType; + } + }); + Object.defineProperty(exports, "TSInferType", { + enumerable: true, + get: function () { + return _index.tsInferType; + } + }); + Object.defineProperty(exports, "TSInstantiationExpression", { + enumerable: true, + get: function () { + return _index.tsInstantiationExpression; + } + }); + Object.defineProperty(exports, "TSInterfaceBody", { + enumerable: true, + get: function () { + return _index.tsInterfaceBody; + } + }); + Object.defineProperty(exports, "TSInterfaceDeclaration", { + enumerable: true, + get: function () { + return _index.tsInterfaceDeclaration; + } + }); + Object.defineProperty(exports, "TSIntersectionType", { + enumerable: true, + get: function () { + return _index.tsIntersectionType; + } + }); + Object.defineProperty(exports, "TSIntrinsicKeyword", { + enumerable: true, + get: function () { + return _index.tsIntrinsicKeyword; + } + }); + Object.defineProperty(exports, "TSLiteralType", { + enumerable: true, + get: function () { + return _index.tsLiteralType; + } + }); + Object.defineProperty(exports, "TSMappedType", { + enumerable: true, + get: function () { + return _index.tsMappedType; + } + }); + Object.defineProperty(exports, "TSMethodSignature", { + enumerable: true, + get: function () { + return _index.tsMethodSignature; + } + }); + Object.defineProperty(exports, "TSModuleBlock", { + enumerable: true, + get: function () { + return _index.tsModuleBlock; + } + }); + Object.defineProperty(exports, "TSModuleDeclaration", { + enumerable: true, + get: function () { + return _index.tsModuleDeclaration; + } + }); + Object.defineProperty(exports, "TSNamedTupleMember", { + enumerable: true, + get: function () { + return _index.tsNamedTupleMember; + } + }); + Object.defineProperty(exports, "TSNamespaceExportDeclaration", { + enumerable: true, + get: function () { + return _index.tsNamespaceExportDeclaration; + } + }); + Object.defineProperty(exports, "TSNeverKeyword", { + enumerable: true, + get: function () { + return _index.tsNeverKeyword; + } + }); + Object.defineProperty(exports, "TSNonNullExpression", { + enumerable: true, + get: function () { + return _index.tsNonNullExpression; + } + }); + Object.defineProperty(exports, "TSNullKeyword", { + enumerable: true, + get: function () { + return _index.tsNullKeyword; + } + }); + Object.defineProperty(exports, "TSNumberKeyword", { + enumerable: true, + get: function () { + return _index.tsNumberKeyword; + } + }); + Object.defineProperty(exports, "TSObjectKeyword", { + enumerable: true, + get: function () { + return _index.tsObjectKeyword; + } + }); + Object.defineProperty(exports, "TSOptionalType", { + enumerable: true, + get: function () { + return _index.tsOptionalType; + } + }); + Object.defineProperty(exports, "TSParameterProperty", { + enumerable: true, + get: function () { + return _index.tsParameterProperty; + } + }); + Object.defineProperty(exports, "TSParenthesizedType", { + enumerable: true, + get: function () { + return _index.tsParenthesizedType; + } + }); + Object.defineProperty(exports, "TSPropertySignature", { + enumerable: true, + get: function () { + return _index.tsPropertySignature; + } + }); + Object.defineProperty(exports, "TSQualifiedName", { + enumerable: true, + get: function () { + return _index.tsQualifiedName; + } + }); + Object.defineProperty(exports, "TSRestType", { + enumerable: true, + get: function () { + return _index.tsRestType; + } + }); + Object.defineProperty(exports, "TSSatisfiesExpression", { + enumerable: true, + get: function () { + return _index.tsSatisfiesExpression; + } + }); + Object.defineProperty(exports, "TSStringKeyword", { + enumerable: true, + get: function () { + return _index.tsStringKeyword; + } + }); + Object.defineProperty(exports, "TSSymbolKeyword", { + enumerable: true, + get: function () { + return _index.tsSymbolKeyword; + } + }); + Object.defineProperty(exports, "TSThisType", { + enumerable: true, + get: function () { + return _index.tsThisType; + } + }); + Object.defineProperty(exports, "TSTupleType", { + enumerable: true, + get: function () { + return _index.tsTupleType; + } + }); + Object.defineProperty(exports, "TSTypeAliasDeclaration", { + enumerable: true, + get: function () { + return _index.tsTypeAliasDeclaration; + } + }); + Object.defineProperty(exports, "TSTypeAnnotation", { + enumerable: true, + get: function () { + return _index.tsTypeAnnotation; + } + }); + Object.defineProperty(exports, "TSTypeAssertion", { + enumerable: true, + get: function () { + return _index.tsTypeAssertion; + } + }); + Object.defineProperty(exports, "TSTypeLiteral", { + enumerable: true, + get: function () { + return _index.tsTypeLiteral; + } + }); + Object.defineProperty(exports, "TSTypeOperator", { + enumerable: true, + get: function () { + return _index.tsTypeOperator; + } + }); + Object.defineProperty(exports, "TSTypeParameter", { + enumerable: true, + get: function () { + return _index.tsTypeParameter; + } + }); + Object.defineProperty(exports, "TSTypeParameterDeclaration", { + enumerable: true, + get: function () { + return _index.tsTypeParameterDeclaration; + } + }); + Object.defineProperty(exports, "TSTypeParameterInstantiation", { + enumerable: true, + get: function () { + return _index.tsTypeParameterInstantiation; + } + }); + Object.defineProperty(exports, "TSTypePredicate", { + enumerable: true, + get: function () { + return _index.tsTypePredicate; + } + }); + Object.defineProperty(exports, "TSTypeQuery", { + enumerable: true, + get: function () { + return _index.tsTypeQuery; + } + }); + Object.defineProperty(exports, "TSTypeReference", { + enumerable: true, + get: function () { + return _index.tsTypeReference; + } + }); + Object.defineProperty(exports, "TSUndefinedKeyword", { + enumerable: true, + get: function () { + return _index.tsUndefinedKeyword; + } + }); + Object.defineProperty(exports, "TSUnionType", { + enumerable: true, + get: function () { + return _index.tsUnionType; + } + }); + Object.defineProperty(exports, "TSUnknownKeyword", { + enumerable: true, + get: function () { + return _index.tsUnknownKeyword; + } + }); + Object.defineProperty(exports, "TSVoidKeyword", { + enumerable: true, + get: function () { + return _index.tsVoidKeyword; + } + }); + Object.defineProperty(exports, "TaggedTemplateExpression", { + enumerable: true, + get: function () { + return _index.taggedTemplateExpression; + } + }); + Object.defineProperty(exports, "TemplateElement", { + enumerable: true, + get: function () { + return _index.templateElement; + } + }); + Object.defineProperty(exports, "TemplateLiteral", { + enumerable: true, + get: function () { + return _index.templateLiteral; + } + }); + Object.defineProperty(exports, "ThisExpression", { + enumerable: true, + get: function () { + return _index.thisExpression; + } + }); + Object.defineProperty(exports, "ThisTypeAnnotation", { + enumerable: true, + get: function () { + return _index.thisTypeAnnotation; + } + }); + Object.defineProperty(exports, "ThrowStatement", { + enumerable: true, + get: function () { + return _index.throwStatement; + } + }); + Object.defineProperty(exports, "TopicReference", { + enumerable: true, + get: function () { + return _index.topicReference; + } + }); + Object.defineProperty(exports, "TryStatement", { + enumerable: true, + get: function () { + return _index.tryStatement; + } + }); + Object.defineProperty(exports, "TupleExpression", { + enumerable: true, + get: function () { + return _index.tupleExpression; + } + }); + Object.defineProperty(exports, "TupleTypeAnnotation", { + enumerable: true, + get: function () { + return _index.tupleTypeAnnotation; + } + }); + Object.defineProperty(exports, "TypeAlias", { + enumerable: true, + get: function () { + return _index.typeAlias; + } + }); + Object.defineProperty(exports, "TypeAnnotation", { + enumerable: true, + get: function () { + return _index.typeAnnotation; + } + }); + Object.defineProperty(exports, "TypeCastExpression", { + enumerable: true, + get: function () { + return _index.typeCastExpression; + } + }); + Object.defineProperty(exports, "TypeParameter", { + enumerable: true, + get: function () { + return _index.typeParameter; + } + }); + Object.defineProperty(exports, "TypeParameterDeclaration", { + enumerable: true, + get: function () { + return _index.typeParameterDeclaration; + } + }); + Object.defineProperty(exports, "TypeParameterInstantiation", { + enumerable: true, + get: function () { + return _index.typeParameterInstantiation; + } + }); + Object.defineProperty(exports, "TypeofTypeAnnotation", { + enumerable: true, + get: function () { + return _index.typeofTypeAnnotation; + } + }); + Object.defineProperty(exports, "UnaryExpression", { + enumerable: true, + get: function () { + return _index.unaryExpression; + } + }); + Object.defineProperty(exports, "UnionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.unionTypeAnnotation; + } + }); + Object.defineProperty(exports, "UpdateExpression", { + enumerable: true, + get: function () { + return _index.updateExpression; + } + }); + Object.defineProperty(exports, "V8IntrinsicIdentifier", { + enumerable: true, + get: function () { + return _index.v8IntrinsicIdentifier; + } + }); + Object.defineProperty(exports, "VariableDeclaration", { + enumerable: true, + get: function () { + return _index.variableDeclaration; + } + }); + Object.defineProperty(exports, "VariableDeclarator", { + enumerable: true, + get: function () { + return _index.variableDeclarator; + } + }); + Object.defineProperty(exports, "Variance", { + enumerable: true, + get: function () { + return _index.variance; + } + }); + Object.defineProperty(exports, "VoidTypeAnnotation", { + enumerable: true, + get: function () { + return _index.voidTypeAnnotation; + } + }); + Object.defineProperty(exports, "WhileStatement", { + enumerable: true, + get: function () { + return _index.whileStatement; + } + }); + Object.defineProperty(exports, "WithStatement", { + enumerable: true, + get: function () { + return _index.withStatement; + } + }); + Object.defineProperty(exports, "YieldExpression", { + enumerable: true, + get: function () { + return _index.yieldExpression; + } + }); + var _index = requireGenerated$2(); + + +} (uppercase)); + return uppercase; +} + +var productions = {}; + +var hasRequiredProductions; + +function requireProductions () { + if (hasRequiredProductions) return productions; + hasRequiredProductions = 1; + + Object.defineProperty(productions, "__esModule", { + value: true + }); + productions.buildUndefinedNode = buildUndefinedNode; + var _index = requireGenerated$2(); + function buildUndefinedNode() { + return (0, _index.unaryExpression)("void", (0, _index.numericLiteral)(0), true); + } + + + return productions; +} + +var cloneNode = {}; + +var hasRequiredCloneNode; + +function requireCloneNode () { + if (hasRequiredCloneNode) return cloneNode; + hasRequiredCloneNode = 1; + + Object.defineProperty(cloneNode, "__esModule", { + value: true + }); + cloneNode.default = cloneNode$1; + var _index = requireDefinitions(); + var _index2 = requireGenerated$3(); + const { + hasOwn + } = { + hasOwn: Function.call.bind(Object.prototype.hasOwnProperty) + }; + function cloneIfNode(obj, deep, withoutLoc, commentsCache) { + if (obj && typeof obj.type === "string") { + return cloneNodeInternal(obj, deep, withoutLoc, commentsCache); + } + return obj; + } + function cloneIfNodeOrArray(obj, deep, withoutLoc, commentsCache) { + if (Array.isArray(obj)) { + return obj.map(node => cloneIfNode(node, deep, withoutLoc, commentsCache)); + } + return cloneIfNode(obj, deep, withoutLoc, commentsCache); + } + function cloneNode$1(node, deep = true, withoutLoc = false) { + return cloneNodeInternal(node, deep, withoutLoc, new Map()); + } + function cloneNodeInternal(node, deep = true, withoutLoc = false, commentsCache) { + if (!node) return node; + const { + type + } = node; + const newNode = { + type: node.type + }; + if ((0, _index2.isIdentifier)(node)) { + newNode.name = node.name; + if (hasOwn(node, "optional") && typeof node.optional === "boolean") { + newNode.optional = node.optional; + } + if (hasOwn(node, "typeAnnotation")) { + newNode.typeAnnotation = deep ? cloneIfNodeOrArray(node.typeAnnotation, true, withoutLoc, commentsCache) : node.typeAnnotation; + } + if (hasOwn(node, "decorators")) { + newNode.decorators = deep ? cloneIfNodeOrArray(node.decorators, true, withoutLoc, commentsCache) : node.decorators; + } + } else if (!hasOwn(_index.NODE_FIELDS, type)) { + throw new Error(`Unknown node type: "${type}"`); + } else { + for (const field of Object.keys(_index.NODE_FIELDS[type])) { + if (hasOwn(node, field)) { + if (deep) { + newNode[field] = (0, _index2.isFile)(node) && field === "comments" ? maybeCloneComments(node.comments, deep, withoutLoc, commentsCache) : cloneIfNodeOrArray(node[field], true, withoutLoc, commentsCache); + } else { + newNode[field] = node[field]; + } + } + } + } + if (hasOwn(node, "loc")) { + if (withoutLoc) { + newNode.loc = null; + } else { + newNode.loc = node.loc; + } + } + if (hasOwn(node, "leadingComments")) { + newNode.leadingComments = maybeCloneComments(node.leadingComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "innerComments")) { + newNode.innerComments = maybeCloneComments(node.innerComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "trailingComments")) { + newNode.trailingComments = maybeCloneComments(node.trailingComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "extra")) { + newNode.extra = Object.assign({}, node.extra); + } + return newNode; + } + function maybeCloneComments(comments, deep, withoutLoc, commentsCache) { + if (!comments || !deep) { + return comments; + } + return comments.map(comment => { + const cache = commentsCache.get(comment); + if (cache) return cache; + const { + type, + value, + loc + } = comment; + const ret = { + type, + value, + loc + }; + if (withoutLoc) { + ret.loc = null; + } + commentsCache.set(comment, ret); + return ret; + }); + } + + + return cloneNode; +} + +var clone = {}; + +var hasRequiredClone; + +function requireClone () { + if (hasRequiredClone) return clone; + hasRequiredClone = 1; + + Object.defineProperty(clone, "__esModule", { + value: true + }); + clone.default = clone$1; + var _cloneNode = requireCloneNode(); + function clone$1(node) { + return (0, _cloneNode.default)(node, false); + } + + + return clone; +} + +var cloneDeep = {}; + +var hasRequiredCloneDeep; + +function requireCloneDeep () { + if (hasRequiredCloneDeep) return cloneDeep; + hasRequiredCloneDeep = 1; + + Object.defineProperty(cloneDeep, "__esModule", { + value: true + }); + cloneDeep.default = cloneDeep$1; + var _cloneNode = requireCloneNode(); + function cloneDeep$1(node) { + return (0, _cloneNode.default)(node); + } + + + return cloneDeep; +} + +var cloneDeepWithoutLoc = {}; + +var hasRequiredCloneDeepWithoutLoc; + +function requireCloneDeepWithoutLoc () { + if (hasRequiredCloneDeepWithoutLoc) return cloneDeepWithoutLoc; + hasRequiredCloneDeepWithoutLoc = 1; + + Object.defineProperty(cloneDeepWithoutLoc, "__esModule", { + value: true + }); + cloneDeepWithoutLoc.default = cloneDeepWithoutLoc$1; + var _cloneNode = requireCloneNode(); + function cloneDeepWithoutLoc$1(node) { + return (0, _cloneNode.default)(node, true, true); + } + + + return cloneDeepWithoutLoc; +} + +var cloneWithoutLoc = {}; + +var hasRequiredCloneWithoutLoc; + +function requireCloneWithoutLoc () { + if (hasRequiredCloneWithoutLoc) return cloneWithoutLoc; + hasRequiredCloneWithoutLoc = 1; + + Object.defineProperty(cloneWithoutLoc, "__esModule", { + value: true + }); + cloneWithoutLoc.default = cloneWithoutLoc$1; + var _cloneNode = requireCloneNode(); + function cloneWithoutLoc$1(node) { + return (0, _cloneNode.default)(node, false, true); + } + + + return cloneWithoutLoc; +} + +var addComment = {}; + +var addComments = {}; + +var hasRequiredAddComments; + +function requireAddComments () { + if (hasRequiredAddComments) return addComments; + hasRequiredAddComments = 1; + + Object.defineProperty(addComments, "__esModule", { + value: true + }); + addComments.default = addComments$1; + function addComments$1(node, type, comments) { + if (!comments || !node) return node; + const key = `${type}Comments`; + if (node[key]) { + if (type === "leading") { + node[key] = comments.concat(node[key]); + } else { + node[key].push(...comments); + } + } else { + node[key] = comments; + } + return node; + } + + + return addComments; +} + +var hasRequiredAddComment; + +function requireAddComment () { + if (hasRequiredAddComment) return addComment; + hasRequiredAddComment = 1; + + Object.defineProperty(addComment, "__esModule", { + value: true + }); + addComment.default = addComment$1; + var _addComments = requireAddComments(); + function addComment$1(node, type, content, line) { + return (0, _addComments.default)(node, type, [{ + type: line ? "CommentLine" : "CommentBlock", + value: content + }]); + } + + + return addComment; +} + +var inheritInnerComments = {}; + +var inherit = {}; + +var hasRequiredInherit; + +function requireInherit () { + if (hasRequiredInherit) return inherit; + hasRequiredInherit = 1; + + Object.defineProperty(inherit, "__esModule", { + value: true + }); + inherit.default = inherit$1; + function inherit$1(key, child, parent) { + if (child && parent) { + child[key] = Array.from(new Set([].concat(child[key], parent[key]).filter(Boolean))); + } + } + + + return inherit; +} + +var hasRequiredInheritInnerComments; + +function requireInheritInnerComments () { + if (hasRequiredInheritInnerComments) return inheritInnerComments; + hasRequiredInheritInnerComments = 1; + + Object.defineProperty(inheritInnerComments, "__esModule", { + value: true + }); + inheritInnerComments.default = inheritInnerComments$1; + var _inherit = requireInherit(); + function inheritInnerComments$1(child, parent) { + (0, _inherit.default)("innerComments", child, parent); + } + + + return inheritInnerComments; +} + +var inheritLeadingComments = {}; + +var hasRequiredInheritLeadingComments; + +function requireInheritLeadingComments () { + if (hasRequiredInheritLeadingComments) return inheritLeadingComments; + hasRequiredInheritLeadingComments = 1; + + Object.defineProperty(inheritLeadingComments, "__esModule", { + value: true + }); + inheritLeadingComments.default = inheritLeadingComments$1; + var _inherit = requireInherit(); + function inheritLeadingComments$1(child, parent) { + (0, _inherit.default)("leadingComments", child, parent); + } + + + return inheritLeadingComments; +} + +var inheritsComments = {}; + +var inheritTrailingComments = {}; + +var hasRequiredInheritTrailingComments; + +function requireInheritTrailingComments () { + if (hasRequiredInheritTrailingComments) return inheritTrailingComments; + hasRequiredInheritTrailingComments = 1; + + Object.defineProperty(inheritTrailingComments, "__esModule", { + value: true + }); + inheritTrailingComments.default = inheritTrailingComments$1; + var _inherit = requireInherit(); + function inheritTrailingComments$1(child, parent) { + (0, _inherit.default)("trailingComments", child, parent); + } + + + return inheritTrailingComments; +} + +var hasRequiredInheritsComments; + +function requireInheritsComments () { + if (hasRequiredInheritsComments) return inheritsComments; + hasRequiredInheritsComments = 1; + + Object.defineProperty(inheritsComments, "__esModule", { + value: true + }); + inheritsComments.default = inheritsComments$1; + var _inheritTrailingComments = requireInheritTrailingComments(); + var _inheritLeadingComments = requireInheritLeadingComments(); + var _inheritInnerComments = requireInheritInnerComments(); + function inheritsComments$1(child, parent) { + (0, _inheritTrailingComments.default)(child, parent); + (0, _inheritLeadingComments.default)(child, parent); + (0, _inheritInnerComments.default)(child, parent); + return child; + } + + + return inheritsComments; +} + +var removeComments = {}; + +var hasRequiredRemoveComments; + +function requireRemoveComments () { + if (hasRequiredRemoveComments) return removeComments; + hasRequiredRemoveComments = 1; + + Object.defineProperty(removeComments, "__esModule", { + value: true + }); + removeComments.default = removeComments$1; + var _index = requireConstants(); + function removeComments$1(node) { + _index.COMMENT_KEYS.forEach(key => { + node[key] = null; + }); + return node; + } + + + return removeComments; +} + +var generated = {}; + +var hasRequiredGenerated; + +function requireGenerated () { + if (hasRequiredGenerated) return generated; + hasRequiredGenerated = 1; + + Object.defineProperty(generated, "__esModule", { + value: true + }); + generated.WHILE_TYPES = generated.USERWHITESPACABLE_TYPES = generated.UNARYLIKE_TYPES = generated.TYPESCRIPT_TYPES = generated.TSTYPE_TYPES = generated.TSTYPEELEMENT_TYPES = generated.TSENTITYNAME_TYPES = generated.TSBASETYPE_TYPES = generated.TERMINATORLESS_TYPES = generated.STATEMENT_TYPES = generated.STANDARDIZED_TYPES = generated.SCOPABLE_TYPES = generated.PUREISH_TYPES = generated.PROPERTY_TYPES = generated.PRIVATE_TYPES = generated.PATTERN_TYPES = generated.PATTERNLIKE_TYPES = generated.OBJECTMEMBER_TYPES = generated.MODULESPECIFIER_TYPES = generated.MODULEDECLARATION_TYPES = generated.MISCELLANEOUS_TYPES = generated.METHOD_TYPES = generated.LVAL_TYPES = generated.LOOP_TYPES = generated.LITERAL_TYPES = generated.JSX_TYPES = generated.IMPORTOREXPORTDECLARATION_TYPES = generated.IMMUTABLE_TYPES = generated.FUNCTION_TYPES = generated.FUNCTIONPARENT_TYPES = generated.FOR_TYPES = generated.FORXSTATEMENT_TYPES = generated.FLOW_TYPES = generated.FLOWTYPE_TYPES = generated.FLOWPREDICATE_TYPES = generated.FLOWDECLARATION_TYPES = generated.FLOWBASEANNOTATION_TYPES = generated.EXPRESSION_TYPES = generated.EXPRESSIONWRAPPER_TYPES = generated.EXPORTDECLARATION_TYPES = generated.ENUMMEMBER_TYPES = generated.ENUMBODY_TYPES = generated.DECLARATION_TYPES = generated.CONDITIONAL_TYPES = generated.COMPLETIONSTATEMENT_TYPES = generated.CLASS_TYPES = generated.BLOCK_TYPES = generated.BLOCKPARENT_TYPES = generated.BINARY_TYPES = generated.ACCESSOR_TYPES = void 0; + var _index = requireDefinitions(); + generated.STANDARDIZED_TYPES = _index.FLIPPED_ALIAS_KEYS["Standardized"]; + generated.EXPRESSION_TYPES = _index.FLIPPED_ALIAS_KEYS["Expression"]; + generated.BINARY_TYPES = _index.FLIPPED_ALIAS_KEYS["Binary"]; + generated.SCOPABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["Scopable"]; + generated.BLOCKPARENT_TYPES = _index.FLIPPED_ALIAS_KEYS["BlockParent"]; + generated.BLOCK_TYPES = _index.FLIPPED_ALIAS_KEYS["Block"]; + generated.STATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["Statement"]; + generated.TERMINATORLESS_TYPES = _index.FLIPPED_ALIAS_KEYS["Terminatorless"]; + generated.COMPLETIONSTATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["CompletionStatement"]; + generated.CONDITIONAL_TYPES = _index.FLIPPED_ALIAS_KEYS["Conditional"]; + generated.LOOP_TYPES = _index.FLIPPED_ALIAS_KEYS["Loop"]; + generated.WHILE_TYPES = _index.FLIPPED_ALIAS_KEYS["While"]; + generated.EXPRESSIONWRAPPER_TYPES = _index.FLIPPED_ALIAS_KEYS["ExpressionWrapper"]; + generated.FOR_TYPES = _index.FLIPPED_ALIAS_KEYS["For"]; + generated.FORXSTATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["ForXStatement"]; + generated.FUNCTION_TYPES = _index.FLIPPED_ALIAS_KEYS["Function"]; + generated.FUNCTIONPARENT_TYPES = _index.FLIPPED_ALIAS_KEYS["FunctionParent"]; + generated.PUREISH_TYPES = _index.FLIPPED_ALIAS_KEYS["Pureish"]; + generated.DECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["Declaration"]; + generated.PATTERNLIKE_TYPES = _index.FLIPPED_ALIAS_KEYS["PatternLike"]; + generated.LVAL_TYPES = _index.FLIPPED_ALIAS_KEYS["LVal"]; + generated.TSENTITYNAME_TYPES = _index.FLIPPED_ALIAS_KEYS["TSEntityName"]; + generated.LITERAL_TYPES = _index.FLIPPED_ALIAS_KEYS["Literal"]; + generated.IMMUTABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["Immutable"]; + generated.USERWHITESPACABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["UserWhitespacable"]; + generated.METHOD_TYPES = _index.FLIPPED_ALIAS_KEYS["Method"]; + generated.OBJECTMEMBER_TYPES = _index.FLIPPED_ALIAS_KEYS["ObjectMember"]; + generated.PROPERTY_TYPES = _index.FLIPPED_ALIAS_KEYS["Property"]; + generated.UNARYLIKE_TYPES = _index.FLIPPED_ALIAS_KEYS["UnaryLike"]; + generated.PATTERN_TYPES = _index.FLIPPED_ALIAS_KEYS["Pattern"]; + generated.CLASS_TYPES = _index.FLIPPED_ALIAS_KEYS["Class"]; + const IMPORTOREXPORTDECLARATION_TYPES = generated.IMPORTOREXPORTDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["ImportOrExportDeclaration"]; + generated.EXPORTDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["ExportDeclaration"]; + generated.MODULESPECIFIER_TYPES = _index.FLIPPED_ALIAS_KEYS["ModuleSpecifier"]; + generated.ACCESSOR_TYPES = _index.FLIPPED_ALIAS_KEYS["Accessor"]; + generated.PRIVATE_TYPES = _index.FLIPPED_ALIAS_KEYS["Private"]; + generated.FLOW_TYPES = _index.FLIPPED_ALIAS_KEYS["Flow"]; + generated.FLOWTYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowType"]; + generated.FLOWBASEANNOTATION_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowBaseAnnotation"]; + generated.FLOWDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowDeclaration"]; + generated.FLOWPREDICATE_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowPredicate"]; + generated.ENUMBODY_TYPES = _index.FLIPPED_ALIAS_KEYS["EnumBody"]; + generated.ENUMMEMBER_TYPES = _index.FLIPPED_ALIAS_KEYS["EnumMember"]; + generated.JSX_TYPES = _index.FLIPPED_ALIAS_KEYS["JSX"]; + generated.MISCELLANEOUS_TYPES = _index.FLIPPED_ALIAS_KEYS["Miscellaneous"]; + generated.TYPESCRIPT_TYPES = _index.FLIPPED_ALIAS_KEYS["TypeScript"]; + generated.TSTYPEELEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["TSTypeElement"]; + generated.TSTYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["TSType"]; + generated.TSBASETYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["TSBaseType"]; + generated.MODULEDECLARATION_TYPES = IMPORTOREXPORTDECLARATION_TYPES; + + + return generated; +} + +var ensureBlock = {}; + +var toBlock = {}; + +var hasRequiredToBlock; + +function requireToBlock () { + if (hasRequiredToBlock) return toBlock; + hasRequiredToBlock = 1; + + Object.defineProperty(toBlock, "__esModule", { + value: true + }); + toBlock.default = toBlock$1; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + function toBlock$1(node, parent) { + if ((0, _index.isBlockStatement)(node)) { + return node; + } + let blockNodes = []; + if ((0, _index.isEmptyStatement)(node)) { + blockNodes = []; + } else { + if (!(0, _index.isStatement)(node)) { + if ((0, _index.isFunction)(parent)) { + node = (0, _index2.returnStatement)(node); + } else { + node = (0, _index2.expressionStatement)(node); + } + } + blockNodes = [node]; + } + return (0, _index2.blockStatement)(blockNodes); + } + + + return toBlock; +} + +var hasRequiredEnsureBlock; + +function requireEnsureBlock () { + if (hasRequiredEnsureBlock) return ensureBlock; + hasRequiredEnsureBlock = 1; + + Object.defineProperty(ensureBlock, "__esModule", { + value: true + }); + ensureBlock.default = ensureBlock$1; + var _toBlock = requireToBlock(); + function ensureBlock$1(node, key = "body") { + const result = (0, _toBlock.default)(node[key], node); + node[key] = result; + return result; + } + + + return ensureBlock; +} + +var toBindingIdentifierName = {}; + +var toIdentifier = {}; + +var hasRequiredToIdentifier; + +function requireToIdentifier () { + if (hasRequiredToIdentifier) return toIdentifier; + hasRequiredToIdentifier = 1; + + Object.defineProperty(toIdentifier, "__esModule", { + value: true + }); + toIdentifier.default = toIdentifier$1; + var _isValidIdentifier = requireIsValidIdentifier(); + var _helperValidatorIdentifier = requireLib$3(); + function toIdentifier$1(input) { + input = input + ""; + let name = ""; + for (const c of input) { + name += (0, _helperValidatorIdentifier.isIdentifierChar)(c.codePointAt(0)) ? c : "-"; + } + name = name.replace(/^[-0-9]+/, ""); + name = name.replace(/[-\s]+(.)?/g, function (match, c) { + return c ? c.toUpperCase() : ""; + }); + if (!(0, _isValidIdentifier.default)(name)) { + name = `_${name}`; + } + return name || "_"; + } + + + return toIdentifier; +} + +var hasRequiredToBindingIdentifierName; + +function requireToBindingIdentifierName () { + if (hasRequiredToBindingIdentifierName) return toBindingIdentifierName; + hasRequiredToBindingIdentifierName = 1; + + Object.defineProperty(toBindingIdentifierName, "__esModule", { + value: true + }); + toBindingIdentifierName.default = toBindingIdentifierName$1; + var _toIdentifier = requireToIdentifier(); + function toBindingIdentifierName$1(name) { + name = (0, _toIdentifier.default)(name); + if (name === "eval" || name === "arguments") name = "_" + name; + return name; + } + + + return toBindingIdentifierName; +} + +var toComputedKey = {}; + +var hasRequiredToComputedKey; + +function requireToComputedKey () { + if (hasRequiredToComputedKey) return toComputedKey; + hasRequiredToComputedKey = 1; + + Object.defineProperty(toComputedKey, "__esModule", { + value: true + }); + toComputedKey.default = toComputedKey$1; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + function toComputedKey$1(node, key = node.key || node.property) { + if (!node.computed && (0, _index.isIdentifier)(key)) key = (0, _index2.stringLiteral)(key.name); + return key; + } + + + return toComputedKey; +} + +var toExpression = {}; + +var hasRequiredToExpression; + +function requireToExpression () { + if (hasRequiredToExpression) return toExpression; + hasRequiredToExpression = 1; + + Object.defineProperty(toExpression, "__esModule", { + value: true + }); + toExpression.default = void 0; + var _index = requireGenerated$3(); + toExpression.default = toExpression$1; + function toExpression$1(node) { + if ((0, _index.isExpressionStatement)(node)) { + node = node.expression; + } + if ((0, _index.isExpression)(node)) { + return node; + } + if ((0, _index.isClass)(node)) { + node.type = "ClassExpression"; + } else if ((0, _index.isFunction)(node)) { + node.type = "FunctionExpression"; + } + if (!(0, _index.isExpression)(node)) { + throw new Error(`cannot turn ${node.type} to an expression`); + } + return node; + } + + + return toExpression; +} + +var toKeyAlias = {}; + +var removePropertiesDeep = {}; + +var traverseFast = {}; + +var hasRequiredTraverseFast; + +function requireTraverseFast () { + if (hasRequiredTraverseFast) return traverseFast; + hasRequiredTraverseFast = 1; + + Object.defineProperty(traverseFast, "__esModule", { + value: true + }); + traverseFast.default = traverseFast$1; + var _index = requireDefinitions(); + function traverseFast$1(node, enter, opts) { + if (!node) return; + const keys = _index.VISITOR_KEYS[node.type]; + if (!keys) return; + opts = opts || {}; + enter(node, opts); + for (const key of keys) { + const subNode = node[key]; + if (Array.isArray(subNode)) { + for (const node of subNode) { + traverseFast$1(node, enter, opts); + } + } else { + traverseFast$1(subNode, enter, opts); + } + } + } + + + return traverseFast; +} + +var removeProperties = {}; + +var hasRequiredRemoveProperties; + +function requireRemoveProperties () { + if (hasRequiredRemoveProperties) return removeProperties; + hasRequiredRemoveProperties = 1; + + Object.defineProperty(removeProperties, "__esModule", { + value: true + }); + removeProperties.default = removeProperties$1; + var _index = requireConstants(); + const CLEAR_KEYS = ["tokens", "start", "end", "loc", "raw", "rawValue"]; + const CLEAR_KEYS_PLUS_COMMENTS = [..._index.COMMENT_KEYS, "comments", ...CLEAR_KEYS]; + function removeProperties$1(node, opts = {}) { + const map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS; + for (const key of map) { + if (node[key] != null) node[key] = undefined; + } + for (const key of Object.keys(node)) { + if (key[0] === "_" && node[key] != null) node[key] = undefined; + } + const symbols = Object.getOwnPropertySymbols(node); + for (const sym of symbols) { + node[sym] = null; + } + } + + + return removeProperties; +} + +var hasRequiredRemovePropertiesDeep; + +function requireRemovePropertiesDeep () { + if (hasRequiredRemovePropertiesDeep) return removePropertiesDeep; + hasRequiredRemovePropertiesDeep = 1; + + Object.defineProperty(removePropertiesDeep, "__esModule", { + value: true + }); + removePropertiesDeep.default = removePropertiesDeep$1; + var _traverseFast = requireTraverseFast(); + var _removeProperties = requireRemoveProperties(); + function removePropertiesDeep$1(tree, opts) { + (0, _traverseFast.default)(tree, _removeProperties.default, opts); + return tree; + } + + + return removePropertiesDeep; +} + +var hasRequiredToKeyAlias; + +function requireToKeyAlias () { + if (hasRequiredToKeyAlias) return toKeyAlias; + hasRequiredToKeyAlias = 1; + + Object.defineProperty(toKeyAlias, "__esModule", { + value: true + }); + toKeyAlias.default = toKeyAlias$1; + var _index = requireGenerated$3(); + var _cloneNode = requireCloneNode(); + var _removePropertiesDeep = requireRemovePropertiesDeep(); + function toKeyAlias$1(node, key = node.key) { + let alias; + if (node.kind === "method") { + return toKeyAlias$1.increment() + ""; + } else if ((0, _index.isIdentifier)(key)) { + alias = key.name; + } else if ((0, _index.isStringLiteral)(key)) { + alias = JSON.stringify(key.value); + } else { + alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneNode.default)(key))); + } + if (node.computed) { + alias = `[${alias}]`; + } + if (node.static) { + alias = `static:${alias}`; + } + return alias; + } + toKeyAlias$1.uid = 0; + toKeyAlias$1.increment = function () { + if (toKeyAlias$1.uid >= Number.MAX_SAFE_INTEGER) { + return toKeyAlias$1.uid = 0; + } else { + return toKeyAlias$1.uid++; + } + }; + + + return toKeyAlias; +} + +var toStatement = {}; + +var hasRequiredToStatement; + +function requireToStatement () { + if (hasRequiredToStatement) return toStatement; + hasRequiredToStatement = 1; + + Object.defineProperty(toStatement, "__esModule", { + value: true + }); + toStatement.default = void 0; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + toStatement.default = toStatement$1; + function toStatement$1(node, ignore) { + if ((0, _index.isStatement)(node)) { + return node; + } + let mustHaveId = false; + let newType; + if ((0, _index.isClass)(node)) { + mustHaveId = true; + newType = "ClassDeclaration"; + } else if ((0, _index.isFunction)(node)) { + mustHaveId = true; + newType = "FunctionDeclaration"; + } else if ((0, _index.isAssignmentExpression)(node)) { + return (0, _index2.expressionStatement)(node); + } + if (mustHaveId && !node.id) { + newType = false; + } + if (!newType) { + if (ignore) { + return false; + } else { + throw new Error(`cannot turn ${node.type} to a statement`); + } + } + node.type = newType; + return node; + } + + + return toStatement; +} + +var valueToNode = {}; + +var hasRequiredValueToNode; + +function requireValueToNode () { + if (hasRequiredValueToNode) return valueToNode; + hasRequiredValueToNode = 1; + + Object.defineProperty(valueToNode, "__esModule", { + value: true + }); + valueToNode.default = void 0; + var _isValidIdentifier = requireIsValidIdentifier(); + var _index = requireGenerated$2(); + valueToNode.default = valueToNode$1; + const objectToString = Function.call.bind(Object.prototype.toString); + function isRegExp(value) { + return objectToString(value) === "[object RegExp]"; + } + function isPlainObject(value) { + if (typeof value !== "object" || value === null || Object.prototype.toString.call(value) !== "[object Object]") { + return false; + } + const proto = Object.getPrototypeOf(value); + return proto === null || Object.getPrototypeOf(proto) === null; + } + function valueToNode$1(value) { + if (value === undefined) { + return (0, _index.identifier)("undefined"); + } + if (value === true || value === false) { + return (0, _index.booleanLiteral)(value); + } + if (value === null) { + return (0, _index.nullLiteral)(); + } + if (typeof value === "string") { + return (0, _index.stringLiteral)(value); + } + if (typeof value === "number") { + let result; + if (Number.isFinite(value)) { + result = (0, _index.numericLiteral)(Math.abs(value)); + } else { + let numerator; + if (Number.isNaN(value)) { + numerator = (0, _index.numericLiteral)(0); + } else { + numerator = (0, _index.numericLiteral)(1); + } + result = (0, _index.binaryExpression)("/", numerator, (0, _index.numericLiteral)(0)); + } + if (value < 0 || Object.is(value, -0)) { + result = (0, _index.unaryExpression)("-", result); + } + return result; + } + if (isRegExp(value)) { + const pattern = value.source; + const flags = /\/([a-z]*)$/.exec(value.toString())[1]; + return (0, _index.regExpLiteral)(pattern, flags); + } + if (Array.isArray(value)) { + return (0, _index.arrayExpression)(value.map(valueToNode$1)); + } + if (isPlainObject(value)) { + const props = []; + for (const key of Object.keys(value)) { + let nodeKey; + if ((0, _isValidIdentifier.default)(key)) { + nodeKey = (0, _index.identifier)(key); + } else { + nodeKey = (0, _index.stringLiteral)(key); + } + props.push((0, _index.objectProperty)(nodeKey, valueToNode$1(value[key]))); + } + return (0, _index.objectExpression)(props); + } + throw new Error("don't know how to turn this value into a node"); + } + + + return valueToNode; +} + +var appendToMemberExpression = {}; + +var hasRequiredAppendToMemberExpression; + +function requireAppendToMemberExpression () { + if (hasRequiredAppendToMemberExpression) return appendToMemberExpression; + hasRequiredAppendToMemberExpression = 1; + + Object.defineProperty(appendToMemberExpression, "__esModule", { + value: true + }); + appendToMemberExpression.default = appendToMemberExpression$1; + var _index = requireGenerated$2(); + function appendToMemberExpression$1(member, append, computed = false) { + member.object = (0, _index.memberExpression)(member.object, member.property, member.computed); + member.property = append; + member.computed = !!computed; + return member; + } + + + return appendToMemberExpression; +} + +var inherits = {}; + +var hasRequiredInherits; + +function requireInherits () { + if (hasRequiredInherits) return inherits; + hasRequiredInherits = 1; + + Object.defineProperty(inherits, "__esModule", { + value: true + }); + inherits.default = inherits$1; + var _index = requireConstants(); + var _inheritsComments = requireInheritsComments(); + function inherits$1(child, parent) { + if (!child || !parent) return child; + for (const key of _index.INHERIT_KEYS.optional) { + if (child[key] == null) { + child[key] = parent[key]; + } + } + for (const key of Object.keys(parent)) { + if (key[0] === "_" && key !== "__clone") { + child[key] = parent[key]; + } + } + for (const key of _index.INHERIT_KEYS.force) { + child[key] = parent[key]; + } + (0, _inheritsComments.default)(child, parent); + return child; + } + + + return inherits; +} + +var prependToMemberExpression = {}; + +var hasRequiredPrependToMemberExpression; + +function requirePrependToMemberExpression () { + if (hasRequiredPrependToMemberExpression) return prependToMemberExpression; + hasRequiredPrependToMemberExpression = 1; + + Object.defineProperty(prependToMemberExpression, "__esModule", { + value: true + }); + prependToMemberExpression.default = prependToMemberExpression$1; + var _index = requireGenerated$2(); + var _index2 = requireLib$1(); + function prependToMemberExpression$1(member, prepend) { + if ((0, _index2.isSuper)(member.object)) { + throw new Error("Cannot prepend node to super property access (`super.foo`)."); + } + member.object = (0, _index.memberExpression)(prepend, member.object); + return member; + } + + + return prependToMemberExpression; +} + +var getAssignmentIdentifiers = {}; + +var hasRequiredGetAssignmentIdentifiers; + +function requireGetAssignmentIdentifiers () { + if (hasRequiredGetAssignmentIdentifiers) return getAssignmentIdentifiers; + hasRequiredGetAssignmentIdentifiers = 1; + + Object.defineProperty(getAssignmentIdentifiers, "__esModule", { + value: true + }); + getAssignmentIdentifiers.default = getAssignmentIdentifiers$1; + function getAssignmentIdentifiers$1(node) { + const search = [].concat(node); + const ids = Object.create(null); + while (search.length) { + const id = search.pop(); + if (!id) continue; + switch (id.type) { + case "ArrayPattern": + search.push(...id.elements); + break; + case "AssignmentExpression": + case "AssignmentPattern": + case "ForInStatement": + case "ForOfStatement": + search.push(id.left); + break; + case "ObjectPattern": + search.push(...id.properties); + break; + case "ObjectProperty": + search.push(id.value); + break; + case "RestElement": + case "UpdateExpression": + search.push(id.argument); + break; + case "UnaryExpression": + if (id.operator === "delete") { + search.push(id.argument); + } + break; + case "Identifier": + ids[id.name] = id; + break; + } + } + return ids; + } + + + return getAssignmentIdentifiers; +} + +var getBindingIdentifiers = {}; + +var hasRequiredGetBindingIdentifiers; + +function requireGetBindingIdentifiers () { + if (hasRequiredGetBindingIdentifiers) return getBindingIdentifiers; + hasRequiredGetBindingIdentifiers = 1; + + Object.defineProperty(getBindingIdentifiers, "__esModule", { + value: true + }); + getBindingIdentifiers.default = getBindingIdentifiers$1; + var _index = requireGenerated$3(); + function getBindingIdentifiers$1(node, duplicates, outerOnly, newBindingsOnly) { + const search = [].concat(node); + const ids = Object.create(null); + while (search.length) { + const id = search.shift(); + if (!id) continue; + if (newBindingsOnly && ((0, _index.isAssignmentExpression)(id) || (0, _index.isUnaryExpression)(id) || (0, _index.isUpdateExpression)(id))) { + continue; + } + if ((0, _index.isIdentifier)(id)) { + if (duplicates) { + const _ids = ids[id.name] = ids[id.name] || []; + _ids.push(id); + } else { + ids[id.name] = id; + } + continue; + } + if ((0, _index.isExportDeclaration)(id) && !(0, _index.isExportAllDeclaration)(id)) { + if ((0, _index.isDeclaration)(id.declaration)) { + search.push(id.declaration); + } + continue; + } + if (outerOnly) { + if ((0, _index.isFunctionDeclaration)(id)) { + search.push(id.id); + continue; + } + if ((0, _index.isFunctionExpression)(id)) { + continue; + } + } + const keys = getBindingIdentifiers$1.keys[id.type]; + if (keys) { + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const nodes = id[key]; + if (nodes) { + if (Array.isArray(nodes)) { + search.push(...nodes); + } else { + search.push(nodes); + } + } + } + } + } + return ids; + } + const keys = { + DeclareClass: ["id"], + DeclareFunction: ["id"], + DeclareModule: ["id"], + DeclareVariable: ["id"], + DeclareInterface: ["id"], + DeclareTypeAlias: ["id"], + DeclareOpaqueType: ["id"], + InterfaceDeclaration: ["id"], + TypeAlias: ["id"], + OpaqueType: ["id"], + CatchClause: ["param"], + LabeledStatement: ["label"], + UnaryExpression: ["argument"], + AssignmentExpression: ["left"], + ImportSpecifier: ["local"], + ImportNamespaceSpecifier: ["local"], + ImportDefaultSpecifier: ["local"], + ImportDeclaration: ["specifiers"], + ExportSpecifier: ["exported"], + ExportNamespaceSpecifier: ["exported"], + ExportDefaultSpecifier: ["exported"], + FunctionDeclaration: ["id", "params"], + FunctionExpression: ["id", "params"], + ArrowFunctionExpression: ["params"], + ObjectMethod: ["params"], + ClassMethod: ["params"], + ClassPrivateMethod: ["params"], + ForInStatement: ["left"], + ForOfStatement: ["left"], + ClassDeclaration: ["id"], + ClassExpression: ["id"], + RestElement: ["argument"], + UpdateExpression: ["argument"], + ObjectProperty: ["value"], + AssignmentPattern: ["left"], + ArrayPattern: ["elements"], + ObjectPattern: ["properties"], + VariableDeclaration: ["declarations"], + VariableDeclarator: ["id"] + }; + getBindingIdentifiers$1.keys = keys; + + + return getBindingIdentifiers; +} + +var getOuterBindingIdentifiers = {}; + +var hasRequiredGetOuterBindingIdentifiers; + +function requireGetOuterBindingIdentifiers () { + if (hasRequiredGetOuterBindingIdentifiers) return getOuterBindingIdentifiers; + hasRequiredGetOuterBindingIdentifiers = 1; + + Object.defineProperty(getOuterBindingIdentifiers, "__esModule", { + value: true + }); + getOuterBindingIdentifiers.default = void 0; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + getOuterBindingIdentifiers.default = getOuterBindingIdentifiers$1; + function getOuterBindingIdentifiers$1(node, duplicates) { + return (0, _getBindingIdentifiers.default)(node, duplicates, true); + } + + + return getOuterBindingIdentifiers; +} + +var getFunctionName$3 = {}; + +var hasRequiredGetFunctionName; + +function requireGetFunctionName () { + if (hasRequiredGetFunctionName) return getFunctionName$3; + hasRequiredGetFunctionName = 1; + + Object.defineProperty(getFunctionName$3, "__esModule", { + value: true + }); + getFunctionName$3.default = getFunctionName; + var _index = requireGenerated$3(); + function getNameFromLiteralId(id) { + if ((0, _index.isNullLiteral)(id)) { + return "null"; + } + if ((0, _index.isRegExpLiteral)(id)) { + return `/${id.pattern}/${id.flags}`; + } + if ((0, _index.isTemplateLiteral)(id)) { + return id.quasis.map(quasi => quasi.value.raw).join(""); + } + if (id.value !== undefined) { + return String(id.value); + } + return null; + } + function getObjectMemberKey(node) { + if (!node.computed || (0, _index.isLiteral)(node.key)) { + return node.key; + } + } + function getFunctionName(node, parent) { + if ("id" in node && node.id) { + return { + name: node.id.name, + originalNode: node.id + }; + } + let prefix = ""; + let id; + if ((0, _index.isObjectProperty)(parent, { + value: node + })) { + id = getObjectMemberKey(parent); + } else if ((0, _index.isObjectMethod)(node) || (0, _index.isClassMethod)(node)) { + id = getObjectMemberKey(node); + if (node.kind === "get") prefix = "get ";else if (node.kind === "set") prefix = "set "; + } else if ((0, _index.isVariableDeclarator)(parent, { + init: node + })) { + id = parent.id; + } else if ((0, _index.isAssignmentExpression)(parent, { + operator: "=", + right: node + })) { + id = parent.left; + } + if (!id) return null; + const name = (0, _index.isLiteral)(id) ? getNameFromLiteralId(id) : (0, _index.isIdentifier)(id) ? id.name : (0, _index.isPrivateName)(id) ? id.id.name : null; + if (name == null) return null; + return { + name: prefix + name, + originalNode: id + }; + } + + + return getFunctionName$3; +} + +var traverse = {}; + +var hasRequiredTraverse; + +function requireTraverse () { + if (hasRequiredTraverse) return traverse; + hasRequiredTraverse = 1; + + Object.defineProperty(traverse, "__esModule", { + value: true + }); + traverse.default = traverse$1; + var _index = requireDefinitions(); + function traverse$1(node, handlers, state) { + if (typeof handlers === "function") { + handlers = { + enter: handlers + }; + } + const { + enter, + exit + } = handlers; + traverseSimpleImpl(node, enter, exit, state, []); + } + function traverseSimpleImpl(node, enter, exit, state, ancestors) { + const keys = _index.VISITOR_KEYS[node.type]; + if (!keys) return; + if (enter) enter(node, ancestors, state); + for (const key of keys) { + const subNode = node[key]; + if (Array.isArray(subNode)) { + for (let i = 0; i < subNode.length; i++) { + const child = subNode[i]; + if (!child) continue; + ancestors.push({ + node, + key, + index: i + }); + traverseSimpleImpl(child, enter, exit, state, ancestors); + ancestors.pop(); + } + } else if (subNode) { + ancestors.push({ + node, + key + }); + traverseSimpleImpl(subNode, enter, exit, state, ancestors); + ancestors.pop(); + } + } + if (exit) exit(node, ancestors, state); + } + + + return traverse; +} + +var isBinding = {}; + +var hasRequiredIsBinding; + +function requireIsBinding () { + if (hasRequiredIsBinding) return isBinding; + hasRequiredIsBinding = 1; + + Object.defineProperty(isBinding, "__esModule", { + value: true + }); + isBinding.default = isBinding$1; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + function isBinding$1(node, parent, grandparent) { + if (grandparent && node.type === "Identifier" && parent.type === "ObjectProperty" && grandparent.type === "ObjectExpression") { + return false; + } + const keys = _getBindingIdentifiers.default.keys[parent.type]; + if (keys) { + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const val = parent[key]; + if (Array.isArray(val)) { + if (val.includes(node)) return true; + } else { + if (val === node) return true; + } + } + } + return false; + } + + + return isBinding; +} + +var isBlockScoped = {}; + +var isLet = {}; + +var hasRequiredIsLet; + +function requireIsLet () { + if (hasRequiredIsLet) return isLet; + hasRequiredIsLet = 1; + + Object.defineProperty(isLet, "__esModule", { + value: true + }); + isLet.default = isLet$1; + var _index = requireGenerated$3(); + var _index2 = requireConstants(); + function isLet$1(node) { + return (0, _index.isVariableDeclaration)(node) && (node.kind !== "var" || node[_index2.BLOCK_SCOPED_SYMBOL]); + } + + + return isLet; +} + +var hasRequiredIsBlockScoped; + +function requireIsBlockScoped () { + if (hasRequiredIsBlockScoped) return isBlockScoped; + hasRequiredIsBlockScoped = 1; + + Object.defineProperty(isBlockScoped, "__esModule", { + value: true + }); + isBlockScoped.default = isBlockScoped$1; + var _index = requireGenerated$3(); + var _isLet = requireIsLet(); + function isBlockScoped$1(node) { + return (0, _index.isFunctionDeclaration)(node) || (0, _index.isClassDeclaration)(node) || (0, _isLet.default)(node); + } + + + return isBlockScoped; +} + +var isImmutable = {}; + +var hasRequiredIsImmutable; + +function requireIsImmutable () { + if (hasRequiredIsImmutable) return isImmutable; + hasRequiredIsImmutable = 1; + + Object.defineProperty(isImmutable, "__esModule", { + value: true + }); + isImmutable.default = isImmutable$1; + var _isType = requireIsType(); + var _index = requireGenerated$3(); + function isImmutable$1(node) { + if ((0, _isType.default)(node.type, "Immutable")) return true; + if ((0, _index.isIdentifier)(node)) { + if (node.name === "undefined") { + return true; + } else { + return false; + } + } + return false; + } + + + return isImmutable; +} + +var isNodesEquivalent = {}; + +var hasRequiredIsNodesEquivalent; + +function requireIsNodesEquivalent () { + if (hasRequiredIsNodesEquivalent) return isNodesEquivalent; + hasRequiredIsNodesEquivalent = 1; + + Object.defineProperty(isNodesEquivalent, "__esModule", { + value: true + }); + isNodesEquivalent.default = isNodesEquivalent$1; + var _index = requireDefinitions(); + function isNodesEquivalent$1(a, b) { + if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) { + return a === b; + } + if (a.type !== b.type) { + return false; + } + const fields = Object.keys(_index.NODE_FIELDS[a.type] || a.type); + const visitorKeys = _index.VISITOR_KEYS[a.type]; + for (const field of fields) { + const val_a = a[field]; + const val_b = b[field]; + if (typeof val_a !== typeof val_b) { + return false; + } + if (val_a == null && val_b == null) { + continue; + } else if (val_a == null || val_b == null) { + return false; + } + if (Array.isArray(val_a)) { + if (!Array.isArray(val_b)) { + return false; + } + if (val_a.length !== val_b.length) { + return false; + } + for (let i = 0; i < val_a.length; i++) { + if (!isNodesEquivalent$1(val_a[i], val_b[i])) { + return false; + } + } + continue; + } + if (typeof val_a === "object" && !(visitorKeys != null && visitorKeys.includes(field))) { + for (const key of Object.keys(val_a)) { + if (val_a[key] !== val_b[key]) { + return false; + } + } + continue; + } + if (!isNodesEquivalent$1(val_a, val_b)) { + return false; + } + } + return true; + } + + + return isNodesEquivalent; +} + +var isReferenced = {}; + +var hasRequiredIsReferenced; + +function requireIsReferenced () { + if (hasRequiredIsReferenced) return isReferenced; + hasRequiredIsReferenced = 1; + + Object.defineProperty(isReferenced, "__esModule", { + value: true + }); + isReferenced.default = isReferenced$1; + function isReferenced$1(node, parent, grandparent) { + switch (parent.type) { + case "MemberExpression": + case "OptionalMemberExpression": + if (parent.property === node) { + return !!parent.computed; + } + return parent.object === node; + case "JSXMemberExpression": + return parent.object === node; + case "VariableDeclarator": + return parent.init === node; + case "ArrowFunctionExpression": + return parent.body === node; + case "PrivateName": + return false; + case "ClassMethod": + case "ClassPrivateMethod": + case "ObjectMethod": + if (parent.key === node) { + return !!parent.computed; + } + return false; + case "ObjectProperty": + if (parent.key === node) { + return !!parent.computed; + } + return !grandparent || grandparent.type !== "ObjectPattern"; + case "ClassProperty": + case "ClassAccessorProperty": + if (parent.key === node) { + return !!parent.computed; + } + return true; + case "ClassPrivateProperty": + return parent.key !== node; + case "ClassDeclaration": + case "ClassExpression": + return parent.superClass === node; + case "AssignmentExpression": + return parent.right === node; + case "AssignmentPattern": + return parent.right === node; + case "LabeledStatement": + return false; + case "CatchClause": + return false; + case "RestElement": + return false; + case "BreakStatement": + case "ContinueStatement": + return false; + case "FunctionDeclaration": + case "FunctionExpression": + return false; + case "ExportNamespaceSpecifier": + case "ExportDefaultSpecifier": + return false; + case "ExportSpecifier": + if (grandparent != null && grandparent.source) { + return false; + } + return parent.local === node; + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + return false; + case "ImportAttribute": + return false; + case "JSXAttribute": + return false; + case "ObjectPattern": + case "ArrayPattern": + return false; + case "MetaProperty": + return false; + case "ObjectTypeProperty": + return parent.key !== node; + case "TSEnumMember": + return parent.id !== node; + case "TSPropertySignature": + if (parent.key === node) { + return !!parent.computed; + } + return true; + } + return true; + } + + + return isReferenced; +} + +var isScope = {}; + +var hasRequiredIsScope; + +function requireIsScope () { + if (hasRequiredIsScope) return isScope; + hasRequiredIsScope = 1; + + Object.defineProperty(isScope, "__esModule", { + value: true + }); + isScope.default = isScope$1; + var _index = requireGenerated$3(); + function isScope$1(node, parent) { + if ((0, _index.isBlockStatement)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) { + return false; + } + if ((0, _index.isPattern)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) { + return true; + } + return (0, _index.isScopable)(node); + } + + + return isScope; +} + +var isSpecifierDefault = {}; + +var hasRequiredIsSpecifierDefault; + +function requireIsSpecifierDefault () { + if (hasRequiredIsSpecifierDefault) return isSpecifierDefault; + hasRequiredIsSpecifierDefault = 1; + + Object.defineProperty(isSpecifierDefault, "__esModule", { + value: true + }); + isSpecifierDefault.default = isSpecifierDefault$1; + var _index = requireGenerated$3(); + function isSpecifierDefault$1(specifier) { + return (0, _index.isImportDefaultSpecifier)(specifier) || (0, _index.isIdentifier)(specifier.imported || specifier.exported, { + name: "default" + }); + } + + + return isSpecifierDefault; +} + +var isValidES3Identifier = {}; + +var hasRequiredIsValidES3Identifier; + +function requireIsValidES3Identifier () { + if (hasRequiredIsValidES3Identifier) return isValidES3Identifier; + hasRequiredIsValidES3Identifier = 1; + + Object.defineProperty(isValidES3Identifier, "__esModule", { + value: true + }); + isValidES3Identifier.default = isValidES3Identifier$1; + var _isValidIdentifier = requireIsValidIdentifier(); + const RESERVED_WORDS_ES3_ONLY = new Set(["abstract", "boolean", "byte", "char", "double", "enum", "final", "float", "goto", "implements", "int", "interface", "long", "native", "package", "private", "protected", "public", "short", "static", "synchronized", "throws", "transient", "volatile"]); + function isValidES3Identifier$1(name) { + return (0, _isValidIdentifier.default)(name) && !RESERVED_WORDS_ES3_ONLY.has(name); + } + + + return isValidES3Identifier; +} + +var isVar = {}; + +var hasRequiredIsVar; + +function requireIsVar () { + if (hasRequiredIsVar) return isVar; + hasRequiredIsVar = 1; + + Object.defineProperty(isVar, "__esModule", { + value: true + }); + isVar.default = isVar$1; + var _index = requireGenerated$3(); + var _index2 = requireConstants(); + function isVar$1(node) { + return (0, _index.isVariableDeclaration)(node, { + kind: "var" + }) && !node[_index2.BLOCK_SCOPED_SYMBOL]; + } + + + return isVar; +} + +var toSequenceExpression = {}; + +var gatherSequenceExpressions = {}; + +var hasRequiredGatherSequenceExpressions; + +function requireGatherSequenceExpressions () { + if (hasRequiredGatherSequenceExpressions) return gatherSequenceExpressions; + hasRequiredGatherSequenceExpressions = 1; + + Object.defineProperty(gatherSequenceExpressions, "__esModule", { + value: true + }); + gatherSequenceExpressions.default = gatherSequenceExpressions$1; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + var _productions = requireProductions(); + var _cloneNode = requireCloneNode(); + function gatherSequenceExpressions$1(nodes, declars) { + const exprs = []; + let ensureLastUndefined = true; + for (const node of nodes) { + if (!(0, _index.isEmptyStatement)(node)) { + ensureLastUndefined = false; + } + if ((0, _index.isExpression)(node)) { + exprs.push(node); + } else if ((0, _index.isExpressionStatement)(node)) { + exprs.push(node.expression); + } else if ((0, _index.isVariableDeclaration)(node)) { + if (node.kind !== "var") return; + for (const declar of node.declarations) { + const bindings = (0, _getBindingIdentifiers.default)(declar); + for (const key of Object.keys(bindings)) { + declars.push({ + kind: node.kind, + id: (0, _cloneNode.default)(bindings[key]) + }); + } + if (declar.init) { + exprs.push((0, _index2.assignmentExpression)("=", declar.id, declar.init)); + } + } + ensureLastUndefined = true; + } else if ((0, _index.isIfStatement)(node)) { + const consequent = node.consequent ? gatherSequenceExpressions$1([node.consequent], declars) : (0, _productions.buildUndefinedNode)(); + const alternate = node.alternate ? gatherSequenceExpressions$1([node.alternate], declars) : (0, _productions.buildUndefinedNode)(); + if (!consequent || !alternate) return; + exprs.push((0, _index2.conditionalExpression)(node.test, consequent, alternate)); + } else if ((0, _index.isBlockStatement)(node)) { + const body = gatherSequenceExpressions$1(node.body, declars); + if (!body) return; + exprs.push(body); + } else if ((0, _index.isEmptyStatement)(node)) { + if (nodes.indexOf(node) === 0) { + ensureLastUndefined = true; + } + } else { + return; + } + } + if (ensureLastUndefined) { + exprs.push((0, _productions.buildUndefinedNode)()); + } + if (exprs.length === 1) { + return exprs[0]; + } else { + return (0, _index2.sequenceExpression)(exprs); + } + } + + + return gatherSequenceExpressions; +} + +var hasRequiredToSequenceExpression; + +function requireToSequenceExpression () { + if (hasRequiredToSequenceExpression) return toSequenceExpression; + hasRequiredToSequenceExpression = 1; + + Object.defineProperty(toSequenceExpression, "__esModule", { + value: true + }); + toSequenceExpression.default = toSequenceExpression$1; + var _gatherSequenceExpressions = requireGatherSequenceExpressions(); + function toSequenceExpression$1(nodes, scope) { + if (!(nodes != null && nodes.length)) return; + const declars = []; + const result = (0, _gatherSequenceExpressions.default)(nodes, declars); + if (!result) return; + for (const declar of declars) { + scope.push(declar); + } + return result; + } + + + return toSequenceExpression; +} + +var hasRequiredLib$1; + +function requireLib$1 () { + if (hasRequiredLib$1) return lib$3; + hasRequiredLib$1 = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var _exportNames = { + react: true, + assertNode: true, + createTypeAnnotationBasedOnTypeof: true, + createUnionTypeAnnotation: true, + createFlowUnionType: true, + createTSUnionType: true, + cloneNode: true, + clone: true, + cloneDeep: true, + cloneDeepWithoutLoc: true, + cloneWithoutLoc: true, + addComment: true, + addComments: true, + inheritInnerComments: true, + inheritLeadingComments: true, + inheritsComments: true, + inheritTrailingComments: true, + removeComments: true, + ensureBlock: true, + toBindingIdentifierName: true, + toBlock: true, + toComputedKey: true, + toExpression: true, + toIdentifier: true, + toKeyAlias: true, + toStatement: true, + valueToNode: true, + appendToMemberExpression: true, + inherits: true, + prependToMemberExpression: true, + removeProperties: true, + removePropertiesDeep: true, + removeTypeDuplicates: true, + getAssignmentIdentifiers: true, + getBindingIdentifiers: true, + getOuterBindingIdentifiers: true, + getFunctionName: true, + traverse: true, + traverseFast: true, + shallowEqual: true, + is: true, + isBinding: true, + isBlockScoped: true, + isImmutable: true, + isLet: true, + isNode: true, + isNodesEquivalent: true, + isPlaceholderType: true, + isReferenced: true, + isScope: true, + isSpecifierDefault: true, + isType: true, + isValidES3Identifier: true, + isValidIdentifier: true, + isVar: true, + matchesPattern: true, + validate: true, + buildMatchMemberExpression: true, + __internal__deprecationWarning: true + }; + Object.defineProperty(exports, "__internal__deprecationWarning", { + enumerable: true, + get: function () { + return _deprecationWarning.default; + } + }); + Object.defineProperty(exports, "addComment", { + enumerable: true, + get: function () { + return _addComment.default; + } + }); + Object.defineProperty(exports, "addComments", { + enumerable: true, + get: function () { + return _addComments.default; + } + }); + Object.defineProperty(exports, "appendToMemberExpression", { + enumerable: true, + get: function () { + return _appendToMemberExpression.default; + } + }); + Object.defineProperty(exports, "assertNode", { + enumerable: true, + get: function () { + return _assertNode.default; + } + }); + Object.defineProperty(exports, "buildMatchMemberExpression", { + enumerable: true, + get: function () { + return _buildMatchMemberExpression.default; + } + }); + Object.defineProperty(exports, "clone", { + enumerable: true, + get: function () { + return _clone.default; + } + }); + Object.defineProperty(exports, "cloneDeep", { + enumerable: true, + get: function () { + return _cloneDeep.default; + } + }); + Object.defineProperty(exports, "cloneDeepWithoutLoc", { + enumerable: true, + get: function () { + return _cloneDeepWithoutLoc.default; + } + }); + Object.defineProperty(exports, "cloneNode", { + enumerable: true, + get: function () { + return _cloneNode.default; + } + }); + Object.defineProperty(exports, "cloneWithoutLoc", { + enumerable: true, + get: function () { + return _cloneWithoutLoc.default; + } + }); + Object.defineProperty(exports, "createFlowUnionType", { + enumerable: true, + get: function () { + return _createFlowUnionType.default; + } + }); + Object.defineProperty(exports, "createTSUnionType", { + enumerable: true, + get: function () { + return _createTSUnionType.default; + } + }); + Object.defineProperty(exports, "createTypeAnnotationBasedOnTypeof", { + enumerable: true, + get: function () { + return _createTypeAnnotationBasedOnTypeof.default; + } + }); + Object.defineProperty(exports, "createUnionTypeAnnotation", { + enumerable: true, + get: function () { + return _createFlowUnionType.default; + } + }); + Object.defineProperty(exports, "ensureBlock", { + enumerable: true, + get: function () { + return _ensureBlock.default; + } + }); + Object.defineProperty(exports, "getAssignmentIdentifiers", { + enumerable: true, + get: function () { + return _getAssignmentIdentifiers.default; + } + }); + Object.defineProperty(exports, "getBindingIdentifiers", { + enumerable: true, + get: function () { + return _getBindingIdentifiers.default; + } + }); + Object.defineProperty(exports, "getFunctionName", { + enumerable: true, + get: function () { + return _getFunctionName.default; + } + }); + Object.defineProperty(exports, "getOuterBindingIdentifiers", { + enumerable: true, + get: function () { + return _getOuterBindingIdentifiers.default; + } + }); + Object.defineProperty(exports, "inheritInnerComments", { + enumerable: true, + get: function () { + return _inheritInnerComments.default; + } + }); + Object.defineProperty(exports, "inheritLeadingComments", { + enumerable: true, + get: function () { + return _inheritLeadingComments.default; + } + }); + Object.defineProperty(exports, "inheritTrailingComments", { + enumerable: true, + get: function () { + return _inheritTrailingComments.default; + } + }); + Object.defineProperty(exports, "inherits", { + enumerable: true, + get: function () { + return _inherits.default; + } + }); + Object.defineProperty(exports, "inheritsComments", { + enumerable: true, + get: function () { + return _inheritsComments.default; + } + }); + Object.defineProperty(exports, "is", { + enumerable: true, + get: function () { + return _is.default; + } + }); + Object.defineProperty(exports, "isBinding", { + enumerable: true, + get: function () { + return _isBinding.default; + } + }); + Object.defineProperty(exports, "isBlockScoped", { + enumerable: true, + get: function () { + return _isBlockScoped.default; + } + }); + Object.defineProperty(exports, "isImmutable", { + enumerable: true, + get: function () { + return _isImmutable.default; + } + }); + Object.defineProperty(exports, "isLet", { + enumerable: true, + get: function () { + return _isLet.default; + } + }); + Object.defineProperty(exports, "isNode", { + enumerable: true, + get: function () { + return _isNode.default; + } + }); + Object.defineProperty(exports, "isNodesEquivalent", { + enumerable: true, + get: function () { + return _isNodesEquivalent.default; + } + }); + Object.defineProperty(exports, "isPlaceholderType", { + enumerable: true, + get: function () { + return _isPlaceholderType.default; + } + }); + Object.defineProperty(exports, "isReferenced", { + enumerable: true, + get: function () { + return _isReferenced.default; + } + }); + Object.defineProperty(exports, "isScope", { + enumerable: true, + get: function () { + return _isScope.default; + } + }); + Object.defineProperty(exports, "isSpecifierDefault", { + enumerable: true, + get: function () { + return _isSpecifierDefault.default; + } + }); + Object.defineProperty(exports, "isType", { + enumerable: true, + get: function () { + return _isType.default; + } + }); + Object.defineProperty(exports, "isValidES3Identifier", { + enumerable: true, + get: function () { + return _isValidES3Identifier.default; + } + }); + Object.defineProperty(exports, "isValidIdentifier", { + enumerable: true, + get: function () { + return _isValidIdentifier.default; + } + }); + Object.defineProperty(exports, "isVar", { + enumerable: true, + get: function () { + return _isVar.default; + } + }); + Object.defineProperty(exports, "matchesPattern", { + enumerable: true, + get: function () { + return _matchesPattern.default; + } + }); + Object.defineProperty(exports, "prependToMemberExpression", { + enumerable: true, + get: function () { + return _prependToMemberExpression.default; + } + }); + exports.react = void 0; + Object.defineProperty(exports, "removeComments", { + enumerable: true, + get: function () { + return _removeComments.default; + } + }); + Object.defineProperty(exports, "removeProperties", { + enumerable: true, + get: function () { + return _removeProperties.default; + } + }); + Object.defineProperty(exports, "removePropertiesDeep", { + enumerable: true, + get: function () { + return _removePropertiesDeep.default; + } + }); + Object.defineProperty(exports, "removeTypeDuplicates", { + enumerable: true, + get: function () { + return _removeTypeDuplicates.default; + } + }); + Object.defineProperty(exports, "shallowEqual", { + enumerable: true, + get: function () { + return _shallowEqual.default; + } + }); + Object.defineProperty(exports, "toBindingIdentifierName", { + enumerable: true, + get: function () { + return _toBindingIdentifierName.default; + } + }); + Object.defineProperty(exports, "toBlock", { + enumerable: true, + get: function () { + return _toBlock.default; + } + }); + Object.defineProperty(exports, "toComputedKey", { + enumerable: true, + get: function () { + return _toComputedKey.default; + } + }); + Object.defineProperty(exports, "toExpression", { + enumerable: true, + get: function () { + return _toExpression.default; + } + }); + Object.defineProperty(exports, "toIdentifier", { + enumerable: true, + get: function () { + return _toIdentifier.default; + } + }); + Object.defineProperty(exports, "toKeyAlias", { + enumerable: true, + get: function () { + return _toKeyAlias.default; + } + }); + Object.defineProperty(exports, "toStatement", { + enumerable: true, + get: function () { + return _toStatement.default; + } + }); + Object.defineProperty(exports, "traverse", { + enumerable: true, + get: function () { + return _traverse.default; + } + }); + Object.defineProperty(exports, "traverseFast", { + enumerable: true, + get: function () { + return _traverseFast.default; + } + }); + Object.defineProperty(exports, "validate", { + enumerable: true, + get: function () { + return _validate.default; + } + }); + Object.defineProperty(exports, "valueToNode", { + enumerable: true, + get: function () { + return _valueToNode.default; + } + }); + var _isReactComponent = requireIsReactComponent(); + var _isCompatTag = requireIsCompatTag(); + var _buildChildren = requireBuildChildren(); + var _assertNode = requireAssertNode(); + var _index = requireGenerated$1(); + Object.keys(_index).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index[key]; + } + }); + }); + var _createTypeAnnotationBasedOnTypeof = requireCreateTypeAnnotationBasedOnTypeof(); + var _createFlowUnionType = requireCreateFlowUnionType(); + var _createTSUnionType = requireCreateTSUnionType(); + var _index2 = requireGenerated$2(); + Object.keys(_index2).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index2[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index2[key]; + } + }); + }); + var _uppercase = requireUppercase(); + Object.keys(_uppercase).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _uppercase[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _uppercase[key]; + } + }); + }); + var _productions = requireProductions(); + Object.keys(_productions).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _productions[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _productions[key]; + } + }); + }); + var _cloneNode = requireCloneNode(); + var _clone = requireClone(); + var _cloneDeep = requireCloneDeep(); + var _cloneDeepWithoutLoc = requireCloneDeepWithoutLoc(); + var _cloneWithoutLoc = requireCloneWithoutLoc(); + var _addComment = requireAddComment(); + var _addComments = requireAddComments(); + var _inheritInnerComments = requireInheritInnerComments(); + var _inheritLeadingComments = requireInheritLeadingComments(); + var _inheritsComments = requireInheritsComments(); + var _inheritTrailingComments = requireInheritTrailingComments(); + var _removeComments = requireRemoveComments(); + var _index3 = requireGenerated(); + Object.keys(_index3).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index3[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index3[key]; + } + }); + }); + var _index4 = requireConstants(); + Object.keys(_index4).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index4[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index4[key]; + } + }); + }); + var _ensureBlock = requireEnsureBlock(); + var _toBindingIdentifierName = requireToBindingIdentifierName(); + var _toBlock = requireToBlock(); + var _toComputedKey = requireToComputedKey(); + var _toExpression = requireToExpression(); + var _toIdentifier = requireToIdentifier(); + var _toKeyAlias = requireToKeyAlias(); + var _toStatement = requireToStatement(); + var _valueToNode = requireValueToNode(); + var _index5 = requireDefinitions(); + Object.keys(_index5).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index5[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index5[key]; + } + }); + }); + var _appendToMemberExpression = requireAppendToMemberExpression(); + var _inherits = requireInherits(); + var _prependToMemberExpression = requirePrependToMemberExpression(); + var _removeProperties = requireRemoveProperties(); + var _removePropertiesDeep = requireRemovePropertiesDeep(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates$1(); + var _getAssignmentIdentifiers = requireGetAssignmentIdentifiers(); + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + var _getOuterBindingIdentifiers = requireGetOuterBindingIdentifiers(); + var _getFunctionName = requireGetFunctionName(); + var _traverse = requireTraverse(); + Object.keys(_traverse).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _traverse[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _traverse[key]; + } + }); + }); + var _traverseFast = requireTraverseFast(); + var _shallowEqual = requireShallowEqual(); + var _is = requireIs(); + var _isBinding = requireIsBinding(); + var _isBlockScoped = requireIsBlockScoped(); + var _isImmutable = requireIsImmutable(); + var _isLet = requireIsLet(); + var _isNode = requireIsNode(); + var _isNodesEquivalent = requireIsNodesEquivalent(); + var _isPlaceholderType = requireIsPlaceholderType(); + var _isReferenced = requireIsReferenced(); + var _isScope = requireIsScope(); + var _isSpecifierDefault = requireIsSpecifierDefault(); + var _isType = requireIsType(); + var _isValidES3Identifier = requireIsValidES3Identifier(); + var _isValidIdentifier = requireIsValidIdentifier(); + var _isVar = requireIsVar(); + var _matchesPattern = requireMatchesPattern(); + var _validate = requireValidate(); + var _buildMatchMemberExpression = requireBuildMatchMemberExpression(); + var _index6 = requireGenerated$3(); + Object.keys(_index6).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index6[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index6[key]; + } + }); + }); + var _deprecationWarning = requireDeprecationWarning(); + exports.react = { + isReactComponent: _isReactComponent.default, + isCompatTag: _isCompatTag.default, + buildChildren: _buildChildren.default + }; + { + exports.toSequenceExpression = requireToSequenceExpression().default; + } + if (process.env.BABEL_TYPES_8_BREAKING) { + console.warn("BABEL_TYPES_8_BREAKING is not supported anymore. Use the latest Babel 8.0.0 pre-release instead!"); + } + + +} (lib$3)); + return lib$3; +} + +var libExports$1 = requireLib$1(); + +function Ok(val) { + return new OkImpl(val); +} +class OkImpl { + constructor(val) { + this.val = val; + } + map(fn) { + return new OkImpl(fn(this.val)); + } + mapErr(_fn) { + return this; + } + mapOr(_fallback, fn) { + return fn(this.val); + } + mapOrElse(_fallback, fn) { + return fn(this.val); + } + andThen(fn) { + return fn(this.val); + } + and(res) { + return res; + } + or(_res) { + return this; + } + orElse(_fn) { + return this; + } + isOk() { + return true; + } + isErr() { + return false; + } + expect(_msg) { + return this.val; + } + expectErr(msg) { + throw new Error(`${msg}: ${this.val}`); + } + unwrap() { + return this.val; + } + unwrapOr(_fallback) { + return this.val; + } + unwrapOrElse(_fallback) { + return this.val; + } + unwrapErr() { + if (this.val instanceof Error) { + throw this.val; + } + throw new Error(`Can't unwrap \`Ok\` to \`Err\`: ${this.val}`); + } +} +function Err(val) { + return new ErrImpl(val); +} +class ErrImpl { + constructor(val) { + this.val = val; + } + map(_fn) { + return this; + } + mapErr(fn) { + return new ErrImpl(fn(this.val)); + } + mapOr(fallback, _fn) { + return fallback; + } + mapOrElse(fallback, _fn) { + return fallback(); + } + andThen(_fn) { + return this; + } + and(_res) { + return this; + } + or(res) { + return res; + } + orElse(fn) { + return fn(this.val); + } + isOk() { + return false; + } + isErr() { + return true; + } + expect(msg) { + throw new Error(`${msg}: ${this.val}`); + } + expectErr(_msg) { + return this.val; + } + unwrap() { + if (this.val instanceof Error) { + throw this.val; + } + throw new Error(`Can't unwrap \`Err\` to \`Ok\`: ${this.val}`); + } + unwrapOr(fallback) { + return fallback; + } + unwrapOrElse(fallback) { + return fallback(this.val); + } + unwrapErr() { + return this.val; + } +} + +function assertExhaustive$1(_, errorMsg) { + throw new Error(errorMsg); +} +function retainWhere(array, predicate) { + let writeIndex = 0; + for (let readIndex = 0; readIndex < array.length; readIndex++) { + const item = array[readIndex]; + if (predicate(item) === true) { + array[writeIndex++] = item; + } + } + array.length = writeIndex; +} +function retainWhere_Set(items, predicate) { + for (const item of items) { + if (!predicate(item)) { + items.delete(item); + } + } +} +function getOrInsertWith(m, key, makeDefault) { + if (m.has(key)) { + return m.get(key); + } + else { + const defaultValue = makeDefault(); + m.set(key, defaultValue); + return defaultValue; + } +} +function getOrInsertDefault(m, key, defaultValue) { + if (m.has(key)) { + return m.get(key); + } + else { + m.set(key, defaultValue); + return defaultValue; + } +} +function Set_equal(a, b) { + if (a.size !== b.size) { + return false; + } + for (const item of a) { + if (!b.has(item)) { + return false; + } + } + return true; +} +function Set_union(a, b) { + const union = new Set(a); + for (const item of b) { + union.add(item); + } + return union; +} +function Set_intersect(sets) { + if (sets.length === 0 || sets.some(s => s.size === 0)) { + return new Set(); + } + else if (sets.length === 1) { + return new Set(sets[0]); + } + const result = new Set(); + const first = sets[0]; + outer: for (const e of first) { + for (let i = 1; i < sets.length; i++) { + if (!sets[i].has(e)) { + continue outer; + } + } + result.add(e); + } + return result; +} +function Iterable_some(iter, pred) { + for (const item of iter) { + if (pred(item)) { + return true; + } + } + return false; +} +function Set_filter(source, fn) { + const result = new Set(); + for (const entry of source) { + if (fn(entry)) { + result.add(entry); + } + } + return result; +} +function hasNode(input) { + return input.node != null; +} +function hasOwnProperty$1(obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key); +} + +var ErrorSeverity; +(function (ErrorSeverity) { + ErrorSeverity["InvalidJS"] = "InvalidJS"; + ErrorSeverity["InvalidReact"] = "InvalidReact"; + ErrorSeverity["InvalidConfig"] = "InvalidConfig"; + ErrorSeverity["CannotPreserveMemoization"] = "CannotPreserveMemoization"; + ErrorSeverity["Todo"] = "Todo"; + ErrorSeverity["Invariant"] = "Invariant"; +})(ErrorSeverity || (ErrorSeverity = {})); +var CompilerSuggestionOperation; +(function (CompilerSuggestionOperation) { + CompilerSuggestionOperation[CompilerSuggestionOperation["InsertBefore"] = 0] = "InsertBefore"; + CompilerSuggestionOperation[CompilerSuggestionOperation["InsertAfter"] = 1] = "InsertAfter"; + CompilerSuggestionOperation[CompilerSuggestionOperation["Remove"] = 2] = "Remove"; + CompilerSuggestionOperation[CompilerSuggestionOperation["Replace"] = 3] = "Replace"; +})(CompilerSuggestionOperation || (CompilerSuggestionOperation = {})); +class CompilerErrorDetail { + constructor(options) { + this.options = options; + } + get reason() { + return this.options.reason; + } + get description() { + return this.options.description; + } + get severity() { + return this.options.severity; + } + get loc() { + return this.options.loc; + } + get suggestions() { + return this.options.suggestions; + } + printErrorMessage() { + const buffer = [`${this.severity}: ${this.reason}`]; + if (this.description != null) { + buffer.push(`. ${this.description}`); + } + if (this.loc != null && typeof this.loc !== 'symbol') { + buffer.push(` (${this.loc.start.line}:${this.loc.end.line})`); + } + return buffer.join(''); + } + toString() { + return this.printErrorMessage(); + } +} +class CompilerError extends Error { + static invariant(condition, options) { + if (!condition) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.Invariant }))); + throw errors; + } + } + static throwTodo(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.Todo }))); + throw errors; + } + static throwInvalidJS(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidJS }))); + throw errors; + } + static throwInvalidReact(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidReact }))); + throw errors; + } + static throwInvalidConfig(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidConfig }))); + throw errors; + } + static throw(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(options)); + throw errors; + } + constructor(...args) { + super(...args); + this.details = []; + this.name = 'ReactCompilerError'; + this.details = []; + } + get message() { + return this.toString(); + } + set message(_message) { } + toString() { + if (Array.isArray(this.details)) { + return this.details.map(detail => detail.toString()).join('\n\n'); + } + return this.name; + } + push(options) { + var _a; + const detail = new CompilerErrorDetail({ + reason: options.reason, + description: (_a = options.description) !== null && _a !== void 0 ? _a : null, + severity: options.severity, + suggestions: options.suggestions, + loc: typeof options.loc === 'symbol' ? null : options.loc, + }); + return this.pushErrorDetail(detail); + } + pushErrorDetail(detail) { + this.details.push(detail); + return detail; + } + hasErrors() { + return this.details.length > 0; + } + asResult() { + return this.hasErrors() ? Err(this) : Ok(undefined); + } + isCritical() { + return this.details.some(detail => { + switch (detail.severity) { + case ErrorSeverity.Invariant: + case ErrorSeverity.InvalidJS: + case ErrorSeverity.InvalidReact: + case ErrorSeverity.InvalidConfig: + return true; + case ErrorSeverity.CannotPreserveMemoization: + case ErrorSeverity.Todo: + return false; + default: + assertExhaustive$1(detail.severity, 'Unhandled error severity'); + } + }); + } +} + +function insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingFunctionIdentifierName) { + var _a, _b; + const originalFnName = fnPath.node.id; + const originalFnParams = fnPath.node.params; + const compiledParams = fnPath.node.params; + CompilerError.invariant(originalFnName != null && compiled.id != null, { + reason: 'Expected function declarations that are referenced elsewhere to have a named identifier', + loc: (_a = fnPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + CompilerError.invariant(originalFnParams.length === compiledParams.length, { + reason: 'Expected React Compiler optimized function declarations to have the same number of parameters as source', + loc: (_b = fnPath.node.loc) !== null && _b !== void 0 ? _b : null, + }); + const gatingCondition = libExports$1.identifier(programContext.newUid(`${gatingFunctionIdentifierName}_result`)); + const unoptimizedFnName = libExports$1.identifier(programContext.newUid(`${originalFnName.name}_unoptimized`)); + const optimizedFnName = libExports$1.identifier(programContext.newUid(`${originalFnName.name}_optimized`)); + compiled.id.name = optimizedFnName.name; + fnPath.get('id').replaceInline(unoptimizedFnName); + const newParams = []; + const genNewArgs = []; + for (let i = 0; i < originalFnParams.length; i++) { + const argName = `arg${i}`; + if (originalFnParams[i].type === 'RestElement') { + newParams.push(libExports$1.restElement(libExports$1.identifier(argName))); + genNewArgs.push(() => libExports$1.spreadElement(libExports$1.identifier(argName))); + } + else { + newParams.push(libExports$1.identifier(argName)); + genNewArgs.push(() => libExports$1.identifier(argName)); + } + } + fnPath.insertAfter(libExports$1.functionDeclaration(originalFnName, newParams, libExports$1.blockStatement([ + libExports$1.ifStatement(gatingCondition, libExports$1.returnStatement(libExports$1.callExpression(compiled.id, genNewArgs.map(fn => fn()))), libExports$1.returnStatement(libExports$1.callExpression(unoptimizedFnName, genNewArgs.map(fn => fn())))), + ]))); + fnPath.insertBefore(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(gatingCondition, libExports$1.callExpression(libExports$1.identifier(gatingFunctionIdentifierName), [])), + ])); + fnPath.insertBefore(compiled); +} +function insertGatedFunctionDeclaration(fnPath, compiled, programContext, gating, referencedBeforeDeclaration) { + var _a; + const gatingImportedName = programContext.addImportSpecifier(gating).name; + if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) { + CompilerError.invariant(compiled.type === 'FunctionDeclaration', { + reason: 'Expected compiled node type to match input type', + description: `Got ${compiled.type} but expected FunctionDeclaration`, + loc: (_a = fnPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingImportedName); + } + else { + const gatingExpression = libExports$1.conditionalExpression(libExports$1.callExpression(libExports$1.identifier(gatingImportedName), []), buildFunctionExpression(compiled), buildFunctionExpression(fnPath.node)); + if (fnPath.parentPath.node.type !== 'ExportDefaultDeclaration' && + fnPath.node.type === 'FunctionDeclaration' && + fnPath.node.id != null) { + fnPath.replaceWith(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(fnPath.node.id, gatingExpression), + ])); + } + else if (fnPath.parentPath.node.type === 'ExportDefaultDeclaration' && + fnPath.node.type !== 'ArrowFunctionExpression' && + fnPath.node.id != null) { + fnPath.insertAfter(libExports$1.exportDefaultDeclaration(libExports$1.identifier(fnPath.node.id.name))); + fnPath.parentPath.replaceWith(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(libExports$1.identifier(fnPath.node.id.name), gatingExpression), + ])); + } + else { + fnPath.replaceWith(gatingExpression); + } + } +} +function buildFunctionExpression(node) { + var _a, _b; + if (node.type === 'ArrowFunctionExpression' || + node.type === 'FunctionExpression') { + return node; + } + else { + const fn = { + type: 'FunctionExpression', + async: node.async, + generator: node.generator, + loc: (_a = node.loc) !== null && _a !== void 0 ? _a : null, + id: (_b = node.id) !== null && _b !== void 0 ? _b : null, + params: node.params, + body: node.body, + }; + return fn; + } +} + +function makeTypeId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected instruction id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +let typeCounter = 0; +function makeType() { + return { + kind: 'Type', + id: makeTypeId(typeCounter++), + }; +} +function typeEquals(tA, tB) { + if (tA.kind !== tB.kind) + return false; + return (typeVarEquals(tA, tB) || + funcTypeEquals(tA, tB) || + objectTypeEquals(tA, tB) || + primitiveTypeEquals(tA, tB) || + polyTypeEquals(tA, tB) || + phiTypeEquals(tA, tB) || + propTypeEquals(tA, tB) || + objectMethodTypeEquals(tA, tB)); +} +function typeVarEquals(tA, tB) { + if (tA.kind === 'Type' && tB.kind === 'Type') { + return tA.id === tB.id; + } + return false; +} +function typeKindCheck(tA, tb, type) { + return tA.kind === type && tb.kind === type; +} +function objectMethodTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'ObjectMethod'); +} +function propTypeEquals(tA, tB) { + if (tA.kind === 'Property' && tB.kind === 'Property') { + if (!typeEquals(tA.objectType, tB.objectType)) { + return false; + } + return (tA.propertyName === tB.propertyName && tA.objectName === tB.objectName); + } + return false; +} +function primitiveTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'Primitive'); +} +function polyTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'Poly'); +} +function objectTypeEquals(tA, tB) { + if (tA.kind === 'Object' && tB.kind == 'Object') { + return tA.shapeId === tB.shapeId; + } + return false; +} +function funcTypeEquals(tA, tB) { + if (tA.kind !== 'Function' || tB.kind !== 'Function') { + return false; + } + return typeEquals(tA.return, tB.return); +} +function phiTypeEquals(tA, tB) { + if (tA.kind === 'Phi' && tB.kind === 'Phi') { + if (tA.operands.length !== tB.operands.length) { + return false; + } + let operands = new Set(tA.operands); + for (let i = 0; i < tB.operands.length; i++) { + if (!operands.has(tB.operands[i])) { + return false; + } + } + } + return false; +} + +const GeneratedSource = Symbol(); +function isStatementBlockKind(kind) { + return kind === 'block' || kind === 'catch'; +} +function isExpressionBlockKind(kind) { + return !isStatementBlockKind(kind); +} +var GotoVariant; +(function (GotoVariant) { + GotoVariant["Break"] = "Break"; + GotoVariant["Continue"] = "Continue"; + GotoVariant["Try"] = "Try"; +})(GotoVariant || (GotoVariant = {})); +var InstructionKind; +(function (InstructionKind) { + InstructionKind["Const"] = "Const"; + InstructionKind["Let"] = "Let"; + InstructionKind["Reassign"] = "Reassign"; + InstructionKind["Catch"] = "Catch"; + InstructionKind["HoistedConst"] = "HoistedConst"; + InstructionKind["HoistedLet"] = "HoistedLet"; + InstructionKind["HoistedFunction"] = "HoistedFunction"; + InstructionKind["Function"] = "Function"; +})(InstructionKind || (InstructionKind = {})); +function convertHoistedLValueKind(kind) { + switch (kind) { + case InstructionKind.HoistedLet: + return InstructionKind.Let; + case InstructionKind.HoistedConst: + return InstructionKind.Const; + case InstructionKind.HoistedFunction: + return InstructionKind.Function; + case InstructionKind.Let: + case InstructionKind.Const: + case InstructionKind.Function: + case InstructionKind.Reassign: + case InstructionKind.Catch: + return null; + default: + assertExhaustive$1(kind, 'Unexpected lvalue kind'); + } +} +function makeTemporaryIdentifier(id, loc) { + return { + id, + name: null, + declarationId: makeDeclarationId(id), + mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) }, + scope: null, + type: makeType(), + loc, + }; +} +function forkTemporaryIdentifier(id, source) { + return Object.assign(Object.assign({}, source), { mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) }, id }); +} +function makeIdentifierName(name) { + CompilerError.invariant(libExports$1.isValidIdentifier(name), { + reason: `Expected a valid identifier name`, + loc: GeneratedSource, + description: `\`${name}\` is not a valid JavaScript identifier`, + suggestions: null, + }); + return { + kind: 'named', + value: name, + }; +} +function promoteTemporary(identifier) { + CompilerError.invariant(identifier.name === null, { + reason: `Expected a temporary (unnamed) identifier`, + loc: GeneratedSource, + description: `Identifier already has a name, \`${identifier.name}\``, + suggestions: null, + }); + identifier.name = { + kind: 'promoted', + value: `#t${identifier.declarationId}`, + }; +} +function isPromotedTemporary(name) { + return name.startsWith('#t'); +} +function promoteTemporaryJsxTag(identifier) { + CompilerError.invariant(identifier.name === null, { + reason: `Expected a temporary (unnamed) identifier`, + loc: GeneratedSource, + description: `Identifier already has a name, \`${identifier.name}\``, + suggestions: null, + }); + identifier.name = { + kind: 'promoted', + value: `#T${identifier.declarationId}`, + }; +} +function isPromotedJsxTemporary(name) { + return name.startsWith('#T'); +} +var ValueReason; +(function (ValueReason) { + ValueReason["Global"] = "global"; + ValueReason["JsxCaptured"] = "jsx-captured"; + ValueReason["KnownReturnSignature"] = "known-return-signature"; + ValueReason["Context"] = "context"; + ValueReason["State"] = "state"; + ValueReason["ReducerState"] = "reducer-state"; + ValueReason["ReactiveFunctionArgument"] = "reactive-function-argument"; + ValueReason["Other"] = "other"; +})(ValueReason || (ValueReason = {})); +var ValueKind; +(function (ValueKind) { + ValueKind["MaybeFrozen"] = "maybefrozen"; + ValueKind["Frozen"] = "frozen"; + ValueKind["Primitive"] = "primitive"; + ValueKind["Global"] = "global"; + ValueKind["Mutable"] = "mutable"; + ValueKind["Context"] = "context"; +})(ValueKind || (ValueKind = {})); +const ValueKindSchema = zod.z.enum([ + ValueKind.MaybeFrozen, + ValueKind.Frozen, + ValueKind.Primitive, + ValueKind.Global, + ValueKind.Mutable, + ValueKind.Context, +]); +var Effect; +(function (Effect) { + Effect["Unknown"] = ""; + Effect["Freeze"] = "freeze"; + Effect["Read"] = "read"; + Effect["Capture"] = "capture"; + Effect["ConditionallyMutateIterator"] = "mutate-iterator?"; + Effect["ConditionallyMutate"] = "mutate?"; + Effect["Mutate"] = "mutate"; + Effect["Store"] = "store"; +})(Effect || (Effect = {})); +const EffectSchema = zod.z.enum([ + Effect.Read, + Effect.Mutate, + Effect.ConditionallyMutate, + Effect.ConditionallyMutateIterator, + Effect.Capture, + Effect.Store, + Effect.Freeze, +]); +function isMutableEffect(effect, location) { + switch (effect) { + case Effect.Capture: + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + return true; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: location, + suggestions: null, + }); + } + case Effect.Read: + case Effect.Freeze: { + return false; + } + default: { + assertExhaustive$1(effect, `Unexpected effect \`${effect}\``); + } + } +} +function makePropertyLiteral(value) { + return value; +} +function areEqualPaths(a, b) { + return (a.length === b.length && + a.every((item, ix) => item.property === b[ix].property && item.optional === b[ix].optional)); +} +function getPlaceScope(id, place) { + const scope = place.identifier.scope; + if (scope !== null && isScopeActive(scope, id)) { + return scope; + } + return null; +} +function isScopeActive(scope, id) { + return id >= scope.range.start && id < scope.range.end; +} +function makeBlockId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected block id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeScopeId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected block id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeIdentifierId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected identifier id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeDeclarationId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected declaration id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeInstructionId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected instruction id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function isObjectMethodType(id) { + return id.type.kind == 'ObjectMethod'; +} +function isObjectType(id) { + return id.type.kind === 'Object'; +} +function isPrimitiveType(id) { + return id.type.kind === 'Primitive'; +} +function isArrayType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInArray'; +} +function isMapType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInMap'; +} +function isSetType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInSet'; +} +function isPropsType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInProps'; +} +function isRefValueType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInRefValue'; +} +function isUseRefType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInUseRefId'; +} +function isUseStateType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInUseState'; +} +function isRefOrRefValue(id) { + return isUseRefType(id) || isRefValueType(id); +} +function isSetStateType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInSetState'; +} +function isStartTransitionType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInStartTransition'); +} +function isSetActionStateType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInSetActionState'); +} +function isUseReducerType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseReducer'; +} +function isDispatcherType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInDispatch'; +} +function isFireFunctionType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInFireFunction'); +} +function isStableType(id) { + return (isSetStateType(id) || + isSetActionStateType(id) || + isDispatcherType(id) || + isUseRefType(id) || + isStartTransitionType(id)); +} +function isStableTypeContainer(id) { + const type_ = id.type; + if (type_.kind !== 'Object') { + return false; + } + return (isUseStateType(id) || + type_.shapeId === 'BuiltInUseActionState' || + isUseReducerType(id) || + type_.shapeId === 'BuiltInUseTransition'); +} +function evaluatesToStableTypeOrContainer(env, { value }) { + if (value.kind === 'CallExpression' || value.kind === 'MethodCall') { + const callee = value.kind === 'CallExpression' ? value.callee : value.property; + const calleeHookKind = getHookKind(env, callee.identifier); + switch (calleeHookKind) { + case 'useState': + case 'useReducer': + case 'useActionState': + case 'useRef': + case 'useTransition': + return true; + } + } + return false; +} +function isUseEffectHookType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseEffectHook'); +} +function isUseLayoutEffectHookType(id) { + return (id.type.kind === 'Function' && + id.type.shapeId === 'BuiltInUseLayoutEffectHook'); +} +function isUseInsertionEffectHookType(id) { + return (id.type.kind === 'Function' && + id.type.shapeId === 'BuiltInUseInsertionEffectHook'); +} +function isUseContextHookType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseContextHook'); +} +function getHookKind(env, id) { + return getHookKindForType(env, id.type); +} +function isUseOperator(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseOperator'); +} +function getHookKindForType(env, type) { + var _a; + if (type.kind === 'Function') { + const signature = env.getFunctionSignature(type); + return (_a = signature === null || signature === void 0 ? void 0 : signature.hookKind) !== null && _a !== void 0 ? _a : null; + } + return null; +} + +var lib = {}; + +var sourceMap$1 = {}; + +var sourceMap = {}; + +var sourceMapGenerator = {}; + +var base64Vlq = {}; + +var base64 = {}; + +var hasRequiredBase64; + +function requireBase64 () { + if (hasRequiredBase64) return base64; + hasRequiredBase64 = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + base64.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + base64.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + return base64; +} + +var hasRequiredBase64Vlq; + +function requireBase64Vlq () { + if (hasRequiredBase64Vlq) return base64Vlq; + hasRequiredBase64Vlq = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + var base64 = requireBase64(); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + base64Vlq.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + return base64Vlq; +} + +var util = {}; + +var hasRequiredUtil; + +function requireUtil () { + if (hasRequiredUtil) return util; + hasRequiredUtil = 1; + (function (exports) { + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port; + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consecutive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + var supportsNullProto = (function () { + var obj = Object.create(null); + return !('__proto__' in obj); + }()); + + function identity (s) { + return s; + } + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + if (isProtoString(aStr)) { + return '$' + aStr; + } + + return aStr; + } + exports.toSetString = supportsNullProto ? identity : toSetString; + + function fromSetString(aStr) { + if (isProtoString(aStr)) { + return aStr.slice(1); + } + + return aStr; + } + exports.fromSetString = supportsNullProto ? identity : fromSetString; + + function isProtoString(s) { + if (!s) { + return false; + } + + var length = s.length; + + if (length < 9 /* "__proto__".length */) { + return false; + } + + if (s.charCodeAt(length - 1) !== 95 /* '_' */ || + s.charCodeAt(length - 2) !== 95 /* '_' */ || + s.charCodeAt(length - 3) !== 111 /* 'o' */ || + s.charCodeAt(length - 4) !== 116 /* 't' */ || + s.charCodeAt(length - 5) !== 111 /* 'o' */ || + s.charCodeAt(length - 6) !== 114 /* 'r' */ || + s.charCodeAt(length - 7) !== 112 /* 'p' */ || + s.charCodeAt(length - 8) !== 95 /* '_' */ || + s.charCodeAt(length - 9) !== 95 /* '_' */) { + return false; + } + + for (var i = length - 10; i >= 0; i--) { + if (s.charCodeAt(i) !== 36 /* '$' */) { + return false; + } + } + + return true; + } + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; +} (util)); + return util; +} + +var arraySet = {}; + +var hasRequiredArraySet; + +function requireArraySet () { + if (hasRequiredArraySet) return arraySet; + hasRequiredArraySet = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + var has = Object.prototype.hasOwnProperty; + var hasNativeMap = typeof Map !== "undefined"; + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = hasNativeMap ? new Map() : Object.create(null); + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = hasNativeMap ? aStr : util.toSetString(aStr); + var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + if (hasNativeMap) { + this._set.set(aStr, idx); + } else { + this._set[sStr] = idx; + } + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + if (hasNativeMap) { + return this._set.has(aStr); + } else { + var sStr = util.toSetString(aStr); + return has.call(this._set, sStr); + } + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + if (hasNativeMap) { + var idx = this._set.get(aStr); + if (idx >= 0) { + return idx; + } + } else { + var sStr = util.toSetString(aStr); + if (has.call(this._set, sStr)) { + return this._set[sStr]; + } + } + + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + arraySet.ArraySet = ArraySet; + return arraySet; +} + +var mappingList = {}; + +var hasRequiredMappingList; + +function requireMappingList () { + if (hasRequiredMappingList) return mappingList; + hasRequiredMappingList = 1; + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + mappingList.MappingList = MappingList; + return mappingList; +} + +var hasRequiredSourceMapGenerator; + +function requireSourceMapGenerator () { + if (hasRequiredSourceMapGenerator) return sourceMapGenerator; + hasRequiredSourceMapGenerator = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var base64VLQ = requireBase64Vlq(); + var util = requireUtil(); + var ArraySet = requireArraySet().ArraySet; + var MappingList = requireMappingList().MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null) { + source = String(source); + if (!this._sources.has(source)) { + this._sources.add(source); + } + } + + if (name != null) { + name = String(name); + if (!this._names.has(name)) { + this._names.add(name); + } + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = Object.create(null); + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source); + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + // When aOriginal is truthy but has empty values for .line and .column, + // it is most likely a programmer error. In this case we throw a very + // specific error message to try to guide them the right way. + // For example: https://github.com/Polymer/polymer-bundler/pull/519 + if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { + throw new Error( + 'original.line and original.column are not numbers -- you probably meant to omit ' + + 'the original mapping entirely and only map the generated position. If so, pass ' + + 'null for the original mapping instead of an object with empty or null values.' + ); + } + + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var next; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + next = ''; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + next += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + next += ','; + } + } + + next += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + next += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + next += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + next += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + next += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + + result += next; + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + sourceMapGenerator.SourceMapGenerator = SourceMapGenerator; + return sourceMapGenerator; +} + +var sourceMapConsumer = {}; + +var binarySearch = {}; + +var hasRequiredBinarySearch; + +function requireBinarySearch () { + if (hasRequiredBinarySearch) return binarySearch; + hasRequiredBinarySearch = 1; + (function (exports) { + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; +} (binarySearch)); + return binarySearch; +} + +var quickSort = {}; + +var hasRequiredQuickSort; + +function requireQuickSort () { + if (hasRequiredQuickSort) return quickSort; + hasRequiredQuickSort = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + quickSort.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + return quickSort; +} + +var hasRequiredSourceMapConsumer; + +function requireSourceMapConsumer () { + if (hasRequiredSourceMapConsumer) return sourceMapConsumer; + hasRequiredSourceMapConsumer = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + var binarySearch = requireBinarySearch(); + var ArraySet = requireArraySet().ArraySet; + var base64VLQ = requireBase64Vlq(); + var quickSort = requireQuickSort().quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + sourceMapConsumer.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + .map(String) + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names.map(String), true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[j]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.generatedColumn + + (section.generatedOffset.generatedLine === mapping.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + return sourceMapConsumer; +} + +var sourceNode = {}; + +var hasRequiredSourceNode; + +function requireSourceNode () { + if (hasRequiredSourceNode) return sourceNode; + hasRequiredSourceNode = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator; + var util = requireUtil(); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are accessed by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var remainingLinesIndex = 0; + var shiftNextLine = function() { + var lineContents = getNextLine(); + // The last line of a file might not have a newline. + var newLine = getNextLine() || ""; + return lineContents + newLine; + + function getNextLine() { + return remainingLinesIndex < remainingLines.length ? + remainingLines[remainingLinesIndex++] : undefined; + } + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[remainingLinesIndex]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[remainingLinesIndex]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLinesIndex < remainingLines.length) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.splice(remainingLinesIndex).join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + sourceNode.SourceNode = SourceNode; + return sourceNode; +} + +var hasRequiredSourceMap$1; + +function requireSourceMap$1 () { + if (hasRequiredSourceMap$1) return sourceMap; + hasRequiredSourceMap$1 = 1; + sourceMap.SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator; + sourceMap.SourceMapConsumer = requireSourceMapConsumer().SourceMapConsumer; + sourceMap.SourceNode = requireSourceNode().SourceNode; + return sourceMap; +} + +var hasRequiredSourceMap; + +function requireSourceMap () { + if (hasRequiredSourceMap) return sourceMap$1; + hasRequiredSourceMap = 1; + + Object.defineProperty(sourceMap$1, "__esModule", { + value: true + }); + sourceMap$1.default = void 0; + + function _sourceMap() { + const data = _interopRequireDefault(requireSourceMap$1()); + + _sourceMap = function () { + return data; + }; + + return data; + } + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + class SourceMap { + constructor(opts, code) { + this._cachedMap = null; + this._code = code; + this._opts = opts; + this._rawMappings = []; + } + + get() { + if (!this._cachedMap) { + const map = this._cachedMap = new (_sourceMap().default.SourceMapGenerator)({ + sourceRoot: this._opts.sourceRoot + }); + const code = this._code; + + if (typeof code === "string") { + map.setSourceContent(this._opts.sourceFileName, code); + } else if (typeof code === "object") { + Object.keys(code).forEach(sourceFileName => { + map.setSourceContent(sourceFileName, code[sourceFileName]); + }); + } + + this._rawMappings.forEach(map.addMapping, map); + } + + return this._cachedMap.toJSON(); + } + + getRawMappings() { + return this._rawMappings.slice(); + } + + mark(generatedLine, generatedColumn, line, column, identifierName, filename, force) { + if (this._lastGenLine !== generatedLine && line === null) return; + + if (!force && this._lastGenLine === generatedLine && this._lastSourceLine === line && this._lastSourceColumn === column) { + return; + } + + this._cachedMap = null; + this._lastGenLine = generatedLine; + this._lastSourceLine = line; + this._lastSourceColumn = column; + + this._rawMappings.push({ + name: identifierName || undefined, + generated: { + line: generatedLine, + column: generatedColumn + }, + source: line == null ? undefined : filename || this._opts.sourceFileName, + original: line == null ? undefined : { + line: line, + column: column + } + }); + } + + } + + sourceMap$1.default = SourceMap; + return sourceMap$1; +} + +var printer = {}; + +var _trimmedEndIndex; +var hasRequired_trimmedEndIndex; + +function require_trimmedEndIndex () { + if (hasRequired_trimmedEndIndex) return _trimmedEndIndex; + hasRequired_trimmedEndIndex = 1; + var reWhitespace = /\s/; + + /** + * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace + * character of `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the index of the last non-whitespace character. + */ + function trimmedEndIndex(string) { + var index = string.length; + + while (index-- && reWhitespace.test(string.charAt(index))) {} + return index; + } + + _trimmedEndIndex = trimmedEndIndex; + return _trimmedEndIndex; +} + +var _baseTrim; +var hasRequired_baseTrim; + +function require_baseTrim () { + if (hasRequired_baseTrim) return _baseTrim; + hasRequired_baseTrim = 1; + var trimmedEndIndex = require_trimmedEndIndex(); + + /** Used to match leading whitespace. */ + var reTrimStart = /^\s+/; + + /** + * The base implementation of `_.trim`. + * + * @private + * @param {string} string The string to trim. + * @returns {string} Returns the trimmed string. + */ + function baseTrim(string) { + return string + ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') + : string; + } + + _baseTrim = baseTrim; + return _baseTrim; +} + +var isObject_1; +var hasRequiredIsObject; + +function requireIsObject () { + if (hasRequiredIsObject) return isObject_1; + hasRequiredIsObject = 1; + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + isObject_1 = isObject; + return isObject_1; +} + +var _freeGlobal; +var hasRequired_freeGlobal; + +function require_freeGlobal () { + if (hasRequired_freeGlobal) return _freeGlobal; + hasRequired_freeGlobal = 1; + var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; + + _freeGlobal = freeGlobal; + return _freeGlobal; +} + +var _root; +var hasRequired_root; + +function require_root () { + if (hasRequired_root) return _root; + hasRequired_root = 1; + var freeGlobal = require_freeGlobal(); + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + + _root = root; + return _root; +} + +var _Symbol; +var hasRequired_Symbol; + +function require_Symbol () { + if (hasRequired_Symbol) return _Symbol; + hasRequired_Symbol = 1; + var root = require_root(); + + /** Built-in value references. */ + var Symbol = root.Symbol; + + _Symbol = Symbol; + return _Symbol; +} + +var _getRawTag; +var hasRequired_getRawTag; + +function require_getRawTag () { + if (hasRequired_getRawTag) return _getRawTag; + hasRequired_getRawTag = 1; + var Symbol = require_Symbol(); + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + _getRawTag = getRawTag; + return _getRawTag; +} + +var _objectToString; +var hasRequired_objectToString; + +function require_objectToString () { + if (hasRequired_objectToString) return _objectToString; + hasRequired_objectToString = 1; + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + + _objectToString = objectToString; + return _objectToString; +} + +var _baseGetTag; +var hasRequired_baseGetTag; + +function require_baseGetTag () { + if (hasRequired_baseGetTag) return _baseGetTag; + hasRequired_baseGetTag = 1; + var Symbol = require_Symbol(), + getRawTag = require_getRawTag(), + objectToString = require_objectToString(); + + /** `Object#toString` result references. */ + var nullTag = '[object Null]', + undefinedTag = '[object Undefined]'; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + return (symToStringTag && symToStringTag in Object(value)) + ? getRawTag(value) + : objectToString(value); + } + + _baseGetTag = baseGetTag; + return _baseGetTag; +} + +var isObjectLike_1; +var hasRequiredIsObjectLike; + +function requireIsObjectLike () { + if (hasRequiredIsObjectLike) return isObjectLike_1; + hasRequiredIsObjectLike = 1; + function isObjectLike(value) { + return value != null && typeof value == 'object'; + } + + isObjectLike_1 = isObjectLike; + return isObjectLike_1; +} + +var isSymbol_1; +var hasRequiredIsSymbol; + +function requireIsSymbol () { + if (hasRequiredIsSymbol) return isSymbol_1; + hasRequiredIsSymbol = 1; + var baseGetTag = require_baseGetTag(), + isObjectLike = requireIsObjectLike(); + + /** `Object#toString` result references. */ + var symbolTag = '[object Symbol]'; + + /** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ + function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && baseGetTag(value) == symbolTag); + } + + isSymbol_1 = isSymbol; + return isSymbol_1; +} + +var toNumber_1; +var hasRequiredToNumber; + +function requireToNumber () { + if (hasRequiredToNumber) return toNumber_1; + hasRequiredToNumber = 1; + var baseTrim = require_baseTrim(), + isObject = requireIsObject(), + isSymbol = requireIsSymbol(); + + /** Used as references for various `Number` constants. */ + var NAN = 0 / 0; + + /** Used to detect bad signed hexadecimal string values. */ + var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + + /** Used to detect binary string values. */ + var reIsBinary = /^0b[01]+$/i; + + /** Used to detect octal string values. */ + var reIsOctal = /^0o[0-7]+$/i; + + /** Built-in method references without a dependency on `root`. */ + var freeParseInt = parseInt; + + /** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */ + function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + if (isObject(value)) { + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; + value = isObject(other) ? (other + '') : other; + } + if (typeof value != 'string') { + return value === 0 ? value : +value; + } + value = baseTrim(value); + var isBinary = reIsBinary.test(value); + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value); + } + + toNumber_1 = toNumber; + return toNumber_1; +} + +var toFinite_1; +var hasRequiredToFinite; + +function requireToFinite () { + if (hasRequiredToFinite) return toFinite_1; + hasRequiredToFinite = 1; + var toNumber = requireToNumber(); + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0, + MAX_INTEGER = 1.7976931348623157e+308; + + /** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ + function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; + } + + toFinite_1 = toFinite; + return toFinite_1; +} + +var toInteger_1; +var hasRequiredToInteger; + +function requireToInteger () { + if (hasRequiredToInteger) return toInteger_1; + hasRequiredToInteger = 1; + var toFinite = requireToFinite(); + + /** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toInteger(3.2); + * // => 3 + * + * _.toInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toInteger(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toInteger('3.2'); + * // => 3 + */ + function toInteger(value) { + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; + } + + toInteger_1 = toInteger; + return toInteger_1; +} + +var isInteger_1; +var hasRequiredIsInteger; + +function requireIsInteger () { + if (hasRequiredIsInteger) return isInteger_1; + hasRequiredIsInteger = 1; + var toInteger = requireToInteger(); + + /** + * Checks if `value` is an integer. + * + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an integer, else `false`. + * @example + * + * _.isInteger(3); + * // => true + * + * _.isInteger(Number.MIN_VALUE); + * // => false + * + * _.isInteger(Infinity); + * // => false + * + * _.isInteger('3'); + * // => false + */ + function isInteger(value) { + return typeof value == 'number' && value == toInteger(value); + } + + isInteger_1 = isInteger; + return isInteger_1; +} + +var _baseRepeat; +var hasRequired_baseRepeat; + +function require_baseRepeat () { + if (hasRequired_baseRepeat) return _baseRepeat; + hasRequired_baseRepeat = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeFloor = Math.floor; + + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + + _baseRepeat = baseRepeat; + return _baseRepeat; +} + +var eq_1; +var hasRequiredEq; + +function requireEq () { + if (hasRequiredEq) return eq_1; + hasRequiredEq = 1; + function eq(value, other) { + return value === other || (value !== value && other !== other); + } + + eq_1 = eq; + return eq_1; +} + +var isFunction_1; +var hasRequiredIsFunction; + +function requireIsFunction () { + if (hasRequiredIsFunction) return isFunction_1; + hasRequiredIsFunction = 1; + var baseGetTag = require_baseGetTag(), + isObject = requireIsObject(); + + /** `Object#toString` result references. */ + var asyncTag = '[object AsyncFunction]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + proxyTag = '[object Proxy]'; + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + if (!isObject(value)) { + return false; + } + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; + } + + isFunction_1 = isFunction; + return isFunction_1; +} + +var isLength_1; +var hasRequiredIsLength; + +function requireIsLength () { + if (hasRequiredIsLength) return isLength_1; + hasRequiredIsLength = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ + function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + } + + isLength_1 = isLength; + return isLength_1; +} + +var isArrayLike_1; +var hasRequiredIsArrayLike; + +function requireIsArrayLike () { + if (hasRequiredIsArrayLike) return isArrayLike_1; + hasRequiredIsArrayLike = 1; + var isFunction = requireIsFunction(), + isLength = requireIsLength(); + + /** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ + function isArrayLike(value) { + return value != null && isLength(value.length) && !isFunction(value); + } + + isArrayLike_1 = isArrayLike; + return isArrayLike_1; +} + +var _isIndex; +var hasRequired_isIndex; + +function require_isIndex () { + if (hasRequired_isIndex) return _isIndex; + hasRequired_isIndex = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /** Used to detect unsigned integer values. */ + var reIsUint = /^(?:0|[1-9]\d*)$/; + + /** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ + function isIndex(value, length) { + var type = typeof value; + length = length == null ? MAX_SAFE_INTEGER : length; + + return !!length && + (type == 'number' || + (type != 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length); + } + + _isIndex = isIndex; + return _isIndex; +} + +var _isIterateeCall; +var hasRequired_isIterateeCall; + +function require_isIterateeCall () { + if (hasRequired_isIterateeCall) return _isIterateeCall; + hasRequired_isIterateeCall = 1; + var eq = requireEq(), + isArrayLike = requireIsArrayLike(), + isIndex = require_isIndex(), + isObject = requireIsObject(); + + /** + * Checks if the given arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. + */ + function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { + return eq(object[index], value); + } + return false; + } + + _isIterateeCall = isIterateeCall; + return _isIterateeCall; +} + +var _arrayMap; +var hasRequired_arrayMap; + +function require_arrayMap () { + if (hasRequired_arrayMap) return _arrayMap; + hasRequired_arrayMap = 1; + function arrayMap(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; + } + + _arrayMap = arrayMap; + return _arrayMap; +} + +var isArray_1; +var hasRequiredIsArray; + +function requireIsArray () { + if (hasRequiredIsArray) return isArray_1; + hasRequiredIsArray = 1; + var isArray = Array.isArray; + + isArray_1 = isArray; + return isArray_1; +} + +var _baseToString; +var hasRequired_baseToString; + +function require_baseToString () { + if (hasRequired_baseToString) return _baseToString; + hasRequired_baseToString = 1; + var Symbol = require_Symbol(), + arrayMap = require_arrayMap(), + isArray = requireIsArray(), + isSymbol = requireIsSymbol(); + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0; + + /** Used to convert symbols to primitives and strings. */ + var symbolProto = Symbol ? Symbol.prototype : undefined, + symbolToString = symbolProto ? symbolProto.toString : undefined; + + /** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ + function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return arrayMap(value, baseToString) + ''; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + _baseToString = baseToString; + return _baseToString; +} + +var toString_1; +var hasRequiredToString; + +function requireToString () { + if (hasRequiredToString) return toString_1; + hasRequiredToString = 1; + var baseToString = require_baseToString(); + + /** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ + function toString(value) { + return value == null ? '' : baseToString(value); + } + + toString_1 = toString; + return toString_1; +} + +var repeat_1; +var hasRequiredRepeat; + +function requireRepeat () { + if (hasRequiredRepeat) return repeat_1; + hasRequiredRepeat = 1; + var baseRepeat = require_baseRepeat(), + isIterateeCall = require_isIterateeCall(), + toInteger = requireToInteger(), + toString = requireToString(); + + /** + * Repeats the given string `n` times. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to repeat. + * @param {number} [n=1] The number of times to repeat the string. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the repeated string. + * @example + * + * _.repeat('*', 3); + * // => '***' + * + * _.repeat('abc', 2); + * // => 'abcabc' + * + * _.repeat('abc', 0); + * // => '' + */ + function repeat(string, n, guard) { + if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { + n = 1; + } else { + n = toInteger(n); + } + return baseRepeat(toString(string), n); + } + + repeat_1 = repeat; + return repeat_1; +} + +var buffer = {}; + +var trimRight; +var hasRequiredTrimRight; + +function requireTrimRight () { + if (hasRequiredTrimRight) return trimRight; + hasRequiredTrimRight = 1; + trimRight = function (str) { + var tail = str.length; + + while (/[\s\uFEFF\u00A0]/.test(str[tail - 1])) { + tail--; + } + + return str.slice(0, tail); + }; + return trimRight; +} + +var hasRequiredBuffer; + +function requireBuffer () { + if (hasRequiredBuffer) return buffer; + hasRequiredBuffer = 1; + + Object.defineProperty(buffer, "__esModule", { + value: true + }); + buffer.default = void 0; + + function _trimRight() { + const data = _interopRequireDefault(requireTrimRight()); + + _trimRight = function () { + return data; + }; + + return data; + } + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + const SPACES_RE = /^[ \t]+$/; + + class Buffer { + constructor(map) { + this._map = null; + this._buf = []; + this._last = ""; + this._queue = []; + this._position = { + line: 1, + column: 0 + }; + this._sourcePosition = { + identifierName: null, + line: null, + column: null, + filename: null + }; + this._disallowedPop = null; + this._map = map; + } + + get() { + this._flush(); + + const map = this._map; + const result = { + code: (0, _trimRight().default)(this._buf.join("")), + map: null, + rawMappings: map && map.getRawMappings() + }; + + if (map) { + Object.defineProperty(result, "map", { + configurable: true, + enumerable: true, + + get() { + return this.map = map.get(); + }, + + set(value) { + Object.defineProperty(this, "map", { + value, + writable: true + }); + } + + }); + } + + return result; + } + + append(str) { + this._flush(); + + const { + line, + column, + filename, + identifierName, + force + } = this._sourcePosition; + + this._append(str, line, column, identifierName, filename, force); + } + + queue(str) { + if (str === "\n") { + while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) { + this._queue.shift(); + } + } + + const { + line, + column, + filename, + identifierName, + force + } = this._sourcePosition; + + this._queue.unshift([str, line, column, identifierName, filename, force]); + } + + _flush() { + let item; + + while (item = this._queue.pop()) this._append(...item); + } + + _append(str, line, column, identifierName, filename, force) { + if (this._map && str[0] !== "\n") { + this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force); + } + + this._buf.push(str); + + this._last = str[str.length - 1]; + + for (let i = 0; i < str.length; i++) { + if (str[i] === "\n") { + this._position.line++; + this._position.column = 0; + } else { + this._position.column++; + } + } + } + + removeTrailingNewline() { + if (this._queue.length > 0 && this._queue[0][0] === "\n") { + this._queue.shift(); + } + } + + removeLastSemicolon() { + if (this._queue.length > 0 && this._queue[0][0] === ";") { + this._queue.shift(); + } + } + + endsWith(suffix) { + if (suffix.length === 1) { + let last; + + if (this._queue.length > 0) { + const str = this._queue[0][0]; + last = str[str.length - 1]; + } else { + last = this._last; + } + + return last === suffix; + } + + const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, ""); + + if (suffix.length <= end.length) { + return end.slice(-suffix.length) === suffix; + } + + return false; + } + + hasContent() { + return this._queue.length > 0 || !!this._last; + } + + exactSource(loc, cb) { + this.source("start", loc, true); + cb(); + this.source("end", loc); + + this._disallowPop("start", loc); + } + + source(prop, loc, force) { + if (prop && !loc) return; + + this._normalizePosition(prop, loc, this._sourcePosition, force); + } + + withSource(prop, loc, cb) { + if (!this._map) return cb(); + const originalLine = this._sourcePosition.line; + const originalColumn = this._sourcePosition.column; + const originalFilename = this._sourcePosition.filename; + const originalIdentifierName = this._sourcePosition.identifierName; + this.source(prop, loc); + cb(); + + if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) { + this._sourcePosition.line = originalLine; + this._sourcePosition.column = originalColumn; + this._sourcePosition.filename = originalFilename; + this._sourcePosition.identifierName = originalIdentifierName; + this._sourcePosition.force = false; + this._disallowedPop = null; + } + } + + _disallowPop(prop, loc) { + if (prop && !loc) return; + this._disallowedPop = this._normalizePosition(prop, loc); + } + + _normalizePosition(prop, loc, targetObj, force) { + const pos = loc ? loc[prop] : null; + + if (targetObj === undefined) { + targetObj = { + identifierName: null, + line: null, + column: null, + filename: null, + force: false + }; + } + + const origLine = targetObj.line; + const origColumn = targetObj.column; + const origFilename = targetObj.filename; + targetObj.identifierName = prop === "start" && loc && loc.identifierName || null; + targetObj.line = pos ? pos.line : null; + targetObj.column = pos ? pos.column : null; + targetObj.filename = loc && loc.filename || null; + + if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) { + targetObj.force = force; + } + + return targetObj; + } + + getCurrentColumn() { + const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); + + const lastIndex = extra.lastIndexOf("\n"); + return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex; + } + + getCurrentLine() { + const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); + + let count = 0; + + for (let i = 0; i < extra.length; i++) { + if (extra[i] === "\n") count++; + } + + return this._position.line + count; + } + + } + + buffer.default = Buffer; + return buffer; +} + +var node = {}; + +var whitespace = {}; + +var hasRequiredWhitespace; + +function requireWhitespace () { + if (hasRequiredWhitespace) return whitespace; + hasRequiredWhitespace = 1; + + Object.defineProperty(whitespace, "__esModule", { + value: true + }); + whitespace.list = whitespace.nodes = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function crawl(node, state = {}) { + if (t().isMemberExpression(node)) { + crawl(node.object, state); + if (node.computed) crawl(node.property, state); + } else if (t().isBinary(node) || t().isAssignmentExpression(node)) { + crawl(node.left, state); + crawl(node.right, state); + } else if (t().isCallExpression(node)) { + state.hasCall = true; + crawl(node.callee, state); + } else if (t().isFunction(node)) { + state.hasFunction = true; + } else if (t().isIdentifier(node)) { + state.hasHelper = state.hasHelper || isHelper(node.callee); + } + + return state; + } + + function isHelper(node) { + if (t().isMemberExpression(node)) { + return isHelper(node.object) || isHelper(node.property); + } else if (t().isIdentifier(node)) { + return node.name === "require" || node.name[0] === "_"; + } else if (t().isCallExpression(node)) { + return isHelper(node.callee); + } else if (t().isBinary(node) || t().isAssignmentExpression(node)) { + return t().isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right); + } else { + return false; + } + } + + function isType(node) { + return t().isLiteral(node) || t().isObjectExpression(node) || t().isArrayExpression(node) || t().isIdentifier(node) || t().isMemberExpression(node); + } + + const nodes = { + AssignmentExpression(node) { + const state = crawl(node.right); + + if (state.hasCall && state.hasHelper || state.hasFunction) { + return { + before: state.hasFunction, + after: true + }; + } + }, + + SwitchCase(node, parent) { + return { + before: node.consequent.length || parent.cases[0] === node, + after: !node.consequent.length && parent.cases[parent.cases.length - 1] === node + }; + }, + + LogicalExpression(node) { + if (t().isFunction(node.left) || t().isFunction(node.right)) { + return { + after: true + }; + } + }, + + Literal(node) { + if (node.value === "use strict") { + return { + after: true + }; + } + }, + + CallExpression(node) { + if (t().isFunction(node.callee) || isHelper(node)) { + return { + before: true, + after: true + }; + } + }, + + VariableDeclaration(node) { + for (let i = 0; i < node.declarations.length; i++) { + const declar = node.declarations[i]; + let enabled = isHelper(declar.id) && !isType(declar.init); + + if (!enabled) { + const state = crawl(declar.init); + enabled = isHelper(declar.init) && state.hasCall || state.hasFunction; + } + + if (enabled) { + return { + before: true, + after: true + }; + } + } + }, + + IfStatement(node) { + if (t().isBlockStatement(node.consequent)) { + return { + before: true, + after: true + }; + } + } + + }; + whitespace.nodes = nodes; + + nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) { + if (parent.properties[0] === node) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeCallProperty = function (node, parent) { + if (parent.callProperties[0] === node && (!parent.properties || !parent.properties.length)) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeIndexer = function (node, parent) { + if (parent.indexers[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length)) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeInternalSlot = function (node, parent) { + if (parent.internalSlots[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length) && (!parent.indexers || !parent.indexers.length)) { + return { + before: true + }; + } + }; + + const list = { + VariableDeclaration(node) { + return node.declarations.map(decl => decl.init); + }, + + ArrayExpression(node) { + return node.elements; + }, + + ObjectExpression(node) { + return node.properties; + } + + }; + whitespace.list = list; + [["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) { + if (typeof amounts === "boolean") { + amounts = { + after: amounts, + before: amounts + }; + } + + [type].concat(t().FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { + nodes[type] = function () { + return amounts; + }; + }); + }); + return whitespace; +} + +var parentheses = {}; + +var hasRequiredParentheses; + +function requireParentheses () { + if (hasRequiredParentheses) return parentheses; + hasRequiredParentheses = 1; + + Object.defineProperty(parentheses, "__esModule", { + value: true + }); + parentheses.FunctionTypeAnnotation = parentheses.NullableTypeAnnotation = NullableTypeAnnotation; + parentheses.UpdateExpression = UpdateExpression; + parentheses.ObjectExpression = ObjectExpression; + parentheses.DoExpression = DoExpression; + parentheses.Binary = Binary; + parentheses.IntersectionTypeAnnotation = parentheses.UnionTypeAnnotation = UnionTypeAnnotation; + parentheses.TSAsExpression = TSAsExpression; + parentheses.TSTypeAssertion = TSTypeAssertion; + parentheses.BinaryExpression = BinaryExpression; + parentheses.SequenceExpression = SequenceExpression; + parentheses.AwaitExpression = parentheses.YieldExpression = YieldExpression; + parentheses.ClassExpression = ClassExpression; + parentheses.UnaryLike = UnaryLike; + parentheses.FunctionExpression = FunctionExpression; + parentheses.ArrowFunctionExpression = ArrowFunctionExpression; + parentheses.ConditionalExpression = ConditionalExpression; + parentheses.OptionalMemberExpression = OptionalMemberExpression; + parentheses.AssignmentExpression = AssignmentExpression; + parentheses.NewExpression = NewExpression; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + const PRECEDENCE = { + "||": 0, + "&&": 1, + "|": 2, + "^": 3, + "&": 4, + "==": 5, + "===": 5, + "!=": 5, + "!==": 5, + "<": 6, + ">": 6, + "<=": 6, + ">=": 6, + in: 6, + instanceof: 6, + ">>": 7, + "<<": 7, + ">>>": 7, + "+": 8, + "-": 8, + "*": 9, + "/": 9, + "%": 9, + "**": 10 + }; + + const isClassExtendsClause = (node, parent) => (t().isClassDeclaration(parent) || t().isClassExpression(parent)) && parent.superClass === node; + + function NullableTypeAnnotation(node, parent) { + return t().isArrayTypeAnnotation(parent); + } + + function UpdateExpression(node, parent) { + return t().isMemberExpression(parent, { + object: node + }) || t().isCallExpression(parent, { + callee: node + }) || t().isNewExpression(parent, { + callee: node + }) || isClassExtendsClause(node, parent); + } + + function ObjectExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerArrow: true + }); + } + + function DoExpression(node, parent, printStack) { + return isFirstInStatement(printStack); + } + + function Binary(node, parent) { + if (node.operator === "**" && t().isBinaryExpression(parent, { + operator: "**" + })) { + return parent.left === node; + } + + if (isClassExtendsClause(node, parent)) { + return true; + } + + if ((t().isCallExpression(parent) || t().isNewExpression(parent)) && parent.callee === node || t().isUnaryLike(parent) || t().isMemberExpression(parent) && parent.object === node || t().isAwaitExpression(parent)) { + return true; + } + + if (t().isBinary(parent)) { + const parentOp = parent.operator; + const parentPos = PRECEDENCE[parentOp]; + const nodeOp = node.operator; + const nodePos = PRECEDENCE[nodeOp]; + + if (parentPos === nodePos && parent.right === node && !t().isLogicalExpression(parent) || parentPos > nodePos) { + return true; + } + } + + return false; + } + + function UnionTypeAnnotation(node, parent) { + return t().isArrayTypeAnnotation(parent) || t().isNullableTypeAnnotation(parent) || t().isIntersectionTypeAnnotation(parent) || t().isUnionTypeAnnotation(parent); + } + + function TSAsExpression() { + return true; + } + + function TSTypeAssertion() { + return true; + } + + function BinaryExpression(node, parent) { + return node.operator === "in" && (t().isVariableDeclarator(parent) || t().isFor(parent)); + } + + function SequenceExpression(node, parent) { + if (t().isForStatement(parent) || t().isThrowStatement(parent) || t().isReturnStatement(parent) || t().isIfStatement(parent) && parent.test === node || t().isWhileStatement(parent) && parent.test === node || t().isForInStatement(parent) && parent.right === node || t().isSwitchStatement(parent) && parent.discriminant === node || t().isExpressionStatement(parent) && parent.expression === node) { + return false; + } + + return true; + } + + function YieldExpression(node, parent) { + return t().isBinary(parent) || t().isUnaryLike(parent) || t().isCallExpression(parent) || t().isMemberExpression(parent) || t().isNewExpression(parent) || t().isAwaitExpression(parent) && t().isYieldExpression(node) || t().isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent); + } + + function ClassExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerDefaultExports: true + }); + } + + function UnaryLike(node, parent) { + return t().isMemberExpression(parent, { + object: node + }) || t().isCallExpression(parent, { + callee: node + }) || t().isNewExpression(parent, { + callee: node + }) || t().isBinaryExpression(parent, { + operator: "**", + left: node + }) || isClassExtendsClause(node, parent); + } + + function FunctionExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerDefaultExports: true + }); + } + + function ArrowFunctionExpression(node, parent) { + return t().isExportDeclaration(parent) || ConditionalExpression(node, parent); + } + + function ConditionalExpression(node, parent) { + if (t().isUnaryLike(parent) || t().isBinary(parent) || t().isConditionalExpression(parent, { + test: node + }) || t().isAwaitExpression(parent) || t().isOptionalMemberExpression(parent) || t().isTaggedTemplateExpression(parent) || t().isTSTypeAssertion(parent) || t().isTSAsExpression(parent)) { + return true; + } + + return UnaryLike(node, parent); + } + + function OptionalMemberExpression(node, parent) { + return t().isCallExpression(parent) || t().isMemberExpression(parent); + } + + function AssignmentExpression(node) { + if (t().isObjectPattern(node.left)) { + return true; + } else { + return ConditionalExpression(...arguments); + } + } + + function NewExpression(node, parent) { + return isClassExtendsClause(node, parent); + } + + function isFirstInStatement(printStack, { + considerArrow = false, + considerDefaultExports = false + } = {}) { + let i = printStack.length - 1; + let node = printStack[i]; + i--; + let parent = printStack[i]; + + while (i > 0) { + if (t().isExpressionStatement(parent, { + expression: node + }) || t().isTaggedTemplateExpression(parent) || considerDefaultExports && t().isExportDefaultDeclaration(parent, { + declaration: node + }) || considerArrow && t().isArrowFunctionExpression(parent, { + body: node + })) { + return true; + } + + if (t().isCallExpression(parent, { + callee: node + }) || t().isSequenceExpression(parent) && parent.expressions[0] === node || t().isMemberExpression(parent, { + object: node + }) || t().isConditional(parent, { + test: node + }) || t().isBinary(parent, { + left: node + }) || t().isAssignmentExpression(parent, { + left: node + })) { + node = parent; + i--; + parent = printStack[i]; + } else { + return false; + } + } + + return false; + } + return parentheses; +} + +var hasRequiredNode; + +function requireNode () { + if (hasRequiredNode) return node; + hasRequiredNode = 1; + + Object.defineProperty(node, "__esModule", { + value: true + }); + node.needsWhitespace = needsWhitespace; + node.needsWhitespaceBefore = needsWhitespaceBefore; + node.needsWhitespaceAfter = needsWhitespaceAfter; + node.needsParens = needsParens; + + var whitespace = _interopRequireWildcard(requireWhitespace()); + + var parens = _interopRequireWildcard(requireParentheses()); + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function expandAliases(obj) { + const newObj = {}; + + function add(type, func) { + const fn = newObj[type]; + newObj[type] = fn ? function (node, parent, stack) { + const result = fn(node, parent, stack); + return result == null ? func(node, parent, stack) : result; + } : func; + } + + for (const type of Object.keys(obj)) { + const aliases = t().FLIPPED_ALIAS_KEYS[type]; + + if (aliases) { + for (const alias of aliases) { + add(alias, obj[type]); + } + } else { + add(type, obj[type]); + } + } + + return newObj; + } + + const expandedParens = expandAliases(parens); + const expandedWhitespaceNodes = expandAliases(whitespace.nodes); + const expandedWhitespaceList = expandAliases(whitespace.list); + + function find(obj, node, parent, printStack) { + const fn = obj[node.type]; + return fn ? fn(node, parent, printStack) : null; + } + + function isOrHasCallExpression(node) { + if (t().isCallExpression(node)) { + return true; + } + + if (t().isMemberExpression(node)) { + return isOrHasCallExpression(node.object) || !node.computed && isOrHasCallExpression(node.property); + } else { + return false; + } + } + + function needsWhitespace(node, parent, type) { + if (!node) return 0; + + if (t().isExpressionStatement(node)) { + node = node.expression; + } + + let linesInfo = find(expandedWhitespaceNodes, node, parent); + + if (!linesInfo) { + const items = find(expandedWhitespaceList, node, parent); + + if (items) { + for (let i = 0; i < items.length; i++) { + linesInfo = needsWhitespace(items[i], node, type); + if (linesInfo) break; + } + } + } + + if (typeof linesInfo === "object" && linesInfo !== null) { + return linesInfo[type] || 0; + } + + return 0; + } + + function needsWhitespaceBefore(node, parent) { + return needsWhitespace(node, parent, "before"); + } + + function needsWhitespaceAfter(node, parent) { + return needsWhitespace(node, parent, "after"); + } + + function needsParens(node, parent, printStack) { + if (!parent) return false; + + if (t().isNewExpression(parent) && parent.callee === node) { + if (isOrHasCallExpression(node)) return true; + } + + return find(expandedParens, node, parent, printStack); + } + return node; +} + +var generators = {}; + +var templateLiterals = {}; + +var hasRequiredTemplateLiterals; + +function requireTemplateLiterals () { + if (hasRequiredTemplateLiterals) return templateLiterals; + hasRequiredTemplateLiterals = 1; + + Object.defineProperty(templateLiterals, "__esModule", { + value: true + }); + templateLiterals.TaggedTemplateExpression = TaggedTemplateExpression; + templateLiterals.TemplateElement = TemplateElement; + templateLiterals.TemplateLiteral = TemplateLiteral; + + function TaggedTemplateExpression(node) { + this.print(node.tag, node); + this.print(node.typeParameters, node); + this.print(node.quasi, node); + } + + function TemplateElement(node, parent) { + const isFirst = parent.quasis[0] === node; + const isLast = parent.quasis[parent.quasis.length - 1] === node; + const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); + this.token(value); + } + + function TemplateLiteral(node) { + const quasis = node.quasis; + + for (let i = 0; i < quasis.length; i++) { + this.print(quasis[i], node); + + if (i + 1 < quasis.length) { + this.print(node.expressions[i], node); + } + } + } + return templateLiterals; +} + +var expressions = {}; + +var hasRequiredExpressions; + +function requireExpressions () { + if (hasRequiredExpressions) return expressions; + hasRequiredExpressions = 1; + + Object.defineProperty(expressions, "__esModule", { + value: true + }); + expressions.UnaryExpression = UnaryExpression; + expressions.DoExpression = DoExpression; + expressions.ParenthesizedExpression = ParenthesizedExpression; + expressions.UpdateExpression = UpdateExpression; + expressions.ConditionalExpression = ConditionalExpression; + expressions.NewExpression = NewExpression; + expressions.SequenceExpression = SequenceExpression; + expressions.ThisExpression = ThisExpression; + expressions.Super = Super; + expressions.Decorator = Decorator; + expressions.OptionalMemberExpression = OptionalMemberExpression; + expressions.OptionalCallExpression = OptionalCallExpression; + expressions.CallExpression = CallExpression; + expressions.Import = Import; + expressions.EmptyStatement = EmptyStatement; + expressions.ExpressionStatement = ExpressionStatement; + expressions.AssignmentPattern = AssignmentPattern; + expressions.LogicalExpression = expressions.BinaryExpression = expressions.AssignmentExpression = AssignmentExpression; + expressions.BindExpression = BindExpression; + expressions.MemberExpression = MemberExpression; + expressions.MetaProperty = MetaProperty; + expressions.PrivateName = PrivateName; + expressions.AwaitExpression = expressions.YieldExpression = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + var n = _interopRequireWildcard(requireNode()); + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function UnaryExpression(node) { + if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") { + this.word(node.operator); + this.space(); + } else { + this.token(node.operator); + } + + this.print(node.argument, node); + } + + function DoExpression(node) { + this.word("do"); + this.space(); + this.print(node.body, node); + } + + function ParenthesizedExpression(node) { + this.token("("); + this.print(node.expression, node); + this.token(")"); + } + + function UpdateExpression(node) { + if (node.prefix) { + this.token(node.operator); + this.print(node.argument, node); + } else { + this.startTerminatorless(true); + this.print(node.argument, node); + this.endTerminatorless(); + this.token(node.operator); + } + } + + function ConditionalExpression(node) { + this.print(node.test, node); + this.space(); + this.token("?"); + this.space(); + this.print(node.consequent, node); + this.space(); + this.token(":"); + this.space(); + this.print(node.alternate, node); + } + + function NewExpression(node, parent) { + this.word("new"); + this.space(); + this.print(node.callee, node); + + if (this.format.minified && node.arguments.length === 0 && !node.optional && !t().isCallExpression(parent, { + callee: node + }) && !t().isMemberExpression(parent) && !t().isNewExpression(parent)) { + return; + } + + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + + if (node.optional) { + this.token("?."); + } + + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function SequenceExpression(node) { + this.printList(node.expressions, node); + } + + function ThisExpression() { + this.word("this"); + } + + function Super() { + this.word("super"); + } + + function Decorator(node) { + this.token("@"); + this.print(node.expression, node); + this.newline(); + } + + function OptionalMemberExpression(node) { + this.print(node.object, node); + + if (!node.computed && t().isMemberExpression(node.property)) { + throw new TypeError("Got a MemberExpression for MemberExpression property"); + } + + let computed = node.computed; + + if (t().isLiteral(node.property) && typeof node.property.value === "number") { + computed = true; + } + + if (node.optional) { + this.token("?."); + } + + if (computed) { + this.token("["); + this.print(node.property, node); + this.token("]"); + } else { + if (!node.optional) { + this.token("."); + } + + this.print(node.property, node); + } + } + + function OptionalCallExpression(node) { + this.print(node.callee, node); + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + + if (node.optional) { + this.token("?."); + } + + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function CallExpression(node) { + this.print(node.callee, node); + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function Import() { + this.word("import"); + } + + function buildYieldAwait(keyword) { + return function (node) { + this.word(keyword); + + if (node.delegate) { + this.token("*"); + } + + if (node.argument) { + this.space(); + const terminatorState = this.startTerminatorless(); + this.print(node.argument, node); + this.endTerminatorless(terminatorState); + } + }; + } + + const YieldExpression = buildYieldAwait("yield"); + expressions.YieldExpression = YieldExpression; + const AwaitExpression = buildYieldAwait("await"); + expressions.AwaitExpression = AwaitExpression; + + function EmptyStatement() { + this.semicolon(true); + } + + function ExpressionStatement(node) { + this.print(node.expression, node); + this.semicolon(); + } + + function AssignmentPattern(node) { + this.print(node.left, node); + if (node.left.optional) this.token("?"); + this.print(node.left.typeAnnotation, node); + this.space(); + this.token("="); + this.space(); + this.print(node.right, node); + } + + function AssignmentExpression(node, parent) { + const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); + + if (parens) { + this.token("("); + } + + this.print(node.left, node); + this.space(); + + if (node.operator === "in" || node.operator === "instanceof") { + this.word(node.operator); + } else { + this.token(node.operator); + } + + this.space(); + this.print(node.right, node); + + if (parens) { + this.token(")"); + } + } + + function BindExpression(node) { + this.print(node.object, node); + this.token("::"); + this.print(node.callee, node); + } + + function MemberExpression(node) { + this.print(node.object, node); + + if (!node.computed && t().isMemberExpression(node.property)) { + throw new TypeError("Got a MemberExpression for MemberExpression property"); + } + + let computed = node.computed; + + if (t().isLiteral(node.property) && typeof node.property.value === "number") { + computed = true; + } + + if (computed) { + this.token("["); + this.print(node.property, node); + this.token("]"); + } else { + this.token("."); + this.print(node.property, node); + } + } + + function MetaProperty(node) { + this.print(node.meta, node); + this.token("."); + this.print(node.property, node); + } + + function PrivateName(node) { + this.token("#"); + this.print(node.id, node); + } + return expressions; +} + +var statements = {}; + +var hasRequiredStatements; + +function requireStatements () { + if (hasRequiredStatements) return statements; + hasRequiredStatements = 1; + + Object.defineProperty(statements, "__esModule", { + value: true + }); + statements.WithStatement = WithStatement; + statements.IfStatement = IfStatement; + statements.ForStatement = ForStatement; + statements.WhileStatement = WhileStatement; + statements.DoWhileStatement = DoWhileStatement; + statements.LabeledStatement = LabeledStatement; + statements.TryStatement = TryStatement; + statements.CatchClause = CatchClause; + statements.SwitchStatement = SwitchStatement; + statements.SwitchCase = SwitchCase; + statements.DebuggerStatement = DebuggerStatement; + statements.VariableDeclaration = VariableDeclaration; + statements.VariableDeclarator = VariableDeclarator; + statements.ThrowStatement = statements.BreakStatement = statements.ReturnStatement = statements.ContinueStatement = statements.ForOfStatement = statements.ForInStatement = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function WithStatement(node) { + this.word("with"); + this.space(); + this.token("("); + this.print(node.object, node); + this.token(")"); + this.printBlock(node); + } + + function IfStatement(node) { + this.word("if"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.space(); + const needsBlock = node.alternate && t().isIfStatement(getLastStatement(node.consequent)); + + if (needsBlock) { + this.token("{"); + this.newline(); + this.indent(); + } + + this.printAndIndentOnComments(node.consequent, node); + + if (needsBlock) { + this.dedent(); + this.newline(); + this.token("}"); + } + + if (node.alternate) { + if (this.endsWith("}")) this.space(); + this.word("else"); + this.space(); + this.printAndIndentOnComments(node.alternate, node); + } + } + + function getLastStatement(statement) { + if (!t().isStatement(statement.body)) return statement; + return getLastStatement(statement.body); + } + + function ForStatement(node) { + this.word("for"); + this.space(); + this.token("("); + this.inForStatementInitCounter++; + this.print(node.init, node); + this.inForStatementInitCounter--; + this.token(";"); + + if (node.test) { + this.space(); + this.print(node.test, node); + } + + this.token(";"); + + if (node.update) { + this.space(); + this.print(node.update, node); + } + + this.token(")"); + this.printBlock(node); + } + + function WhileStatement(node) { + this.word("while"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.printBlock(node); + } + + const buildForXStatement = function (op) { + return function (node) { + this.word("for"); + this.space(); + + if (op === "of" && node.await) { + this.word("await"); + this.space(); + } + + this.token("("); + this.print(node.left, node); + this.space(); + this.word(op); + this.space(); + this.print(node.right, node); + this.token(")"); + this.printBlock(node); + }; + }; + + const ForInStatement = buildForXStatement("in"); + statements.ForInStatement = ForInStatement; + const ForOfStatement = buildForXStatement("of"); + statements.ForOfStatement = ForOfStatement; + + function DoWhileStatement(node) { + this.word("do"); + this.space(); + this.print(node.body, node); + this.space(); + this.word("while"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.semicolon(); + } + + function buildLabelStatement(prefix, key = "label") { + return function (node) { + this.word(prefix); + const label = node[key]; + + if (label) { + this.space(); + const isLabel = key == "label"; + const terminatorState = this.startTerminatorless(isLabel); + this.print(label, node); + this.endTerminatorless(terminatorState); + } + + this.semicolon(); + }; + } + + const ContinueStatement = buildLabelStatement("continue"); + statements.ContinueStatement = ContinueStatement; + const ReturnStatement = buildLabelStatement("return", "argument"); + statements.ReturnStatement = ReturnStatement; + const BreakStatement = buildLabelStatement("break"); + statements.BreakStatement = BreakStatement; + const ThrowStatement = buildLabelStatement("throw", "argument"); + statements.ThrowStatement = ThrowStatement; + + function LabeledStatement(node) { + this.print(node.label, node); + this.token(":"); + this.space(); + this.print(node.body, node); + } + + function TryStatement(node) { + this.word("try"); + this.space(); + this.print(node.block, node); + this.space(); + + if (node.handlers) { + this.print(node.handlers[0], node); + } else { + this.print(node.handler, node); + } + + if (node.finalizer) { + this.space(); + this.word("finally"); + this.space(); + this.print(node.finalizer, node); + } + } + + function CatchClause(node) { + this.word("catch"); + this.space(); + + if (node.param) { + this.token("("); + this.print(node.param, node); + this.token(")"); + this.space(); + } + + this.print(node.body, node); + } + + function SwitchStatement(node) { + this.word("switch"); + this.space(); + this.token("("); + this.print(node.discriminant, node); + this.token(")"); + this.space(); + this.token("{"); + this.printSequence(node.cases, node, { + indent: true, + + addNewlines(leading, cas) { + if (!leading && node.cases[node.cases.length - 1] === cas) return -1; + } + + }); + this.token("}"); + } + + function SwitchCase(node) { + if (node.test) { + this.word("case"); + this.space(); + this.print(node.test, node); + this.token(":"); + } else { + this.word("default"); + this.token(":"); + } + + if (node.consequent.length) { + this.newline(); + this.printSequence(node.consequent, node, { + indent: true + }); + } + } + + function DebuggerStatement() { + this.word("debugger"); + this.semicolon(); + } + + function variableDeclarationIndent() { + this.token(","); + this.newline(); + if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true); + } + + function constDeclarationIndent() { + this.token(","); + this.newline(); + if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true); + } + + function VariableDeclaration(node, parent) { + if (node.declare) { + this.word("declare"); + this.space(); + } + + this.word(node.kind); + this.space(); + let hasInits = false; + + if (!t().isFor(parent)) { + for (const declar of node.declarations) { + if (declar.init) { + hasInits = true; + } + } + } + + let separator; + + if (hasInits) { + separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent; + } + + this.printList(node.declarations, node, { + separator + }); + + if (t().isFor(parent)) { + if (parent.left === node || parent.init === node) return; + } + + this.semicolon(); + } + + function VariableDeclarator(node) { + this.print(node.id, node); + if (node.definite) this.token("!"); + this.print(node.id.typeAnnotation, node); + + if (node.init) { + this.space(); + this.token("="); + this.space(); + this.print(node.init, node); + } + } + return statements; +} + +var classes = {}; + +var hasRequiredClasses; + +function requireClasses () { + if (hasRequiredClasses) return classes; + hasRequiredClasses = 1; + + Object.defineProperty(classes, "__esModule", { + value: true + }); + classes.ClassExpression = classes.ClassDeclaration = ClassDeclaration; + classes.ClassBody = ClassBody; + classes.ClassProperty = ClassProperty; + classes.ClassPrivateProperty = ClassPrivateProperty; + classes.ClassMethod = ClassMethod; + classes.ClassPrivateMethod = ClassPrivateMethod; + classes._classMethodHead = _classMethodHead; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function ClassDeclaration(node, parent) { + if (!this.format.decoratorsBeforeExport || !t().isExportDefaultDeclaration(parent) && !t().isExportNamedDeclaration(parent)) { + this.printJoin(node.decorators, node); + } + + if (node.declare) { + this.word("declare"); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + this.word("class"); + + if (node.id) { + this.space(); + this.print(node.id, node); + } + + this.print(node.typeParameters, node); + + if (node.superClass) { + this.space(); + this.word("extends"); + this.space(); + this.print(node.superClass, node); + this.print(node.superTypeParameters, node); + } + + if (node.implements) { + this.space(); + this.word("implements"); + this.space(); + this.printList(node.implements, node); + } + + this.space(); + this.print(node.body, node); + } + + function ClassBody(node) { + this.token("{"); + this.printInnerComments(node); + + if (node.body.length === 0) { + this.token("}"); + } else { + this.newline(); + this.indent(); + this.printSequence(node.body, node); + this.dedent(); + if (!this.endsWith("\n")) this.newline(); + this.rightBrace(); + } + } + + function ClassProperty(node) { + this.printJoin(node.decorators, node); + + if (node.accessibility) { + this.word(node.accessibility); + this.space(); + } + + if (node.static) { + this.word("static"); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + if (node.readonly) { + this.word("readonly"); + this.space(); + } + + if (node.computed) { + this.token("["); + this.print(node.key, node); + this.token("]"); + } else { + this._variance(node); + + this.print(node.key, node); + } + + if (node.optional) { + this.token("?"); + } + + if (node.definite) { + this.token("!"); + } + + this.print(node.typeAnnotation, node); + + if (node.value) { + this.space(); + this.token("="); + this.space(); + this.print(node.value, node); + } + + this.semicolon(); + } + + function ClassPrivateProperty(node) { + if (node.static) { + this.word("static"); + this.space(); + } + + this.print(node.key, node); + this.print(node.typeAnnotation, node); + + if (node.value) { + this.space(); + this.token("="); + this.space(); + this.print(node.value, node); + } + + this.semicolon(); + } + + function ClassMethod(node) { + this._classMethodHead(node); + + this.space(); + this.print(node.body, node); + } + + function ClassPrivateMethod(node) { + this._classMethodHead(node); + + this.space(); + this.print(node.body, node); + } + + function _classMethodHead(node) { + this.printJoin(node.decorators, node); + + if (node.accessibility) { + this.word(node.accessibility); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + if (node.static) { + this.word("static"); + this.space(); + } + + this._methodHead(node); + } + return classes; +} + +var methods = {}; + +var hasRequiredMethods; + +function requireMethods () { + if (hasRequiredMethods) return methods; + hasRequiredMethods = 1; + + Object.defineProperty(methods, "__esModule", { + value: true + }); + methods._params = _params; + methods._parameters = _parameters; + methods._param = _param; + methods._methodHead = _methodHead; + methods._predicate = _predicate; + methods._functionHead = _functionHead; + methods.FunctionDeclaration = methods.FunctionExpression = FunctionExpression; + methods.ArrowFunctionExpression = ArrowFunctionExpression; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function _params(node) { + this.print(node.typeParameters, node); + this.token("("); + + this._parameters(node.params, node); + + this.token(")"); + this.print(node.returnType, node); + } + + function _parameters(parameters, parent) { + for (let i = 0; i < parameters.length; i++) { + this._param(parameters[i], parent); + + if (i < parameters.length - 1) { + this.token(","); + this.space(); + } + } + } + + function _param(parameter, parent) { + this.printJoin(parameter.decorators, parameter); + this.print(parameter, parent); + if (parameter.optional) this.token("?"); + this.print(parameter.typeAnnotation, parameter); + } + + function _methodHead(node) { + const kind = node.kind; + const key = node.key; + + if (kind === "get" || kind === "set") { + this.word(kind); + this.space(); + } + + if (node.async) { + this.word("async"); + this.space(); + } + + if (kind === "method" || kind === "init") { + if (node.generator) { + this.token("*"); + } + } + + if (node.computed) { + this.token("["); + this.print(key, node); + this.token("]"); + } else { + this.print(key, node); + } + + if (node.optional) { + this.token("?"); + } + + this._params(node); + } + + function _predicate(node) { + if (node.predicate) { + if (!node.returnType) { + this.token(":"); + } + + this.space(); + this.print(node.predicate, node); + } + } + + function _functionHead(node) { + if (node.async) { + this.word("async"); + this.space(); + } + + this.word("function"); + if (node.generator) this.token("*"); + this.space(); + + if (node.id) { + this.print(node.id, node); + } + + this._params(node); + + this._predicate(node); + } + + function FunctionExpression(node) { + this._functionHead(node); + + this.space(); + this.print(node.body, node); + } + + function ArrowFunctionExpression(node) { + if (node.async) { + this.word("async"); + this.space(); + } + + const firstParam = node.params[0]; + + if (node.params.length === 1 && t().isIdentifier(firstParam) && !hasTypes(node, firstParam)) { + if (this.format.retainLines && node.loc && node.body.loc && node.loc.start.line < node.body.loc.start.line) { + this.token("("); + + if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) { + this.indent(); + this.print(firstParam, node); + this.dedent(); + + this._catchUp("start", node.body.loc); + } else { + this.print(firstParam, node); + } + + this.token(")"); + } else { + this.print(firstParam, node); + } + } else { + this._params(node); + } + + this._predicate(node); + + this.space(); + this.token("=>"); + this.space(); + this.print(node.body, node); + } + + function hasTypes(node, param) { + return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments; + } + return methods; +} + +var modules = {}; + +var hasRequiredModules; + +function requireModules () { + if (hasRequiredModules) return modules; + hasRequiredModules = 1; + + Object.defineProperty(modules, "__esModule", { + value: true + }); + modules.ImportSpecifier = ImportSpecifier; + modules.ImportDefaultSpecifier = ImportDefaultSpecifier; + modules.ExportDefaultSpecifier = ExportDefaultSpecifier; + modules.ExportSpecifier = ExportSpecifier; + modules.ExportNamespaceSpecifier = ExportNamespaceSpecifier; + modules.ExportAllDeclaration = ExportAllDeclaration; + modules.ExportNamedDeclaration = ExportNamedDeclaration; + modules.ExportDefaultDeclaration = ExportDefaultDeclaration; + modules.ImportDeclaration = ImportDeclaration; + modules.ImportNamespaceSpecifier = ImportNamespaceSpecifier; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function ImportSpecifier(node) { + if (node.importKind === "type" || node.importKind === "typeof") { + this.word(node.importKind); + this.space(); + } + + this.print(node.imported, node); + + if (node.local && node.local.name !== node.imported.name) { + this.space(); + this.word("as"); + this.space(); + this.print(node.local, node); + } + } + + function ImportDefaultSpecifier(node) { + this.print(node.local, node); + } + + function ExportDefaultSpecifier(node) { + this.print(node.exported, node); + } + + function ExportSpecifier(node) { + this.print(node.local, node); + + if (node.exported && node.local.name !== node.exported.name) { + this.space(); + this.word("as"); + this.space(); + this.print(node.exported, node); + } + } + + function ExportNamespaceSpecifier(node) { + this.token("*"); + this.space(); + this.word("as"); + this.space(); + this.print(node.exported, node); + } + + function ExportAllDeclaration(node) { + this.word("export"); + this.space(); + + if (node.exportKind === "type") { + this.word("type"); + this.space(); + } + + this.token("*"); + this.space(); + this.word("from"); + this.space(); + this.print(node.source, node); + this.semicolon(); + } + + function ExportNamedDeclaration(node) { + if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) { + this.printJoin(node.declaration.decorators, node); + } + + this.word("export"); + this.space(); + ExportDeclaration.apply(this, arguments); + } + + function ExportDefaultDeclaration(node) { + if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) { + this.printJoin(node.declaration.decorators, node); + } + + this.word("export"); + this.space(); + this.word("default"); + this.space(); + ExportDeclaration.apply(this, arguments); + } + + function ExportDeclaration(node) { + if (node.declaration) { + const declar = node.declaration; + this.print(declar, node); + if (!t().isStatement(declar)) this.semicolon(); + } else { + if (node.exportKind === "type") { + this.word("type"); + this.space(); + } + + const specifiers = node.specifiers.slice(0); + let hasSpecial = false; + + while (true) { + const first = specifiers[0]; + + if (t().isExportDefaultSpecifier(first) || t().isExportNamespaceSpecifier(first)) { + hasSpecial = true; + this.print(specifiers.shift(), node); + + if (specifiers.length) { + this.token(","); + this.space(); + } + } else { + break; + } + } + + if (specifiers.length || !specifiers.length && !hasSpecial) { + this.token("{"); + + if (specifiers.length) { + this.space(); + this.printList(specifiers, node); + this.space(); + } + + this.token("}"); + } + + if (node.source) { + this.space(); + this.word("from"); + this.space(); + this.print(node.source, node); + } + + this.semicolon(); + } + } + + function ImportDeclaration(node) { + this.word("import"); + this.space(); + + if (node.importKind === "type" || node.importKind === "typeof") { + this.word(node.importKind); + this.space(); + } + + const specifiers = node.specifiers.slice(0); + + if (specifiers && specifiers.length) { + while (true) { + const first = specifiers[0]; + + if (t().isImportDefaultSpecifier(first) || t().isImportNamespaceSpecifier(first)) { + this.print(specifiers.shift(), node); + + if (specifiers.length) { + this.token(","); + this.space(); + } + } else { + break; + } + } + + if (specifiers.length) { + this.token("{"); + this.space(); + this.printList(specifiers, node); + this.space(); + this.token("}"); + } + + this.space(); + this.word("from"); + this.space(); + } + + this.print(node.source, node); + this.semicolon(); + } + + function ImportNamespaceSpecifier(node) { + this.token("*"); + this.space(); + this.word("as"); + this.space(); + this.print(node.local, node); + } + return modules; +} + +var types = {}; + +var jsesc_1; +var hasRequiredJsesc; + +function requireJsesc () { + if (hasRequiredJsesc) return jsesc_1; + hasRequiredJsesc = 1; + + const object = {}; + const hasOwnProperty = object.hasOwnProperty; + const forOwn = (object, callback) => { + for (const key in object) { + if (hasOwnProperty.call(object, key)) { + callback(key, object[key]); + } + } + }; + + const extend = (destination, source) => { + if (!source) { + return destination; + } + forOwn(source, (key, value) => { + destination[key] = value; + }); + return destination; + }; + + const forEach = (array, callback) => { + const length = array.length; + let index = -1; + while (++index < length) { + callback(array[index]); + } + }; + + const toString = object.toString; + const isArray = Array.isArray; + const isBuffer = Buffer.isBuffer; + const isObject = (value) => { + // This is a very simple check, but it’s good enough for what we need. + return toString.call(value) == '[object Object]'; + }; + const isString = (value) => { + return typeof value == 'string' || + toString.call(value) == '[object String]'; + }; + const isNumber = (value) => { + return typeof value == 'number' || + toString.call(value) == '[object Number]'; + }; + const isFunction = (value) => { + return typeof value == 'function'; + }; + const isMap = (value) => { + return toString.call(value) == '[object Map]'; + }; + const isSet = (value) => { + return toString.call(value) == '[object Set]'; + }; + + /*--------------------------------------------------------------------------*/ + + // https://mathiasbynens.be/notes/javascript-escapes#single + const singleEscapes = { + '"': '\\"', + '\'': '\\\'', + '\\': '\\\\', + '\b': '\\b', + '\f': '\\f', + '\n': '\\n', + '\r': '\\r', + '\t': '\\t' + // `\v` is omitted intentionally, because in IE < 9, '\v' == 'v'. + // '\v': '\\x0B' + }; + const regexSingleEscape = /["'\\\b\f\n\r\t]/; + + const regexDigit = /[0-9]/; + const regexWhitelist = /[ !#-&\(-\[\]-_a-~]/; + + const jsesc = (argument, options) => { + const increaseIndentation = () => { + oldIndent = indent; + ++options.indentLevel; + indent = options.indent.repeat(options.indentLevel); + }; + // Handle options + const defaults = { + 'escapeEverything': false, + 'minimal': false, + 'isScriptContext': false, + 'quotes': 'single', + 'wrap': false, + 'es6': false, + 'json': false, + 'compact': true, + 'lowercaseHex': false, + 'numbers': 'decimal', + 'indent': '\t', + 'indentLevel': 0, + '__inline1__': false, + '__inline2__': false + }; + const json = options && options.json; + if (json) { + defaults.quotes = 'double'; + defaults.wrap = true; + } + options = extend(defaults, options); + if ( + options.quotes != 'single' && + options.quotes != 'double' && + options.quotes != 'backtick' + ) { + options.quotes = 'single'; + } + const quote = options.quotes == 'double' ? + '"' : + (options.quotes == 'backtick' ? + '`' : + '\'' + ); + const compact = options.compact; + const lowercaseHex = options.lowercaseHex; + let indent = options.indent.repeat(options.indentLevel); + let oldIndent = ''; + const inline1 = options.__inline1__; + const inline2 = options.__inline2__; + const newLine = compact ? '' : '\n'; + let result; + let isEmpty = true; + const useBinNumbers = options.numbers == 'binary'; + const useOctNumbers = options.numbers == 'octal'; + const useDecNumbers = options.numbers == 'decimal'; + const useHexNumbers = options.numbers == 'hexadecimal'; + + if (json && argument && isFunction(argument.toJSON)) { + argument = argument.toJSON(); + } + + if (!isString(argument)) { + if (isMap(argument)) { + if (argument.size == 0) { + return 'new Map()'; + } + if (!compact) { + options.__inline1__ = true; + options.__inline2__ = false; + } + return 'new Map(' + jsesc(Array.from(argument), options) + ')'; + } + if (isSet(argument)) { + if (argument.size == 0) { + return 'new Set()'; + } + return 'new Set(' + jsesc(Array.from(argument), options) + ')'; + } + if (isBuffer(argument)) { + if (argument.length == 0) { + return 'Buffer.from([])'; + } + return 'Buffer.from(' + jsesc(Array.from(argument), options) + ')'; + } + if (isArray(argument)) { + result = []; + options.wrap = true; + if (inline1) { + options.__inline1__ = false; + options.__inline2__ = true; + } + if (!inline2) { + increaseIndentation(); + } + forEach(argument, (value) => { + isEmpty = false; + if (inline2) { + options.__inline2__ = false; + } + result.push( + (compact || inline2 ? '' : indent) + + jsesc(value, options) + ); + }); + if (isEmpty) { + return '[]'; + } + if (inline2) { + return '[' + result.join(', ') + ']'; + } + return '[' + newLine + result.join(',' + newLine) + newLine + + (compact ? '' : oldIndent) + ']'; + } else if (isNumber(argument)) { + if (json) { + // Some number values (e.g. `Infinity`) cannot be represented in JSON. + return JSON.stringify(argument); + } + if (useDecNumbers) { + return String(argument); + } + if (useHexNumbers) { + let hexadecimal = argument.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + return '0x' + hexadecimal; + } + if (useBinNumbers) { + return '0b' + argument.toString(2); + } + if (useOctNumbers) { + return '0o' + argument.toString(8); + } + } else if (!isObject(argument)) { + if (json) { + // For some values (e.g. `undefined`, `function` objects), + // `JSON.stringify(value)` returns `undefined` (which isn’t valid + // JSON) instead of `'null'`. + return JSON.stringify(argument) || 'null'; + } + return String(argument); + } else { // it’s an object + result = []; + options.wrap = true; + increaseIndentation(); + forOwn(argument, (key, value) => { + isEmpty = false; + result.push( + (compact ? '' : indent) + + jsesc(key, options) + ':' + + (compact ? '' : ' ') + + jsesc(value, options) + ); + }); + if (isEmpty) { + return '{}'; + } + return '{' + newLine + result.join(',' + newLine) + newLine + + (compact ? '' : oldIndent) + '}'; + } + } + + const string = argument; + // Loop over each code unit in the string and escape it + let index = -1; + const length = string.length; + result = ''; + while (++index < length) { + const character = string.charAt(index); + if (options.es6) { + const first = string.charCodeAt(index); + if ( // check if it’s the start of a surrogate pair + first >= 0xD800 && first <= 0xDBFF && // high surrogate + length > index + 1 // there is a next code unit + ) { + const second = string.charCodeAt(index + 1); + if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + const codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; + let hexadecimal = codePoint.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + result += '\\u{' + hexadecimal + '}'; + ++index; + continue; + } + } + } + if (!options.escapeEverything) { + if (regexWhitelist.test(character)) { + // It’s a printable ASCII character that is not `"`, `'` or `\`, + // so don’t escape it. + result += character; + continue; + } + if (character == '"') { + result += quote == character ? '\\"' : character; + continue; + } + if (character == '`') { + result += quote == character ? '\\`' : character; + continue; + } + if (character == '\'') { + result += quote == character ? '\\\'' : character; + continue; + } + } + if ( + character == '\0' && + !json && + !regexDigit.test(string.charAt(index + 1)) + ) { + result += '\\0'; + continue; + } + if (regexSingleEscape.test(character)) { + // no need for a `hasOwnProperty` check here + result += singleEscapes[character]; + continue; + } + const charCode = character.charCodeAt(0); + if (options.minimal && charCode != 0x2028 && charCode != 0x2029) { + result += character; + continue; + } + let hexadecimal = charCode.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + const longhand = hexadecimal.length > 2 || json; + const escaped = '\\' + (longhand ? 'u' : 'x') + + ('0000' + hexadecimal).slice(longhand ? -4 : -2); + result += escaped; + continue; + } + if (options.wrap) { + result = quote + result + quote; + } + if (quote == '`') { + result = result.replace(/\$\{/g, '\\\$\{'); + } + if (options.isScriptContext) { + // https://mathiasbynens.be/notes/etago + return result + .replace(/<\/(script|style)/gi, '<\\/$1') + .replace(/' + + commentColor.close + ); + }; // Separate the functions to format props, children, and element, + // so a plugin could override a particular function, if needed. + // Too bad, so sad: the traditional (but unnecessary) space + // in a self-closing tagColor requires a second test of printedProps. + + markup.printComment = printComment; + + const printElement = ( + type, + printedProps, + printedChildren, + config, + indentation + ) => { + const tagColor = config.colors.tag; + return ( + tagColor.open + + '<' + + type + + (printedProps && + tagColor.close + + printedProps + + config.spacingOuter + + indentation + + tagColor.open) + + (printedChildren + ? '>' + + tagColor.close + + printedChildren + + config.spacingOuter + + indentation + + tagColor.open + + '' + + tagColor.close + ); + }; + + markup.printElement = printElement; + + const printElementAsLeaf = (type, config) => { + const tagColor = config.colors.tag; + return ( + tagColor.open + + '<' + + type + + tagColor.close + + ' …' + + tagColor.open + + ' />' + + tagColor.close + ); + }; + + markup.printElementAsLeaf = printElementAsLeaf; + return markup; +} + +var hasRequiredDOMElement; + +function requireDOMElement () { + if (hasRequiredDOMElement) return DOMElement; + hasRequiredDOMElement = 1; + + Object.defineProperty(DOMElement, '__esModule', { + value: true + }); + DOMElement.default = DOMElement.serialize = DOMElement.test = void 0; + + var _markup = requireMarkup(); + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noformat + * @nolint + * @lightSyntaxTransform + * @preventMunge + * @oncall react_core + */ + const ELEMENT_NODE = 1; + const TEXT_NODE = 3; + const COMMENT_NODE = 8; + const FRAGMENT_NODE = 11; + const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/; + + const testNode = (nodeType, name) => + (nodeType === ELEMENT_NODE && ELEMENT_REGEXP.test(name)) || + (nodeType === TEXT_NODE && name === 'Text') || + (nodeType === COMMENT_NODE && name === 'Comment') || + (nodeType === FRAGMENT_NODE && name === 'DocumentFragment'); + + const test = val => + val && + val.constructor && + val.constructor.name && + testNode(val.nodeType, val.constructor.name); + + DOMElement.test = test; + + function nodeIsText(node) { + return node.nodeType === TEXT_NODE; + } + + function nodeIsComment(node) { + return node.nodeType === COMMENT_NODE; + } + + function nodeIsFragment(node) { + return node.nodeType === FRAGMENT_NODE; + } + + const serialize = (node, config, indentation, depth, refs, printer) => { + if (nodeIsText(node)) { + return (0, _markup.printText)(node.data, config); + } + + if (nodeIsComment(node)) { + return (0, _markup.printComment)(node.data, config); + } + + const type = nodeIsFragment(node) + ? `DocumentFragment` + : node.tagName.toLowerCase(); + + if (++depth > config.maxDepth) { + return (0, _markup.printElementAsLeaf)(type, config); + } + + return (0, _markup.printElement)( + type, + (0, _markup.printProps)( + nodeIsFragment(node) + ? [] + : Array.from(node.attributes) + .map(attr => attr.name) + .sort(), + nodeIsFragment(node) + ? [] + : Array.from(node.attributes).reduce((props, attribute) => { + props[attribute.name] = attribute.value; + return props; + }, {}), + config, + indentation + config.indent, + depth, + refs, + printer + ), + (0, _markup.printChildren)( + Array.prototype.slice.call(node.childNodes || node.children), + config, + indentation + config.indent, + depth, + refs, + printer + ), + config, + indentation + ); + }; + + DOMElement.serialize = serialize; + const plugin = { + serialize, + test + }; + var _default = plugin; + DOMElement.default = _default; + return DOMElement; +} + +var Immutable = {}; + +var hasRequiredImmutable; + +function requireImmutable () { + if (hasRequiredImmutable) return Immutable; + hasRequiredImmutable = 1; + + Object.defineProperty(Immutable, '__esModule', { + value: true + }); + Immutable.default = Immutable.test = Immutable.serialize = void 0; + + var _collections = requireCollections(); + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noformat + * @nolint + * @lightSyntaxTransform + * @preventMunge + * @oncall react_core + */ + // SENTINEL constants are from https://github.com/facebook/immutable-js + const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; + const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@'; + const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; + const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@'; + const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@'; + const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // immutable v4 + + const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@'; + const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@'; + const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@'; + + const getImmutableName = name => 'Immutable.' + name; + + const printAsLeaf = name => '[' + name + ']'; + + const SPACE = ' '; + const LAZY = '…'; // Seq is lazy if it calls a method like filter + + const printImmutableEntries = ( + val, + config, + indentation, + depth, + refs, + printer, + type + ) => + ++depth > config.maxDepth + ? printAsLeaf(getImmutableName(type)) + : getImmutableName(type) + + SPACE + + '{' + + (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer + ) + + '}'; // Record has an entries method because it is a collection in immutable v3. + // Return an iterator for Immutable Record from version v3 or v4. + + const getRecordEntries = val => { + let i = 0; + return { + next() { + if (i < val._keys.length) { + const key = val._keys[i++]; + return { + done: false, + value: [key, val.get(key)] + }; + } + + return { + done: true + }; + } + }; + }; + + const printImmutableRecord = ( + val, + config, + indentation, + depth, + refs, + printer + ) => { + // _name property is defined only for an Immutable Record instance + // which was constructed with a second optional descriptive name arg + const name = getImmutableName(val._name || 'Record'); + return ++depth > config.maxDepth + ? printAsLeaf(name) + : name + + SPACE + + '{' + + (0, _collections.printIteratorEntries)( + getRecordEntries(val), + config, + indentation, + depth, + refs, + printer + ) + + '}'; + }; + + const printImmutableSeq = (val, config, indentation, depth, refs, printer) => { + const name = getImmutableName('Seq'); + + if (++depth > config.maxDepth) { + return printAsLeaf(name); + } + + if (val[IS_KEYED_SENTINEL]) { + return ( + name + + SPACE + + '{' + // from Immutable collection of entries or from ECMAScript object + (val._iter || val._object + ? (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer + ) + : LAZY) + + '}' + ); + } + + return ( + name + + SPACE + + '[' + + (val._iter || // from Immutable collection of values + val._array || // from ECMAScript array + val._collection || // from ECMAScript collection in immutable v4 + val._iterable // from ECMAScript collection in immutable v3 + ? (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + : LAZY) + + ']' + ); + }; + + const printImmutableValues = ( + val, + config, + indentation, + depth, + refs, + printer, + type + ) => + ++depth > config.maxDepth + ? printAsLeaf(getImmutableName(type)) + : getImmutableName(type) + + SPACE + + '[' + + (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + + ']'; + + const serialize = (val, config, indentation, depth, refs, printer) => { + if (val[IS_MAP_SENTINEL]) { + return printImmutableEntries( + val, + config, + indentation, + depth, + refs, + printer, + val[IS_ORDERED_SENTINEL] ? 'OrderedMap' : 'Map' + ); + } + + if (val[IS_LIST_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + 'List' + ); + } + + if (val[IS_SET_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + val[IS_ORDERED_SENTINEL] ? 'OrderedSet' : 'Set' + ); + } + + if (val[IS_STACK_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + 'Stack' + ); + } + + if (val[IS_SEQ_SENTINEL]) { + return printImmutableSeq(val, config, indentation, depth, refs, printer); + } // For compatibility with immutable v3 and v4, let record be the default. + + return printImmutableRecord(val, config, indentation, depth, refs, printer); + }; // Explicitly comparing sentinel properties to true avoids false positive + // when mock identity-obj-proxy returns the key as the value for any key. + + Immutable.serialize = serialize; + + const test = val => + val && + (val[IS_ITERABLE_SENTINEL] === true || val[IS_RECORD_SENTINEL] === true); + + Immutable.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + Immutable.default = _default; + return Immutable; +} + +var ReactElement = {}; + +var reactIsExports = {}; +var reactIs = { + get exports(){ return reactIsExports; }, + set exports(v){ reactIsExports = v; }, +}; + +var reactIs_development = {}; + +var hasRequiredReactIs_development; + +function requireReactIs_development () { + if (hasRequiredReactIs_development) return reactIs_development; + hasRequiredReactIs_development = 1; + + + + { + (function() { + + // The Symbol used to tag the ReactElement-like types. If there is no native Symbol + // nor polyfill, then a plain number is used for performance. + var hasSymbol = typeof Symbol === 'function' && Symbol.for; + var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; + var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; + var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; + var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; + var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; + var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; + var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary + // (unstable) APIs that have been removed. Can we remove the symbols? + + var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; + var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; + var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; + var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; + var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; + var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; + var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; + var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9; + var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; + var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; + var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; + + function isValidElementType(type) { + return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. + type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE); + } + + function typeOf(object) { + if (typeof object === 'object' && object !== null) { + var $$typeof = object.$$typeof; + + switch ($$typeof) { + case REACT_ELEMENT_TYPE: + var type = object.type; + + switch (type) { + case REACT_ASYNC_MODE_TYPE: + case REACT_CONCURRENT_MODE_TYPE: + case REACT_FRAGMENT_TYPE: + case REACT_PROFILER_TYPE: + case REACT_STRICT_MODE_TYPE: + case REACT_SUSPENSE_TYPE: + return type; + + default: + var $$typeofType = type && type.$$typeof; + + switch ($$typeofType) { + case REACT_CONTEXT_TYPE: + case REACT_FORWARD_REF_TYPE: + case REACT_LAZY_TYPE: + case REACT_MEMO_TYPE: + case REACT_PROVIDER_TYPE: + return $$typeofType; + + default: + return $$typeof; + } + + } + + case REACT_PORTAL_TYPE: + return $$typeof; + } + } + + return undefined; + } // AsyncMode is deprecated along with isAsyncMode + + var AsyncMode = REACT_ASYNC_MODE_TYPE; + var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; + var ContextConsumer = REACT_CONTEXT_TYPE; + var ContextProvider = REACT_PROVIDER_TYPE; + var Element = REACT_ELEMENT_TYPE; + var ForwardRef = REACT_FORWARD_REF_TYPE; + var Fragment = REACT_FRAGMENT_TYPE; + var Lazy = REACT_LAZY_TYPE; + var Memo = REACT_MEMO_TYPE; + var Portal = REACT_PORTAL_TYPE; + var Profiler = REACT_PROFILER_TYPE; + var StrictMode = REACT_STRICT_MODE_TYPE; + var Suspense = REACT_SUSPENSE_TYPE; + var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated + + function isAsyncMode(object) { + { + if (!hasWarnedAboutDeprecatedIsAsyncMode) { + hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint + + console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); + } + } + + return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; + } + function isConcurrentMode(object) { + return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; + } + function isContextConsumer(object) { + return typeOf(object) === REACT_CONTEXT_TYPE; + } + function isContextProvider(object) { + return typeOf(object) === REACT_PROVIDER_TYPE; + } + function isElement(object) { + return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; + } + function isForwardRef(object) { + return typeOf(object) === REACT_FORWARD_REF_TYPE; + } + function isFragment(object) { + return typeOf(object) === REACT_FRAGMENT_TYPE; + } + function isLazy(object) { + return typeOf(object) === REACT_LAZY_TYPE; + } + function isMemo(object) { + return typeOf(object) === REACT_MEMO_TYPE; + } + function isPortal(object) { + return typeOf(object) === REACT_PORTAL_TYPE; + } + function isProfiler(object) { + return typeOf(object) === REACT_PROFILER_TYPE; + } + function isStrictMode(object) { + return typeOf(object) === REACT_STRICT_MODE_TYPE; + } + function isSuspense(object) { + return typeOf(object) === REACT_SUSPENSE_TYPE; + } + + reactIs_development.AsyncMode = AsyncMode; + reactIs_development.ConcurrentMode = ConcurrentMode; + reactIs_development.ContextConsumer = ContextConsumer; + reactIs_development.ContextProvider = ContextProvider; + reactIs_development.Element = Element; + reactIs_development.ForwardRef = ForwardRef; + reactIs_development.Fragment = Fragment; + reactIs_development.Lazy = Lazy; + reactIs_development.Memo = Memo; + reactIs_development.Portal = Portal; + reactIs_development.Profiler = Profiler; + reactIs_development.StrictMode = StrictMode; + reactIs_development.Suspense = Suspense; + reactIs_development.isAsyncMode = isAsyncMode; + reactIs_development.isConcurrentMode = isConcurrentMode; + reactIs_development.isContextConsumer = isContextConsumer; + reactIs_development.isContextProvider = isContextProvider; + reactIs_development.isElement = isElement; + reactIs_development.isForwardRef = isForwardRef; + reactIs_development.isFragment = isFragment; + reactIs_development.isLazy = isLazy; + reactIs_development.isMemo = isMemo; + reactIs_development.isPortal = isPortal; + reactIs_development.isProfiler = isProfiler; + reactIs_development.isStrictMode = isStrictMode; + reactIs_development.isSuspense = isSuspense; + reactIs_development.isValidElementType = isValidElementType; + reactIs_development.typeOf = typeOf; + })(); + } + return reactIs_development; +} + +var hasRequiredReactIs; + +function requireReactIs () { + if (hasRequiredReactIs) return reactIsExports; + hasRequiredReactIs = 1; + (function (module) { + + { + module.exports = requireReactIs_development(); + } +} (reactIs)); + return reactIsExports; +} + +var hasRequiredReactElement; + +function requireReactElement () { + if (hasRequiredReactElement) return ReactElement; + hasRequiredReactElement = 1; + + Object.defineProperty(ReactElement, '__esModule', { + value: true + }); + ReactElement.default = ReactElement.test = ReactElement.serialize = void 0; + + var ReactIs = _interopRequireWildcard(requireReactIs()); + + var _markup = requireMarkup(); + + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = + Object.defineProperty && Object.getOwnPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : {}; + if (desc.get || desc.set) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + } + newObj.default = obj; + return newObj; + } + } + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @noformat + * @nolint + * @lightSyntaxTransform + * @preventMunge + * @oncall react_core + */ + // Given element.props.children, or subtree during recursive traversal, + // return flattened array of children. + const getChildren = (arg, children = []) => { + if (Array.isArray(arg)) { + arg.forEach(item => { + getChildren(item, children); + }); + } else if (arg != null && arg !== false) { + children.push(arg); + } + + return children; + }; + + const getType = element => { + const type = element.type; + + if (typeof type === 'string') { + return type; + } + + if (typeof type === 'function') { + return type.displayName || type.name || 'Unknown'; + } + + if (ReactIs.isFragment(element)) { + return 'React.Fragment'; + } + + if (ReactIs.isSuspense(element)) { + return 'React.Suspense'; + } + + if (typeof type === 'object' && type !== null) { + if (ReactIs.isContextProvider(element)) { + return 'Context.Provider'; + } + + if (ReactIs.isContextConsumer(element)) { + return 'Context.Consumer'; + } + + if (ReactIs.isForwardRef(element)) { + const functionName = type.render.displayName || type.render.name || ''; + return functionName !== '' + ? 'ForwardRef(' + functionName + ')' + : 'ForwardRef'; + } + + if (ReactIs.isMemo(type)) { + const functionName = + type.displayName || type.type.displayName || type.type.name || ''; + return functionName !== '' ? 'Memo(' + functionName + ')' : 'Memo'; + } + } + + return 'UNDEFINED'; + }; + + const getPropKeys = element => { + const props = element.props; + return Object.keys(props) + .filter(key => key !== 'children' && props[key] !== undefined) + .sort(); + }; + + const serialize = (element, config, indentation, depth, refs, printer) => + ++depth > config.maxDepth + ? (0, _markup.printElementAsLeaf)(getType(element), config) + : (0, _markup.printElement)( + getType(element), + (0, _markup.printProps)( + getPropKeys(element), + element.props, + config, + indentation + config.indent, + depth, + refs, + printer + ), + (0, _markup.printChildren)( + getChildren(element.props.children), + config, + indentation + config.indent, + depth, + refs, + printer + ), + config, + indentation + ); + + ReactElement.serialize = serialize; + + const test = val => val && ReactIs.isElement(val); + + ReactElement.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + ReactElement.default = _default; + return ReactElement; +} + +var ReactTestComponent = {}; + +var hasRequiredReactTestComponent; + +function requireReactTestComponent () { + if (hasRequiredReactTestComponent) return ReactTestComponent; + hasRequiredReactTestComponent = 1; + + Object.defineProperty(ReactTestComponent, '__esModule', { + value: true + }); + ReactTestComponent.default = ReactTestComponent.test = ReactTestComponent.serialize = void 0; + + var _markup = requireMarkup(); + + var Symbol = commonjsGlobal['jest-symbol-do-not-touch'] || commonjsGlobal.Symbol; + const testSymbol = Symbol.for('react.test.json'); + + const getPropKeys = object => { + const props = object.props; + return props + ? Object.keys(props) + .filter(key => props[key] !== undefined) + .sort() + : []; + }; + + const serialize = (object, config, indentation, depth, refs, printer) => + ++depth > config.maxDepth + ? (0, _markup.printElementAsLeaf)(object.type, config) + : (0, _markup.printElement)( + object.type, + object.props + ? (0, _markup.printProps)( + getPropKeys(object), + object.props, + config, + indentation + config.indent, + depth, + refs, + printer + ) + : '', + object.children + ? (0, _markup.printChildren)( + object.children, + config, + indentation + config.indent, + depth, + refs, + printer + ) + : '', + config, + indentation + ); + + ReactTestComponent.serialize = serialize; + + const test = val => val && val.$$typeof === testSymbol; + + ReactTestComponent.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + ReactTestComponent.default = _default; + return ReactTestComponent; +} + +var build; +var hasRequiredBuild; + +function requireBuild () { + if (hasRequiredBuild) return build; + hasRequiredBuild = 1; + + var _ansiStyles = _interopRequireDefault(requireAnsiStyles()); + + var _collections = requireCollections(); + + var _AsymmetricMatcher = _interopRequireDefault( + requireAsymmetricMatcher() + ); + + var _ConvertAnsi = _interopRequireDefault(requireConvertAnsi()); + + var _DOMCollection = _interopRequireDefault(requireDOMCollection()); + + var _DOMElement = _interopRequireDefault(requireDOMElement()); + + var _Immutable = _interopRequireDefault(requireImmutable()); + + var _ReactElement = _interopRequireDefault(requireReactElement()); + + var _ReactTestComponent = _interopRequireDefault( + requireReactTestComponent() + ); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : {default: obj}; + } + + var Symbol = commonjsGlobal['jest-symbol-do-not-touch'] || commonjsGlobal.Symbol; + const toString = Object.prototype.toString; + const toISOString = Date.prototype.toISOString; + const errorToString = Error.prototype.toString; + const regExpToString = RegExp.prototype.toString; + const symbolToString = Symbol.prototype.toString; + /** + * Explicitly comparing typeof constructor to function avoids undefined as name + * when mock identity-obj-proxy returns the key as the value for any key. + */ + + const getConstructorName = val => + (typeof val.constructor === 'function' && val.constructor.name) || 'Object'; + /* global window */ + + /** Is val is equal to global window object? Works even if it does not exist :) */ + + const isWindow = val => typeof window !== 'undefined' && val === window; + + const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; + const NEWLINE_REGEXP = /\n/gi; + + class PrettyFormatPluginError extends Error { + constructor(message, stack) { + super(message); + this.stack = stack; + this.name = this.constructor.name; + } + } + + function isToStringedArrayType(toStringed) { + return ( + toStringed === '[object Array]' || + toStringed === '[object ArrayBuffer]' || + toStringed === '[object DataView]' || + toStringed === '[object Float32Array]' || + toStringed === '[object Float64Array]' || + toStringed === '[object Int8Array]' || + toStringed === '[object Int16Array]' || + toStringed === '[object Int32Array]' || + toStringed === '[object Uint8Array]' || + toStringed === '[object Uint8ClampedArray]' || + toStringed === '[object Uint16Array]' || + toStringed === '[object Uint32Array]' + ); + } + + function printNumber(val) { + return Object.is(val, -0) ? '-0' : String(val); + } + + function printBigInt(val) { + return String(`${val}n`); + } + + function printFunction(val, printFunctionName) { + if (!printFunctionName) { + return '[Function]'; + } + + return '[Function ' + (val.name || 'anonymous') + ']'; + } + + function printSymbol(val) { + return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); + } + + function printError(val) { + return '[' + errorToString.call(val) + ']'; + } + /** + * The first port of call for printing an object, handles most of the + * data-types in JS. + */ + + function printBasicValue(val, printFunctionName, escapeRegex, escapeString) { + if (val === true || val === false) { + return '' + val; + } + + if (val === undefined) { + return 'undefined'; + } + + if (val === null) { + return 'null'; + } + + const typeOf = typeof val; + + if (typeOf === 'number') { + return printNumber(val); + } + + if (typeOf === 'bigint') { + return printBigInt(val); + } + + if (typeOf === 'string') { + if (escapeString) { + return '"' + val.replace(/"|\\/g, '\\$&') + '"'; + } + + return '"' + val + '"'; + } + + if (typeOf === 'function') { + return printFunction(val, printFunctionName); + } + + if (typeOf === 'symbol') { + return printSymbol(val); + } + + const toStringed = toString.call(val); + + if (toStringed === '[object WeakMap]') { + return 'WeakMap {}'; + } + + if (toStringed === '[object WeakSet]') { + return 'WeakSet {}'; + } + + if ( + toStringed === '[object Function]' || + toStringed === '[object GeneratorFunction]' + ) { + return printFunction(val, printFunctionName); + } + + if (toStringed === '[object Symbol]') { + return printSymbol(val); + } + + if (toStringed === '[object Date]') { + return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val); + } + + if (toStringed === '[object Error]') { + return printError(val); + } + + if (toStringed === '[object RegExp]') { + if (escapeRegex) { + // https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js + return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); + } + + return regExpToString.call(val); + } + + if (val instanceof Error) { + return printError(val); + } + + return null; + } + /** + * Handles more complex objects ( such as objects with circular references. + * maps and sets etc ) + */ + + function printComplexValue( + val, + config, + indentation, + depth, + refs, + hasCalledToJSON + ) { + if (refs.indexOf(val) !== -1) { + return '[Circular]'; + } + + refs = refs.slice(); + refs.push(val); + const hitMaxDepth = ++depth > config.maxDepth; + const min = config.min; + + if ( + config.callToJSON && + !hitMaxDepth && + val.toJSON && + typeof val.toJSON === 'function' && + !hasCalledToJSON + ) { + return printer(val.toJSON(), config, indentation, depth, refs, true); + } + + const toStringed = toString.call(val); + + if (toStringed === '[object Arguments]') { + return hitMaxDepth + ? '[Arguments]' + : (min ? '' : 'Arguments ') + + '[' + + (0, _collections.printListItems)( + val, + config, + indentation, + depth, + refs, + printer + ) + + ']'; + } + + if (isToStringedArrayType(toStringed)) { + return hitMaxDepth + ? '[' + val.constructor.name + ']' + : (min ? '' : val.constructor.name + ' ') + + '[' + + (0, _collections.printListItems)( + val, + config, + indentation, + depth, + refs, + printer + ) + + ']'; + } + + if (toStringed === '[object Map]') { + return hitMaxDepth + ? '[Map]' + : 'Map {' + + (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer, + ' => ' + ) + + '}'; + } + + if (toStringed === '[object Set]') { + return hitMaxDepth + ? '[Set]' + : 'Set {' + + (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + + '}'; + } // Avoid failure to serialize global window object in jsdom test environment. + // For example, not even relevant if window is prop of React element. + + return hitMaxDepth || isWindow(val) + ? '[' + getConstructorName(val) + ']' + : (min ? '' : getConstructorName(val) + ' ') + + '{' + + (0, _collections.printObjectProperties)( + val, + config, + indentation, + depth, + refs, + printer + ) + + '}'; + } + + function isNewPlugin(plugin) { + return plugin.serialize != null; + } + + function printPlugin(plugin, val, config, indentation, depth, refs) { + let printed; + + try { + printed = isNewPlugin(plugin) + ? plugin.serialize(val, config, indentation, depth, refs, printer) + : plugin.print( + val, + valChild => printer(valChild, config, indentation, depth, refs), + str => { + const indentationNext = indentation + config.indent; + return ( + indentationNext + + str.replace(NEWLINE_REGEXP, '\n' + indentationNext) + ); + }, + { + edgeSpacing: config.spacingOuter, + min: config.min, + spacing: config.spacingInner + }, + config.colors + ); + } catch (error) { + throw new PrettyFormatPluginError(error.message, error.stack); + } + + if (typeof printed !== 'string') { + throw new Error( + `pretty-format: Plugin must return type "string" but instead returned "${typeof printed}".` + ); + } + + return printed; + } + + function findPlugin(plugins, val) { + for (let p = 0; p < plugins.length; p++) { + try { + if (plugins[p].test(val)) { + return plugins[p]; + } + } catch (error) { + throw new PrettyFormatPluginError(error.message, error.stack); + } + } + + return null; + } + + function printer(val, config, indentation, depth, refs, hasCalledToJSON) { + const plugin = findPlugin(config.plugins, val); + + if (plugin !== null) { + return printPlugin(plugin, val, config, indentation, depth, refs); + } + + const basicResult = printBasicValue( + val, + config.printFunctionName, + config.escapeRegex, + config.escapeString + ); + + if (basicResult !== null) { + return basicResult; + } + + return printComplexValue( + val, + config, + indentation, + depth, + refs, + hasCalledToJSON + ); + } + + const DEFAULT_THEME = { + comment: 'gray', + content: 'reset', + prop: 'yellow', + tag: 'cyan', + value: 'green' + }; + const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME); + const DEFAULT_OPTIONS = { + callToJSON: true, + escapeRegex: false, + escapeString: true, + highlight: false, + indent: 2, + maxDepth: Infinity, + min: false, + plugins: [], + printFunctionName: true, + theme: DEFAULT_THEME + }; + + function validateOptions(options) { + Object.keys(options).forEach(key => { + if (!DEFAULT_OPTIONS.hasOwnProperty(key)) { + throw new Error(`pretty-format: Unknown option "${key}".`); + } + }); + + if (options.min && options.indent !== undefined && options.indent !== 0) { + throw new Error( + 'pretty-format: Options "min" and "indent" cannot be used together.' + ); + } + + if (options.theme !== undefined) { + if (options.theme === null) { + throw new Error(`pretty-format: Option "theme" must not be null.`); + } + + if (typeof options.theme !== 'object') { + throw new Error( + `pretty-format: Option "theme" must be of type "object" but instead received "${typeof options.theme}".` + ); + } + } + } + + const getColorsHighlight = options => + DEFAULT_THEME_KEYS.reduce((colors, key) => { + const value = + options.theme && options.theme[key] !== undefined + ? options.theme[key] + : DEFAULT_THEME[key]; + const color = value && _ansiStyles.default[value]; + + if ( + color && + typeof color.close === 'string' && + typeof color.open === 'string' + ) { + colors[key] = color; + } else { + throw new Error( + `pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.` + ); + } + + return colors; + }, Object.create(null)); + + const getColorsEmpty = () => + DEFAULT_THEME_KEYS.reduce((colors, key) => { + colors[key] = { + close: '', + open: '' + }; + return colors; + }, Object.create(null)); + + const getPrintFunctionName = options => + options && options.printFunctionName !== undefined + ? options.printFunctionName + : DEFAULT_OPTIONS.printFunctionName; + + const getEscapeRegex = options => + options && options.escapeRegex !== undefined + ? options.escapeRegex + : DEFAULT_OPTIONS.escapeRegex; + + const getEscapeString = options => + options && options.escapeString !== undefined + ? options.escapeString + : DEFAULT_OPTIONS.escapeString; + + const getConfig = options => ({ + callToJSON: + options && options.callToJSON !== undefined + ? options.callToJSON + : DEFAULT_OPTIONS.callToJSON, + colors: + options && options.highlight + ? getColorsHighlight(options) + : getColorsEmpty(), + escapeRegex: getEscapeRegex(options), + escapeString: getEscapeString(options), + indent: + options && options.min + ? '' + : createIndent( + options && options.indent !== undefined + ? options.indent + : DEFAULT_OPTIONS.indent + ), + maxDepth: + options && options.maxDepth !== undefined + ? options.maxDepth + : DEFAULT_OPTIONS.maxDepth, + min: options && options.min !== undefined ? options.min : DEFAULT_OPTIONS.min, + plugins: + options && options.plugins !== undefined + ? options.plugins + : DEFAULT_OPTIONS.plugins, + printFunctionName: getPrintFunctionName(options), + spacingInner: options && options.min ? ' ' : '\n', + spacingOuter: options && options.min ? '' : '\n' + }); + + function createIndent(indent) { + return new Array(indent + 1).join(' '); + } + /** + * Returns a presentation string of your `val` object + * @param val any potential JavaScript object + * @param options Custom settings + */ + + function prettyFormat(val, options) { + if (options) { + validateOptions(options); + + if (options.plugins) { + const plugin = findPlugin(options.plugins, val); + + if (plugin !== null) { + return printPlugin(plugin, val, getConfig(options), '', 0, []); + } + } + } + + const basicResult = printBasicValue( + val, + getPrintFunctionName(options), + getEscapeRegex(options), + getEscapeString(options) + ); + + if (basicResult !== null) { + return basicResult; + } + + return printComplexValue(val, getConfig(options), '', 0, []); + } + + prettyFormat.plugins = { + AsymmetricMatcher: _AsymmetricMatcher.default, + ConvertAnsi: _ConvertAnsi.default, + DOMCollection: _DOMCollection.default, + DOMElement: _DOMElement.default, + Immutable: _Immutable.default, + ReactElement: _ReactElement.default, + ReactTestComponent: _ReactTestComponent.default + }; + /* eslint-disable-next-line no-redeclare */ + + build = prettyFormat; + return build; +} + +var buildExports = requireBuild(); +var prettyFormat = /*@__PURE__*/getDefaultExportFromCjs(buildExports); + +var _PostDominator_exit, _PostDominator_nodes; +function computePostDominatorTree(fn, options) { + const graph = buildReverseGraph(fn, options.includeThrowsAsExitNode); + const nodes = computeImmediateDominators(graph); + if (!options.includeThrowsAsExitNode) { + for (const [id] of fn.body.blocks) { + if (!nodes.has(id)) { + nodes.set(id, id); + } + } + } + return new PostDominator(graph.entry, nodes); +} +class PostDominator { + constructor(exit, nodes) { + _PostDominator_exit.set(this, void 0); + _PostDominator_nodes.set(this, void 0); + __classPrivateFieldSet(this, _PostDominator_exit, exit, "f"); + __classPrivateFieldSet(this, _PostDominator_nodes, nodes, "f"); + } + get exit() { + return __classPrivateFieldGet(this, _PostDominator_exit, "f"); + } + get(id) { + const dominator = __classPrivateFieldGet(this, _PostDominator_nodes, "f").get(id); + CompilerError.invariant(dominator !== undefined, { + reason: 'Unknown node', + description: null, + loc: null, + suggestions: null, + }); + return dominator === id ? null : dominator; + } + debug() { + const postDominators = new Map(); + for (const [key, value] of __classPrivateFieldGet(this, _PostDominator_nodes, "f")) { + postDominators.set(`bb${key}`, `bb${value}`); + } + return prettyFormat({ + exit: `bb${this.exit}`, + postDominators, + }); + } +} +_PostDominator_exit = new WeakMap(), _PostDominator_nodes = new WeakMap(); +function computeImmediateDominators(graph) { + const nodes = new Map(); + nodes.set(graph.entry, graph.entry); + let changed = true; + while (changed) { + changed = false; + for (const [id, node] of graph.nodes) { + if (node.id === graph.entry) { + continue; + } + let newIdom = null; + for (const pred of node.preds) { + if (nodes.has(pred)) { + newIdom = pred; + break; + } + } + CompilerError.invariant(newIdom !== null, { + reason: `At least one predecessor must have been visited for block ${id}`, + description: null, + loc: null, + suggestions: null, + }); + for (const pred of node.preds) { + if (pred === newIdom) { + continue; + } + const predDom = nodes.get(pred); + if (predDom !== undefined) { + newIdom = intersect(pred, newIdom, graph, nodes); + } + } + if (nodes.get(id) !== newIdom) { + nodes.set(id, newIdom); + changed = true; + } + } + } + return nodes; +} +function intersect(a, b, graph, nodes) { + let block1 = graph.nodes.get(a); + let block2 = graph.nodes.get(b); + while (block1 !== block2) { + while (block1.index > block2.index) { + const dom = nodes.get(block1.id); + block1 = graph.nodes.get(dom); + } + while (block2.index > block1.index) { + const dom = nodes.get(block2.id); + block2 = graph.nodes.get(dom); + } + } + return block1.id; +} +function buildReverseGraph(fn, includeThrowsAsExitNode) { + const nodes = new Map(); + const exitId = fn.env.nextBlockId; + const exit = { + id: exitId, + index: 0, + preds: new Set(), + succs: new Set(), + }; + nodes.set(exitId, exit); + for (const [id, block] of fn.body.blocks) { + const node = { + id, + index: 0, + preds: new Set(eachTerminalSuccessor(block.terminal)), + succs: new Set(block.preds), + }; + if (block.terminal.kind === 'return') { + node.preds.add(exitId); + exit.succs.add(id); + } + else if (block.terminal.kind === 'throw' && includeThrowsAsExitNode) { + node.preds.add(exitId); + exit.succs.add(id); + } + nodes.set(id, node); + } + const visited = new Set(); + const postorder = []; + function visit(id) { + if (visited.has(id)) { + return; + } + visited.add(id); + const node = nodes.get(id); + for (const successor of node.succs) { + visit(successor); + } + postorder.push(id); + } + visit(exitId); + const rpo = { entry: exitId, nodes: new Map() }; + let index = 0; + for (const id of postorder.reverse()) { + const node = nodes.get(id); + node.index = index++; + rpo.nodes.set(id, node); + } + return rpo; +} + +const DEFAULT_SHAPES = new Map(BUILTIN_SHAPES); +const UNTYPED_GLOBALS = new Set([ + 'Object', + 'Function', + 'RegExp', + 'Date', + 'Error', + 'TypeError', + 'RangeError', + 'ReferenceError', + 'SyntaxError', + 'URIError', + 'EvalError', + 'DataView', + 'Float32Array', + 'Float64Array', + 'Int8Array', + 'Int16Array', + 'Int32Array', + 'WeakMap', + 'Uint8Array', + 'Uint8ClampedArray', + 'Uint16Array', + 'Uint32Array', + 'ArrayBuffer', + 'JSON', + 'console', + 'eval', +]); +const TYPED_GLOBALS = [ + [ + 'Object', + addObject(DEFAULT_SHAPES, 'Object', [ + [ + 'keys', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.Read], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'fromEntries', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutate], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInObjectId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), + ], + [ + 'Array', + addObject(DEFAULT_SHAPES, 'Array', [ + [ + 'isArray', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.Read], + restParam: null, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'from', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [ + Effect.ConditionallyMutateIterator, + Effect.ConditionallyMutate, + Effect.ConditionallyMutate, + ], + restParam: Effect.Read, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'of', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), + ], + [ + 'performance', + addObject(DEFAULT_SHAPES, 'performance', [ + [ + 'now', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'performance.now', + }), + ], + ]), + ], + [ + 'Date', + addObject(DEFAULT_SHAPES, 'Date', [ + [ + 'now', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'Date.now', + }), + ], + ]), + ], + [ + 'Math', + addObject(DEFAULT_SHAPES, 'Math', [ + ['PI', { kind: 'Primitive' }], + [ + 'max', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'min', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'trunc', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'ceil', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'floor', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'pow', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'random', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'Math.random', + }), + ], + ]), + ], + ['Infinity', { kind: 'Primitive' }], + ['NaN', { kind: 'Primitive' }], + [ + 'console', + addObject(DEFAULT_SHAPES, 'console', [ + [ + 'error', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'info', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'log', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'table', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'trace', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'warn', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + ]), + ], + [ + 'Boolean', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'Number', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'String', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'parseInt', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'parseFloat', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'isNaN', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'isFinite', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'encodeURI', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'encodeURIComponent', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'decodeURI', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'decodeURIComponent', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'Map', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutateIterator], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInMapId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }, null, true), + ], + [ + 'Set', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutateIterator], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInSetId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }, null, true), + ], +]; +const REACT_APIS = [ + [ + 'useContext', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useContext', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.Context, + }, BuiltInUseContextHookId), + ], + [ + 'useState', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseStateId }, + calleeEffect: Effect.Read, + hookKind: 'useState', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.State, + }), + ], + [ + 'useActionState', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseActionStateId }, + calleeEffect: Effect.Read, + hookKind: 'useActionState', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.State, + }), + ], + [ + 'useReducer', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseReducerId }, + calleeEffect: Effect.Read, + hookKind: 'useReducer', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.ReducerState, + }), + ], + [ + 'useRef', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Capture, + returnType: { kind: 'Object', shapeId: BuiltInUseRefId }, + calleeEffect: Effect.Read, + hookKind: 'useRef', + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'useImperativeHandle', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + hookKind: 'useImperativeHandle', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useMemo', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useMemo', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useCallback', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useCallback', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + hookKind: 'useEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseEffectHookId), + ], + [ + 'useLayoutEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useLayoutEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseLayoutEffectHookId), + ], + [ + 'useInsertionEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useInsertionEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseInsertionEffectHookId), + ], + [ + 'useTransition', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInUseTransitionId }, + calleeEffect: Effect.Read, + hookKind: 'useTransition', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'use', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }, BuiltInUseOperatorId), + ], + [ + 'fire', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: null, + returnType: { + kind: 'Function', + return: { kind: 'Poly' }, + shapeId: BuiltInFireFunctionId, + isConstructor: false, + }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }, BuiltInFireId), + ], +]; +TYPED_GLOBALS.push([ + 'React', + addObject(DEFAULT_SHAPES, null, [ + ...REACT_APIS, + [ + 'createElement', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'cloneElement', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'createRef', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Capture, + returnType: { kind: 'Object', shapeId: BuiltInUseRefId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), +], [ + '_jsx', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), +]); +const DEFAULT_GLOBALS = new Map(REACT_APIS); +for (const name of UNTYPED_GLOBALS) { + DEFAULT_GLOBALS.set(name, { + kind: 'Poly', + }); +} +for (const [name, type_] of TYPED_GLOBALS) { + DEFAULT_GLOBALS.set(name, type_); +} +DEFAULT_GLOBALS.set('globalThis', addObject(DEFAULT_SHAPES, 'globalThis', TYPED_GLOBALS)); +DEFAULT_GLOBALS.set('global', addObject(DEFAULT_SHAPES, 'global', TYPED_GLOBALS)); +function installTypeConfig(globals, shapes, typeConfig, moduleName, loc) { + var _a, _b, _c, _d; + switch (typeConfig.kind) { + case 'type': { + switch (typeConfig.name) { + case 'Array': { + return { kind: 'Object', shapeId: BuiltInArrayId }; + } + case 'MixedReadonly': { + return { kind: 'Object', shapeId: BuiltInMixedReadonlyId }; + } + case 'Primitive': { + return { kind: 'Primitive' }; + } + case 'Ref': { + return { kind: 'Object', shapeId: BuiltInUseRefId }; + } + case 'Any': { + return { kind: 'Poly' }; + } + default: { + assertExhaustive$1(typeConfig.name, `Unexpected type '${typeConfig.name}'`); + } + } + } + case 'function': { + return addFunction(shapes, [], { + positionalParams: typeConfig.positionalParams, + restParam: typeConfig.restParam, + calleeEffect: typeConfig.calleeEffect, + returnType: installTypeConfig(globals, shapes, typeConfig.returnType, moduleName, loc), + returnValueKind: typeConfig.returnValueKind, + noAlias: typeConfig.noAlias === true, + mutableOnlyIfOperandsAreMutable: typeConfig.mutableOnlyIfOperandsAreMutable === true, + }); + } + case 'hook': { + return addHook(shapes, { + hookKind: 'Custom', + positionalParams: (_a = typeConfig.positionalParams) !== null && _a !== void 0 ? _a : [], + restParam: (_b = typeConfig.restParam) !== null && _b !== void 0 ? _b : Effect.Freeze, + calleeEffect: Effect.Read, + returnType: installTypeConfig(globals, shapes, typeConfig.returnType, moduleName, loc), + returnValueKind: (_c = typeConfig.returnValueKind) !== null && _c !== void 0 ? _c : ValueKind.Frozen, + noAlias: typeConfig.noAlias === true, + }); + } + case 'object': { + return addObject(shapes, null, Object.entries((_d = typeConfig.properties) !== null && _d !== void 0 ? _d : {}).map(([key, value]) => { + var _a; + const type = installTypeConfig(globals, shapes, value, moduleName, loc); + const expectHook = isHookName$2(key); + let isHook = false; + if (type.kind === 'Function' && type.shapeId !== null) { + const functionType = shapes.get(type.shapeId); + if (((_a = functionType === null || functionType === void 0 ? void 0 : functionType.functionType) === null || _a === void 0 ? void 0 : _a.hookKind) !== null) { + isHook = true; + } + } + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for object property '${key}' from module '${moduleName}' ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the property name`, + loc, + }); + } + return [key, type]; + })); + } + default: { + assertExhaustive$1(typeConfig, `Unexpected type kind '${typeConfig.kind}'`); + } + } +} +function getReanimatedModuleType(registry) { + const frozenHooks = [ + 'useFrameCallback', + 'useAnimatedStyle', + 'useAnimatedProps', + 'useAnimatedScrollHandler', + 'useAnimatedReaction', + 'useWorkletCallback', + ]; + const reanimatedType = []; + for (const hook of frozenHooks) { + reanimatedType.push([ + hook, + addHook(registry, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + returnValueKind: ValueKind.Frozen, + noAlias: true, + calleeEffect: Effect.Read, + hookKind: 'Custom', + }), + ]); + } + const mutableHooks = ['useSharedValue', 'useDerivedValue']; + for (const hook of mutableHooks) { + reanimatedType.push([ + hook, + addHook(registry, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + returnValueKind: ValueKind.Mutable, + noAlias: true, + calleeEffect: Effect.Read, + hookKind: 'Custom', + }), + ]); + } + const funcs = [ + 'withTiming', + 'withSpring', + 'createAnimatedPropAdapter', + 'withDecay', + 'withRepeat', + 'runOnUI', + 'executeOnUIRuntimeSync', + ]; + for (const fn of funcs) { + reanimatedType.push([ + fn, + addFunction(registry, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + noAlias: true, + }), + ]); + } + return addObject(registry, null, reanimatedType); +} + +const ObjectPropertiesSchema = zod.z + .record(zod.z.string(), zod.z.lazy(() => TypeSchema)) + .refine(record => { + return Object.keys(record).every(key => key === '*' || key === 'default' || libExports$1.isValidIdentifier(key)); +}, 'Expected all "object" property names to be valid identifier, `*` to match any property, of `default` to define a module default export'); +const ObjectTypeSchema = zod.z.object({ + kind: zod.z.literal('object'), + properties: ObjectPropertiesSchema.nullable(), +}); +const FunctionTypeSchema = zod.z.object({ + kind: zod.z.literal('function'), + positionalParams: zod.z.array(EffectSchema), + restParam: EffectSchema.nullable(), + calleeEffect: EffectSchema, + returnType: zod.z.lazy(() => TypeSchema), + returnValueKind: ValueKindSchema, + noAlias: zod.z.boolean().nullable().optional(), + mutableOnlyIfOperandsAreMutable: zod.z.boolean().nullable().optional(), + impure: zod.z.boolean().nullable().optional(), + canonicalName: zod.z.string().nullable().optional(), +}); +const HookTypeSchema = zod.z.object({ + kind: zod.z.literal('hook'), + positionalParams: zod.z.array(EffectSchema).nullable().optional(), + restParam: EffectSchema.nullable().optional(), + returnType: zod.z.lazy(() => TypeSchema), + returnValueKind: ValueKindSchema.nullable().optional(), + noAlias: zod.z.boolean().nullable().optional(), +}); +const BuiltInTypeSchema = zod.z.union([ + zod.z.literal('Any'), + zod.z.literal('Ref'), + zod.z.literal('Array'), + zod.z.literal('Primitive'), + zod.z.literal('MixedReadonly'), +]); +const TypeReferenceSchema = zod.z.object({ + kind: zod.z.literal('type'), + name: BuiltInTypeSchema, +}); +const TypeSchema = zod.z.union([ + ObjectTypeSchema, + FunctionTypeSchema, + HookTypeSchema, + TypeReferenceSchema, +]); + +var _Environment_instances, _Environment_globals, _Environment_shapes, _Environment_moduleTypes, _Environment_nextIdentifer, _Environment_nextBlock, _Environment_nextScope, _Environment_scope, _Environment_outlinedFunctions, _Environment_contextIdentifiers, _Environment_hoistedIdentifiers, _Environment_resolveModuleType, _Environment_isKnownReactModule, _Environment_getCustomHookType; +const ReactElementSymbolSchema = zod.z.object({ + elementSymbol: zod.z.union([ + zod.z.literal('react.element'), + zod.z.literal('react.transitional.element'), + ]), + globalDevVar: zod.z.string(), +}); +const ExternalFunctionSchema = zod.z.object({ + source: zod.z.string(), + importSpecifierName: zod.z.string(), +}); +const InstrumentationSchema = zod.z + .object({ + fn: ExternalFunctionSchema, + gating: ExternalFunctionSchema.nullable(), + globalGating: zod.z.string().nullable(), +}) + .refine(opts => opts.gating != null || opts.globalGating != null, 'Expected at least one of gating or globalGating'); +const USE_FIRE_FUNCTION_NAME = 'useFire'; +const EMIT_FREEZE_GLOBAL_GATING = 'true'; +const MacroMethodSchema = zod.z.union([ + zod.z.object({ type: zod.z.literal('wildcard') }), + zod.z.object({ type: zod.z.literal('name'), name: zod.z.string() }), +]); +const MacroSchema = zod.z.union([ + zod.z.string(), + zod.z.tuple([zod.z.string(), zod.z.array(MacroMethodSchema)]), +]); +const HookSchema = zod.z.object({ + effectKind: zod.z.nativeEnum(Effect), + valueKind: zod.z.nativeEnum(ValueKind), + noAlias: zod.z.boolean().default(false), + transitiveMixedData: zod.z.boolean().default(false), +}); +const EnvironmentConfigSchema = zod.z.object({ + customHooks: zod.z.map(zod.z.string(), HookSchema).default(new Map()), + moduleTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null), + customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null), + enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null), + enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(false), + validatePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true), + enablePreserveExistingManualUseMemo: zod.z.boolean().default(false), + enableForest: zod.z.boolean().default(false), + enableUseTypeAnnotations: zod.z.boolean().default(false), + enableOptionalDependencies: zod.z.boolean().default(true), + enableFire: zod.z.boolean().default(false), + inferEffectDependencies: zod.z + .nullable(zod.z.array(zod.z.object({ + function: ExternalFunctionSchema, + numRequiredArgs: zod.z.number().min(1, 'numRequiredArgs must be > 0'), + }))) + .default(null), + inlineJsxTransform: ReactElementSymbolSchema.nullable().default(null), + validateHooksUsage: zod.z.boolean().default(true), + validateRefAccessDuringRender: zod.z.boolean().default(true), + validateNoSetStateInRender: zod.z.boolean().default(true), + validateNoSetStateInPassiveEffects: zod.z.boolean().default(false), + validateNoJSXInTryStatements: zod.z.boolean().default(false), + validateStaticComponents: zod.z.boolean().default(false), + validateMemoizedEffectDependencies: zod.z.boolean().default(false), + validateNoCapitalizedCalls: zod.z.nullable(zod.z.array(zod.z.string())).default(null), + validateBlocklistedImports: zod.z.nullable(zod.z.array(zod.z.string())).default(null), + validateNoImpureFunctionsInRender: zod.z.boolean().default(false), + enableAssumeHooksFollowRulesOfReact: zod.z.boolean().default(true), + enableTransitivelyFreezeFunctionExpressions: zod.z.boolean().default(true), + enableEmitFreeze: ExternalFunctionSchema.nullable().default(null), + enableEmitHookGuards: ExternalFunctionSchema.nullable().default(null), + enableInstructionReordering: zod.z.boolean().default(false), + enableFunctionOutlining: zod.z.boolean().default(true), + enableJsxOutlining: zod.z.boolean().default(false), + enableEmitInstrumentForget: InstrumentationSchema.nullable().default(null), + assertValidMutableRanges: zod.z.boolean().default(false), + enableChangeVariableCodegen: zod.z.boolean().default(false), + enableMemoizationComments: zod.z.boolean().default(false), + throwUnknownException__testonly: zod.z.boolean().default(false), + enableTreatFunctionDepsAsConditional: zod.z.boolean().default(false), + disableMemoizationForDebugging: zod.z.boolean().default(false), + enableChangeDetectionForDebugging: ExternalFunctionSchema.nullable().default(null), + enableCustomTypeDefinitionForReanimated: zod.z.boolean().default(false), + hookPattern: zod.z.string().nullable().default(null), + enableTreatRefLikeIdentifiersAsRefs: zod.z.boolean().default(false), + lowerContextAccess: ExternalFunctionSchema.nullable().default(null), +}); +class Environment { + constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, programContext) { + _Environment_instances.add(this); + _Environment_globals.set(this, void 0); + _Environment_shapes.set(this, void 0); + _Environment_moduleTypes.set(this, new Map()); + _Environment_nextIdentifer.set(this, 0); + _Environment_nextBlock.set(this, 0); + _Environment_nextScope.set(this, 0); + _Environment_scope.set(this, void 0); + _Environment_outlinedFunctions.set(this, []); + this.inferredEffectLocations = new Set(); + _Environment_contextIdentifiers.set(this, void 0); + _Environment_hoistedIdentifiers.set(this, void 0); + __classPrivateFieldSet(this, _Environment_scope, scope, "f"); + this.fnType = fnType; + this.compilerMode = compilerMode; + this.config = config; + this.filename = filename; + this.code = code; + this.logger = logger; + this.programContext = programContext; + __classPrivateFieldSet(this, _Environment_shapes, new Map(DEFAULT_SHAPES), "f"); + __classPrivateFieldSet(this, _Environment_globals, new Map(DEFAULT_GLOBALS), "f"); + this.hasFireRewrite = false; + this.hasInferredEffect = false; + if (config.disableMemoizationForDebugging && + config.enableChangeDetectionForDebugging != null) { + CompilerError.throwInvalidConfig({ + reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`, + description: null, + loc: null, + suggestions: null, + }); + } + for (const [hookName, hook] of this.config.customHooks) { + CompilerError.invariant(!__classPrivateFieldGet(this, _Environment_globals, "f").has(hookName), { + reason: `[Globals] Found existing definition in global registry for custom hook ${hookName}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Environment_globals, "f").set(hookName, addHook(__classPrivateFieldGet(this, _Environment_shapes, "f"), { + positionalParams: [], + restParam: hook.effectKind, + returnType: hook.transitiveMixedData + ? { kind: 'Object', shapeId: BuiltInMixedReadonlyId } + : { kind: 'Poly' }, + returnValueKind: hook.valueKind, + calleeEffect: Effect.Read, + hookKind: 'Custom', + noAlias: hook.noAlias, + })); + } + if (config.enableCustomTypeDefinitionForReanimated) { + const reanimatedModuleType = getReanimatedModuleType(__classPrivateFieldGet(this, _Environment_shapes, "f")); + __classPrivateFieldGet(this, _Environment_moduleTypes, "f").set(REANIMATED_MODULE_NAME, reanimatedModuleType); + } + __classPrivateFieldSet(this, _Environment_contextIdentifiers, contextIdentifiers, "f"); + __classPrivateFieldSet(this, _Environment_hoistedIdentifiers, new Set(), "f"); + } + get isInferredMemoEnabled() { + return this.compilerMode !== 'no_inferred_memo'; + } + get nextIdentifierId() { + var _a, _b; + return makeIdentifierId((__classPrivateFieldSet(this, _Environment_nextIdentifer, (_b = __classPrivateFieldGet(this, _Environment_nextIdentifer, "f"), _a = _b++, _b), "f"), _a)); + } + get nextBlockId() { + var _a, _b; + return makeBlockId((__classPrivateFieldSet(this, _Environment_nextBlock, (_b = __classPrivateFieldGet(this, _Environment_nextBlock, "f"), _a = _b++, _b), "f"), _a)); + } + get nextScopeId() { + var _a, _b; + return makeScopeId((__classPrivateFieldSet(this, _Environment_nextScope, (_b = __classPrivateFieldGet(this, _Environment_nextScope, "f"), _a = _b++, _b), "f"), _a)); + } + get scope() { + return __classPrivateFieldGet(this, _Environment_scope, "f"); + } + logErrors(errors) { + if (errors.isOk() || this.logger == null) { + return; + } + for (const error of errors.unwrapErr().details) { + this.logger.logEvent(this.filename, { + kind: 'CompileError', + detail: error, + fnLoc: null, + }); + } + } + isContextIdentifier(node) { + return __classPrivateFieldGet(this, _Environment_contextIdentifiers, "f").has(node); + } + isHoistedIdentifier(node) { + return __classPrivateFieldGet(this, _Environment_hoistedIdentifiers, "f").has(node); + } + generateGloballyUniqueIdentifierName(name) { + const identifierNode = __classPrivateFieldGet(this, _Environment_scope, "f").generateUidIdentifier(name !== null && name !== void 0 ? name : undefined); + return makeIdentifierName(identifierNode.name); + } + outlineFunction(fn, type) { + __classPrivateFieldGet(this, _Environment_outlinedFunctions, "f").push({ fn, type }); + } + getOutlinedFunctions() { + return __classPrivateFieldGet(this, _Environment_outlinedFunctions, "f"); + } + getGlobalDeclaration(binding, loc) { + var _a, _b, _c, _d; + if (this.config.hookPattern != null) { + const match = new RegExp(this.config.hookPattern).exec(binding.name); + if (match != null && + typeof match[1] === 'string' && + isHookName$2(match[1])) { + const resolvedName = match[1]; + return (_a = __classPrivateFieldGet(this, _Environment_globals, "f").get(resolvedName)) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this); + } + } + switch (binding.kind) { + case 'ModuleLocal': { + return isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null; + } + case 'Global': { + return ((_b = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.name)) !== null && _b !== void 0 ? _b : (isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + case 'ImportSpecifier': { + if (__classPrivateFieldGet(this, _Environment_instances, "m", _Environment_isKnownReactModule).call(this, binding.module)) { + return ((_c = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.imported)) !== null && _c !== void 0 ? _c : (isHookName$2(binding.imported) || isHookName$2(binding.name) + ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) + : null)); + } + else { + const moduleType = __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_resolveModuleType).call(this, binding.module, loc); + if (moduleType !== null) { + const importedType = this.getPropertyType(moduleType, binding.imported); + if (importedType != null) { + const expectHook = isHookName$2(binding.imported); + const isHook = getHookKindForType(this, importedType) != null; + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for \`import {${binding.imported}} from '${binding.module}'\` ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the exported name`, + loc, + }); + } + return importedType; + } + } + return isHookName$2(binding.imported) || isHookName$2(binding.name) + ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) + : null; + } + } + case 'ImportDefault': + case 'ImportNamespace': { + if (__classPrivateFieldGet(this, _Environment_instances, "m", _Environment_isKnownReactModule).call(this, binding.module)) { + return ((_d = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.name)) !== null && _d !== void 0 ? _d : (isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + else { + const moduleType = __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_resolveModuleType).call(this, binding.module, loc); + if (moduleType !== null) { + let importedType = null; + if (binding.kind === 'ImportDefault') { + const defaultType = this.getPropertyType(moduleType, 'default'); + if (defaultType !== null) { + importedType = defaultType; + } + } + else { + importedType = moduleType; + } + if (importedType !== null) { + const expectHook = isHookName$2(binding.module); + const isHook = getHookKindForType(this, importedType) != null; + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for \`import ... from '${binding.module}'\` ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the module name`, + loc, + }); + } + return importedType; + } + } + return isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null; + } + } + } + } + getFallthroughPropertyType(receiver, _property) { + var _a; + let shapeId = null; + if (receiver.kind === 'Object' || receiver.kind === 'Function') { + shapeId = receiver.shapeId; + } + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + return (_a = shape.properties.get('*')) !== null && _a !== void 0 ? _a : null; + } + return null; + } + getPropertyType(receiver, property) { + var _a, _b, _c; + let shapeId = null; + if (receiver.kind === 'Object' || receiver.kind === 'Function') { + shapeId = receiver.shapeId; + } + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + if (typeof property === 'string') { + return ((_b = (_a = shape.properties.get(property)) !== null && _a !== void 0 ? _a : shape.properties.get('*')) !== null && _b !== void 0 ? _b : (isHookName$2(property) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + else { + return (_c = shape.properties.get('*')) !== null && _c !== void 0 ? _c : null; + } + } + else if (typeof property === 'string' && isHookName$2(property)) { + return __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this); + } + return null; + } + getFunctionSignature(type) { + const { shapeId } = type; + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + return shape.functionType; + } + return null; + } + addHoistedIdentifier(node) { + __classPrivateFieldGet(this, _Environment_contextIdentifiers, "f").add(node); + __classPrivateFieldGet(this, _Environment_hoistedIdentifiers, "f").add(node); + } +} +_Environment_globals = new WeakMap(), _Environment_shapes = new WeakMap(), _Environment_moduleTypes = new WeakMap(), _Environment_nextIdentifer = new WeakMap(), _Environment_nextBlock = new WeakMap(), _Environment_nextScope = new WeakMap(), _Environment_scope = new WeakMap(), _Environment_outlinedFunctions = new WeakMap(), _Environment_contextIdentifiers = new WeakMap(), _Environment_hoistedIdentifiers = new WeakMap(), _Environment_instances = new WeakSet(), _Environment_resolveModuleType = function _Environment_resolveModuleType(moduleName, loc) { + let moduleType = __classPrivateFieldGet(this, _Environment_moduleTypes, "f").get(moduleName); + if (moduleType === undefined) { + if (this.config.moduleTypeProvider == null) { + return null; + } + const unparsedModuleConfig = this.config.moduleTypeProvider(moduleName); + if (unparsedModuleConfig != null) { + const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig); + if (!parsedModuleConfig.success) { + CompilerError.throwInvalidConfig({ + reason: `Could not parse module type, the configured \`moduleTypeProvider\` function returned an invalid module description`, + description: parsedModuleConfig.error.toString(), + loc, + }); + } + const moduleConfig = parsedModuleConfig.data; + moduleType = installTypeConfig(__classPrivateFieldGet(this, _Environment_globals, "f"), __classPrivateFieldGet(this, _Environment_shapes, "f"), moduleConfig, moduleName, loc); + } + else { + moduleType = null; + } + __classPrivateFieldGet(this, _Environment_moduleTypes, "f").set(moduleName, moduleType); + } + return moduleType; +}, _Environment_isKnownReactModule = function _Environment_isKnownReactModule(moduleName) { + return (moduleName.toLowerCase() === 'react' || + moduleName.toLowerCase() === 'react-dom'); +}, _Environment_getCustomHookType = function _Environment_getCustomHookType() { + if (this.config.enableAssumeHooksFollowRulesOfReact) { + return DefaultNonmutatingHook; + } + else { + return DefaultMutatingHook; + } +}; +Environment.knownReactModules = ['react', 'react-dom']; +const REANIMATED_MODULE_NAME = 'react-native-reanimated'; +function isHookName$2(name) { + return /^use[A-Z0-9]/.test(name); +} +function parseEnvironmentConfig(partialConfig) { + const config = EnvironmentConfigSchema.safeParse(partialConfig); + if (config.success) { + return Ok(config.data); + } + else { + return Err(config.error); + } +} +function validateEnvironmentConfig(partialConfig) { + const config = EnvironmentConfigSchema.safeParse(partialConfig); + if (config.success) { + return config.data; + } + CompilerError.throwInvalidConfig({ + reason: 'Could not validate environment config. Update React Compiler config to fix the error', + description: `${zodValidationError.fromZodError(config.error)}`, + loc: null, + suggestions: null, + }); +} +function tryParseExternalFunction(maybeExternalFunction) { + const externalFunction = ExternalFunctionSchema.safeParse(maybeExternalFunction); + if (externalFunction.success) { + return externalFunction.data; + } + CompilerError.throwInvalidConfig({ + reason: 'Could not parse external function. Update React Compiler config to fix the error', + description: `${zodValidationError.fromZodError(externalFunction.error)}`, + loc: null, + suggestions: null, + }); +} +const DEFAULT_EXPORT = 'default'; + +var _MergedBlocks_map; +function mergeConsecutiveBlocks(fn) { + const merged = new MergedBlocks(); + const fallthroughBlocks = new Set(); + for (const [, block] of fn.body.blocks) { + const fallthrough = terminalFallthrough(block.terminal); + if (fallthrough !== null) { + fallthroughBlocks.add(fallthrough); + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + mergeConsecutiveBlocks(instr.value.loweredFunc.func); + } + } + if (block.preds.size !== 1 || + block.kind !== 'block' || + fallthroughBlocks.has(block.id)) { + continue; + } + const originalPredecessorId = Array.from(block.preds)[0]; + const predecessorId = merged.get(originalPredecessorId); + const predecessor = fn.body.blocks.get(predecessorId); + CompilerError.invariant(predecessor !== undefined, { + reason: `Expected predecessor ${predecessorId} to exist`, + description: null, + loc: null, + suggestions: null, + }); + if (predecessor.terminal.kind !== 'goto' || predecessor.kind !== 'block') { + continue; + } + for (const phi of block.phis) { + CompilerError.invariant(phi.operands.size === 1, { + reason: `Found a block with a single predecessor but where a phi has multiple (${phi.operands.size}) operands`, + description: null, + loc: null, + suggestions: null, + }); + const operand = Array.from(phi.operands.values())[0]; + const instr = { + id: predecessor.terminal.id, + lvalue: { + kind: 'Identifier', + identifier: phi.place.identifier, + effect: Effect.ConditionallyMutate, + reactive: false, + loc: GeneratedSource, + }, + value: { + kind: 'LoadLocal', + place: Object.assign({}, operand), + loc: GeneratedSource, + }, + loc: GeneratedSource, + }; + predecessor.instructions.push(instr); + } + predecessor.instructions.push(...block.instructions); + predecessor.terminal = block.terminal; + merged.merge(block.id, predecessorId); + fn.body.blocks.delete(block.id); + } + markPredecessors(fn.body); + for (const [, { terminal }] of fn.body.blocks) { + if (terminalHasFallthrough(terminal)) { + terminal.fallthrough = merged.get(terminal.fallthrough); + } + } +} +class MergedBlocks { + constructor() { + _MergedBlocks_map.set(this, new Map()); + } + merge(block, into) { + const target = this.get(into); + __classPrivateFieldGet(this, _MergedBlocks_map, "f").set(block, target); + } + get(block) { + var _a; + let current = block; + while (__classPrivateFieldGet(this, _MergedBlocks_map, "f").has(current)) { + current = (_a = __classPrivateFieldGet(this, _MergedBlocks_map, "f").get(current)) !== null && _a !== void 0 ? _a : current; + } + return current; + } +} +_MergedBlocks_map = new WeakMap(); + +var _DisjointSet_entries; +class DisjointSet { + constructor() { + _DisjointSet_entries.set(this, new Map()); + } + union(items) { + const first = items.shift(); + CompilerError.invariant(first != null, { + reason: 'Expected set to be non-empty', + description: null, + loc: null, + suggestions: null, + }); + let root = this.find(first); + if (root == null) { + root = first; + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(first, first); + } + for (const item of items) { + let itemParent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(item); + if (itemParent == null) { + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(item, root); + continue; + } + else if (itemParent === root) { + continue; + } + else { + let current = item; + while (itemParent !== root) { + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(current, root); + current = itemParent; + itemParent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(current); + } + } + } + } + find(item) { + if (!__classPrivateFieldGet(this, _DisjointSet_entries, "f").has(item)) { + return null; + } + const parent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(item); + if (parent === item) { + return item; + } + const root = this.find(parent); + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(item, root); + return root; + } + canonicalize() { + const entries = new Map(); + for (const item of __classPrivateFieldGet(this, _DisjointSet_entries, "f").keys()) { + const root = this.find(item); + entries.set(item, root); + } + return entries; + } + forEach(fn) { + for (const item of __classPrivateFieldGet(this, _DisjointSet_entries, "f").keys()) { + const group = this.find(item); + fn(item, group); + } + } + buildSets() { + const ids = new Map(); + const sets = new Map(); + this.forEach((identifier, groupIdentifier) => { + let id = ids.get(groupIdentifier); + if (id == null) { + id = ids.size; + ids.set(groupIdentifier, id); + } + let set = sets.get(id); + if (set === undefined) { + set = new Set(); + sets.set(id, set); + } + set.add(identifier); + }); + return [...sets.values()]; + } + get size() { + return __classPrivateFieldGet(this, _DisjointSet_entries, "f").size; + } +} +_DisjointSet_entries = new WeakMap(); + +function inferReactiveScopeVariables(fn) { + var _a, _b; + const scopeIdentifiers = findDisjointMutableValues(fn); + const scopes = new Map(); + scopeIdentifiers.forEach((identifier, groupIdentifier) => { + let scope = scopes.get(groupIdentifier); + if (scope === undefined) { + scope = { + id: fn.env.nextScopeId, + range: identifier.mutableRange, + dependencies: new Set(), + declarations: new Map(), + reassignments: new Set(), + earlyReturnValue: null, + merged: new Set(), + loc: identifier.loc, + }; + scopes.set(groupIdentifier, scope); + } + else { + if (scope.range.start === 0) { + scope.range.start = identifier.mutableRange.start; + } + else if (identifier.mutableRange.start !== 0) { + scope.range.start = makeInstructionId(Math.min(scope.range.start, identifier.mutableRange.start)); + } + scope.range.end = makeInstructionId(Math.max(scope.range.end, identifier.mutableRange.end)); + scope.loc = mergeLocation(scope.loc, identifier.loc); + } + identifier.scope = scope; + identifier.mutableRange = scope.range; + }); + let maxInstruction = 0; + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + maxInstruction = makeInstructionId(Math.max(maxInstruction, instr.id)); + } + maxInstruction = makeInstructionId(Math.max(maxInstruction, block.terminal.id)); + } + for (const [, scope] of scopes) { + if (scope.range.start === 0 || + scope.range.end === 0 || + maxInstruction === 0 || + scope.range.end > maxInstruction + 1) { + (_b = (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'hir', + name: 'InferReactiveScopeVariables (invalid scope)', + value: fn, + }); + CompilerError.invariant(false, { + reason: `Invalid mutable range for scope`, + loc: GeneratedSource, + description: `Scope @${scope.id} has range [${scope.range.start}:${scope.range.end}] but the valid range is [1:${maxInstruction + 1}]`, + }); + } + } +} +function mergeLocation(l, r) { + if (l === GeneratedSource) { + return r; + } + else if (r === GeneratedSource) { + return l; + } + else { + return { + filename: l.filename, + identifierName: l.identifierName, + start: { + index: Math.min(l.start.index, r.start.index), + line: Math.min(l.start.line, r.start.line), + column: Math.min(l.start.column, r.start.column), + }, + end: { + index: Math.max(l.end.index, r.end.index), + line: Math.max(l.end.line, r.end.line), + column: Math.max(l.end.column, r.end.column), + }, + }; + } +} +function isMutable(instr, place) { + return inRange(instr, place.identifier.mutableRange); +} +function inRange({ id }, range) { + return id >= range.start && id < range.end; +} +function mayAllocate(_env, instruction) { + const { value } = instruction; + switch (value.kind) { + case 'Destructure': { + return doesPatternContainSpreadElement(value.lvalue.pattern); + } + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'Await': + case 'DeclareLocal': + case 'DeclareContext': + case 'StoreLocal': + case 'LoadGlobal': + case 'MetaProperty': + case 'TypeCastExpression': + case 'LoadLocal': + case 'LoadContext': + case 'StoreContext': + case 'PropertyDelete': + case 'ComputedLoad': + case 'ComputedDelete': + case 'JSXText': + case 'TemplateLiteral': + case 'Primitive': + case 'GetIterator': + case 'IteratorNext': + case 'NextPropertyOf': + case 'Debugger': + case 'StartMemoize': + case 'FinishMemoize': + case 'UnaryExpression': + case 'BinaryExpression': + case 'PropertyLoad': + case 'StoreGlobal': { + return false; + } + case 'TaggedTemplateExpression': + case 'CallExpression': + case 'MethodCall': { + return instruction.lvalue.identifier.type.kind !== 'Primitive'; + } + case 'RegExpLiteral': + case 'PropertyStore': + case 'ComputedStore': + case 'ArrayExpression': + case 'JsxExpression': + case 'JsxFragment': + case 'NewExpression': + case 'ObjectExpression': + case 'UnsupportedNode': + case 'ObjectMethod': + case 'FunctionExpression': { + return true; + } + default: { + assertExhaustive$1(value, `Unexpected value kind \`${value.kind}\``); + } + } +} +function findDisjointMutableValues(fn) { + var _a, _b; + const scopeIdentifiers = new DisjointSet(); + const declarations = new Map(); + function declareIdentifier(lvalue) { + if (!declarations.has(lvalue.identifier.declarationId)) { + declarations.set(lvalue.identifier.declarationId, lvalue.identifier); + } + } + for (const [_, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (phi.place.identifier.mutableRange.start + 1 !== + phi.place.identifier.mutableRange.end && + phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id)) { + const operands = [phi.place.identifier]; + const declaration = declarations.get(phi.place.identifier.declarationId); + if (declaration !== undefined) { + operands.push(declaration); + } + for (const [_, phiId] of phi.operands) { + operands.push(phiId.identifier); + } + scopeIdentifiers.union(operands); + } + else if (fn.env.config.enableForest) { + for (const [, phiId] of phi.operands) { + scopeIdentifiers.union([phi.place.identifier, phiId.identifier]); + } + } + } + for (const instr of block.instructions) { + const operands = []; + const range = instr.lvalue.identifier.mutableRange; + if (range.end > range.start + 1 || mayAllocate(fn.env, instr)) { + operands.push(instr.lvalue.identifier); + } + if (instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + declareIdentifier(instr.value.lvalue.place); + } + else if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext') { + declareIdentifier(instr.value.lvalue.place); + if (instr.value.lvalue.place.identifier.mutableRange.end > + instr.value.lvalue.place.identifier.mutableRange.start + 1) { + operands.push(instr.value.lvalue.place.identifier); + } + if (isMutable(instr, instr.value.value) && + instr.value.value.identifier.mutableRange.start > 0) { + operands.push(instr.value.value.identifier); + } + } + else if (instr.value.kind === 'Destructure') { + for (const place of eachPatternOperand(instr.value.lvalue.pattern)) { + declareIdentifier(place); + if (place.identifier.mutableRange.end > + place.identifier.mutableRange.start + 1) { + operands.push(place.identifier); + } + } + if (isMutable(instr, instr.value.value) && + instr.value.value.identifier.mutableRange.start > 0) { + operands.push(instr.value.value.identifier); + } + } + else if (instr.value.kind === 'MethodCall') { + for (const operand of eachInstructionOperand(instr)) { + if (isMutable(instr, operand) && + operand.identifier.mutableRange.start > 0) { + operands.push(operand.identifier); + } + } + operands.push(instr.value.property.identifier); + } + else { + for (const operand of eachInstructionOperand(instr)) { + if (isMutable(instr, operand) && + operand.identifier.mutableRange.start > 0) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + if (operand.identifier.type.kind === 'Primitive') { + continue; + } + } + operands.push(operand.identifier); + } + } + } + if (operands.length !== 0) { + scopeIdentifiers.union(operands); + } + } + } + return scopeIdentifiers; +} + +function mergeOverlappingReactiveScopesHIR(fn) { + const scopesInfo = collectScopeInfo(fn); + const joinedScopes = getOverlappingReactiveScopes(fn, scopesInfo); + joinedScopes.forEach((scope, groupScope) => { + if (scope !== groupScope) { + groupScope.range.start = makeInstructionId(Math.min(groupScope.range.start, scope.range.start)); + groupScope.range.end = makeInstructionId(Math.max(groupScope.range.end, scope.range.end)); + } + }); + for (const [place, originalScope] of scopesInfo.placeScopes) { + const nextScope = joinedScopes.find(originalScope); + if (nextScope !== null && nextScope !== originalScope) { + place.identifier.scope = nextScope; + } + } +} +function collectScopeInfo(fn) { + const scopeStarts = new Map(); + const scopeEnds = new Map(); + const placeScopes = new Map(); + function collectPlaceScope(place) { + const scope = place.identifier.scope; + if (scope != null) { + placeScopes.set(place, scope); + if (scope.range.start !== scope.range.end) { + getOrInsertDefault(scopeStarts, scope.range.start, new Set()).add(scope); + getOrInsertDefault(scopeEnds, scope.range.end, new Set()).add(scope); + } + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + collectPlaceScope(operand); + } + for (const operand of eachInstructionOperand(instr)) { + collectPlaceScope(operand); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + collectPlaceScope(operand); + } + } + return { + scopeStarts: [...scopeStarts.entries()] + .map(([id, scopes]) => ({ id, scopes })) + .sort((a, b) => b.id - a.id), + scopeEnds: [...scopeEnds.entries()] + .map(([id, scopes]) => ({ id, scopes })) + .sort((a, b) => b.id - a.id), + placeScopes, + }; +} +function visitInstructionId(id, { scopeEnds, scopeStarts }, { activeScopes, joined }) { + const scopeEndTop = scopeEnds.at(-1); + if (scopeEndTop != null && scopeEndTop.id <= id) { + scopeEnds.pop(); + const scopesSortedStartDescending = [...scopeEndTop.scopes].sort((a, b) => b.range.start - a.range.start); + for (const scope of scopesSortedStartDescending) { + const idx = activeScopes.indexOf(scope); + if (idx !== -1) { + if (idx !== activeScopes.length - 1) { + joined.union([scope, ...activeScopes.slice(idx + 1)]); + } + activeScopes.splice(idx, 1); + } + } + } + const scopeStartTop = scopeStarts.at(-1); + if (scopeStartTop != null && scopeStartTop.id <= id) { + scopeStarts.pop(); + const scopesSortedEndDescending = [...scopeStartTop.scopes].sort((a, b) => b.range.end - a.range.end); + activeScopes.push(...scopesSortedEndDescending); + for (let i = 1; i < scopesSortedEndDescending.length; i++) { + const prev = scopesSortedEndDescending[i - 1]; + const curr = scopesSortedEndDescending[i]; + if (prev.range.end === curr.range.end) { + joined.union([prev, curr]); + } + } + } +} +function visitPlace(id, place, { activeScopes, joined }) { + const placeScope = getPlaceScope(id, place); + if (placeScope != null && isMutable({ id }, place)) { + const placeScopeIdx = activeScopes.indexOf(placeScope); + if (placeScopeIdx !== -1 && placeScopeIdx !== activeScopes.length - 1) { + joined.union([placeScope, ...activeScopes.slice(placeScopeIdx + 1)]); + } + } +} +function getOverlappingReactiveScopes(fn, context) { + const state = { + joined: new DisjointSet(), + activeScopes: [], + }; + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + visitInstructionId(instr.id, context, state); + for (const place of eachInstructionOperand(instr)) { + if ((instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') && + place.identifier.type.kind === 'Primitive') { + continue; + } + visitPlace(instr.id, place, state); + } + for (const place of eachInstructionLValue(instr)) { + visitPlace(instr.id, place, state); + } + } + visitInstructionId(block.terminal.id, context, state); + for (const place of eachTerminalOperand(block.terminal)) { + visitPlace(block.terminal.id, place, state); + } + } + return state.joined; +} + +function pruneUnusedLabelsHIR(fn) { + var _a; + const merged = []; + const rewrites = new Map(); + for (const [blockId, block] of fn.body.blocks) { + const terminal = block.terminal; + if (terminal.kind === 'label') { + const { block: nextId, fallthrough: fallthroughId } = terminal; + const next = fn.body.blocks.get(nextId); + const fallthrough = fn.body.blocks.get(fallthroughId); + if (next.terminal.kind === 'goto' && + next.terminal.variant === GotoVariant.Break && + next.terminal.block === fallthroughId) { + if (next.kind === 'block' && fallthrough.kind === 'block') { + merged.push({ + label: blockId, + next: nextId, + fallthrough: fallthroughId, + }); + } + } + } + } + for (const { label: originalLabelId, next: nextId, fallthrough: fallthroughId, } of merged) { + const labelId = (_a = rewrites.get(originalLabelId)) !== null && _a !== void 0 ? _a : originalLabelId; + const label = fn.body.blocks.get(labelId); + const next = fn.body.blocks.get(nextId); + const fallthrough = fn.body.blocks.get(fallthroughId); + CompilerError.invariant(next.phis.size === 0 && fallthrough.phis.size === 0, { + reason: 'Unexpected phis when merging label blocks', + loc: label.terminal.loc, + }); + CompilerError.invariant(next.preds.size === 1 && + fallthrough.preds.size === 1 && + next.preds.has(originalLabelId) && + fallthrough.preds.has(nextId), { + reason: 'Unexpected block predecessors when merging label blocks', + loc: label.terminal.loc, + }); + label.instructions.push(...next.instructions, ...fallthrough.instructions); + label.terminal = fallthrough.terminal; + fn.body.blocks.delete(nextId); + fn.body.blocks.delete(fallthroughId); + rewrites.set(fallthroughId, labelId); + } + for (const [_, block] of fn.body.blocks) { + for (const pred of block.preds) { + const rewritten = rewrites.get(pred); + if (rewritten != null) { + block.preds.delete(pred); + block.preds.add(rewritten); + } + } + } +} + +function isComponentDeclaration(node) { + return Object.prototype.hasOwnProperty.call(node, '__componentDeclaration'); +} + +function isHookDeclaration(node) { + return Object.prototype.hasOwnProperty.call(node, '__hookDeclaration'); +} + +const DEFAULT_IDENTIFIER_INFO = { + reassigned: false, + reassignedByInnerFn: false, + referencedByInnerFn: false, +}; +const withFunctionScope = { + enter: function (path, state) { + state.currentFn.push(path); + }, + exit: function (_, state) { + state.currentFn.pop(); + }, +}; +function findContextIdentifiers(func) { + const state = { + currentFn: [], + identifiers: new Map(), + }; + func.traverse({ + FunctionDeclaration: withFunctionScope, + FunctionExpression: withFunctionScope, + ArrowFunctionExpression: withFunctionScope, + ObjectMethod: withFunctionScope, + AssignmentExpression(path, state) { + var _a, _b; + const left = path.get('left'); + if (left.isLVal()) { + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + handleAssignment(currentFn, state.identifiers, left); + } + else { + CompilerError.throwTodo({ + reason: `Unsupported syntax on the left side of an AssignmentExpression`, + description: `Expected an LVal, got: ${left.type}`, + loc: (_b = left.node.loc) !== null && _b !== void 0 ? _b : null, + }); + } + }, + UpdateExpression(path, state) { + var _a; + const argument = path.get('argument'); + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + if (argument.isLVal()) { + handleAssignment(currentFn, state.identifiers, argument); + } + }, + Identifier(path, state) { + var _a; + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + if (path.isReferencedIdentifier()) { + handleIdentifier$1(currentFn, state.identifiers, path); + } + }, + }, state); + const result = new Set(); + for (const [id, info] of state.identifiers.entries()) { + if (info.reassignedByInnerFn) { + result.add(id); + } + else if (info.reassigned && info.referencedByInnerFn) { + result.add(id); + } + } + return result; +} +function handleIdentifier$1(currentFn, identifiers, path) { + const name = path.node.name; + const binding = path.scope.getBinding(name); + if (binding == null) { + return; + } + const identifier = getOrInsertDefault(identifiers, binding.identifier, Object.assign({}, DEFAULT_IDENTIFIER_INFO)); + if (currentFn != null) { + const bindingAboveLambdaScope = currentFn.scope.parent.getBinding(name); + if (binding === bindingAboveLambdaScope) { + identifier.referencedByInnerFn = true; + } + } +} +function handleAssignment(currentFn, identifiers, lvalPath) { + var _a, _b, _c; + const lvalNode = lvalPath.node; + switch (lvalNode.type) { + case 'Identifier': { + const path = lvalPath; + const name = path.node.name; + const binding = path.scope.getBinding(name); + if (binding == null) { + break; + } + const state = getOrInsertDefault(identifiers, binding.identifier, Object.assign({}, DEFAULT_IDENTIFIER_INFO)); + state.reassigned = true; + if (currentFn != null) { + const bindingAboveLambdaScope = currentFn.scope.parent.getBinding(name); + if (binding === bindingAboveLambdaScope) { + state.reassignedByInnerFn = true; + } + } + break; + } + case 'ArrayPattern': { + const path = lvalPath; + for (const element of path.get('elements')) { + if (nonNull(element)) { + handleAssignment(currentFn, identifiers, element); + } + } + break; + } + case 'ObjectPattern': { + const path = lvalPath; + for (const property of path.get('properties')) { + if (property.isObjectProperty()) { + const valuePath = property.get('value'); + CompilerError.invariant(valuePath.isLVal(), { + reason: `[FindContextIdentifiers] Expected object property value to be an LVal, got: ${valuePath.type}`, + description: null, + loc: (_a = valuePath.node.loc) !== null && _a !== void 0 ? _a : GeneratedSource, + suggestions: null, + }); + handleAssignment(currentFn, identifiers, valuePath); + } + else { + CompilerError.invariant(property.isRestElement(), { + reason: `[FindContextIdentifiers] Invalid assumptions for babel types.`, + description: null, + loc: (_b = property.node.loc) !== null && _b !== void 0 ? _b : GeneratedSource, + suggestions: null, + }); + handleAssignment(currentFn, identifiers, property); + } + } + break; + } + case 'AssignmentPattern': { + const path = lvalPath; + const left = path.get('left'); + handleAssignment(currentFn, identifiers, left); + break; + } + case 'RestElement': { + const path = lvalPath; + handleAssignment(currentFn, identifiers, path.get('argument')); + break; + } + case 'MemberExpression': { + break; + } + default: { + CompilerError.throwTodo({ + reason: `[FindContextIdentifiers] Cannot handle Object destructuring assignment target ${lvalNode.type}`, + description: null, + loc: (_c = lvalNode.loc) !== null && _c !== void 0 ? _c : GeneratedSource, + suggestions: null, + }); + } + } +} +function nonNull(t) { + return t.node != null; +} + +function eliminateRedundantPhi(fn, sharedRewrites) { + const ir = fn.body; + const rewrites = sharedRewrites != null ? sharedRewrites : new Map(); + let hasBackEdge = false; + const visited = new Set(); + let size = rewrites.size; + do { + size = rewrites.size; + for (const [blockId, block] of ir.blocks) { + if (!hasBackEdge) { + for (const predId of block.preds) { + if (!visited.has(predId)) { + hasBackEdge = true; + } + } + } + visited.add(blockId); + phis: for (const phi of block.phis) { + phi.operands.forEach((place, _) => rewritePlace(place, rewrites)); + let same = null; + for (const [_, operand] of phi.operands) { + if ((same !== null && operand.identifier.id === same.id) || + operand.identifier.id === phi.place.identifier.id) { + continue; + } + else if (same !== null) { + continue phis; + } + else { + same = operand.identifier; + } + } + CompilerError.invariant(same !== null, { + reason: 'Expected phis to be non-empty', + description: null, + loc: null, + suggestions: null, + }); + rewrites.set(phi.place.identifier, same); + block.phis.delete(phi); + } + for (const instr of block.instructions) { + for (const place of eachInstructionLValue(instr)) { + rewritePlace(place, rewrites); + } + for (const place of eachInstructionOperand(instr)) { + rewritePlace(place, rewrites); + } + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + const { context } = instr.value.loweredFunc.func; + for (const place of context) { + rewritePlace(place, rewrites); + } + eliminateRedundantPhi(instr.value.loweredFunc.func, rewrites); + } + } + const { terminal } = block; + for (const place of eachTerminalOperand(terminal)) { + rewritePlace(place, rewrites); + } + } + } while (rewrites.size > size && hasBackEdge); +} +function rewritePlace(place, rewrites) { + const rewrite = rewrites.get(place.identifier); + if (rewrite != null) { + place.identifier = rewrite; + } +} + +var _SSABuilder_states, _SSABuilder_current, _SSABuilder_blocks, _SSABuilder_env, _SSABuilder_unknown, _SSABuilder_context; +class SSABuilder { + constructor(env, blocks) { + _SSABuilder_states.set(this, new Map()); + _SSABuilder_current.set(this, null); + this.unsealedPreds = new Map(); + _SSABuilder_blocks.set(this, void 0); + _SSABuilder_env.set(this, void 0); + _SSABuilder_unknown.set(this, new Set()); + _SSABuilder_context.set(this, new Set()); + __classPrivateFieldSet(this, _SSABuilder_blocks, new Map(blocks), "f"); + __classPrivateFieldSet(this, _SSABuilder_env, env, "f"); + } + get nextSsaId() { + return __classPrivateFieldGet(this, _SSABuilder_env, "f").nextIdentifierId; + } + defineFunction(func) { + for (const [id, block] of func.body.blocks) { + __classPrivateFieldGet(this, _SSABuilder_blocks, "f").set(id, block); + } + } + enter(fn) { + const current = __classPrivateFieldGet(this, _SSABuilder_current, "f"); + fn(); + __classPrivateFieldSet(this, _SSABuilder_current, current, "f"); + } + state() { + CompilerError.invariant(__classPrivateFieldGet(this, _SSABuilder_current, "f") !== null, { + reason: 'we need to be in a block to access state!', + description: null, + loc: null, + suggestions: null, + }); + return __classPrivateFieldGet(this, _SSABuilder_states, "f").get(__classPrivateFieldGet(this, _SSABuilder_current, "f")); + } + makeId(oldId) { + return { + id: this.nextSsaId, + declarationId: oldId.declarationId, + name: oldId.name, + mutableRange: { + start: makeInstructionId(0), + end: makeInstructionId(0), + }, + scope: null, + type: makeType(), + loc: oldId.loc, + }; + } + defineContext(oldPlace) { + const newPlace = this.definePlace(oldPlace); + __classPrivateFieldGet(this, _SSABuilder_context, "f").add(oldPlace.identifier); + return newPlace; + } + definePlace(oldPlace) { + const oldId = oldPlace.identifier; + if (__classPrivateFieldGet(this, _SSABuilder_unknown, "f").has(oldId)) { + CompilerError.throwTodo({ + reason: `[hoisting] EnterSSA: Expected identifier to be defined before being used`, + description: `Identifier ${printIdentifier(oldId)} is undefined`, + loc: oldPlace.loc, + suggestions: null, + }); + } + if (__classPrivateFieldGet(this, _SSABuilder_context, "f").has(oldId)) { + return this.getPlace(oldPlace); + } + const newId = this.makeId(oldId); + this.state().defs.set(oldId, newId); + return Object.assign(Object.assign({}, oldPlace), { identifier: newId }); + } + getPlace(oldPlace) { + const newId = this.getIdAt(oldPlace, __classPrivateFieldGet(this, _SSABuilder_current, "f").id); + return Object.assign(Object.assign({}, oldPlace), { identifier: newId }); + } + getIdAt(oldPlace, blockId) { + const block = __classPrivateFieldGet(this, _SSABuilder_blocks, "f").get(blockId); + const state = __classPrivateFieldGet(this, _SSABuilder_states, "f").get(block); + if (state.defs.has(oldPlace.identifier)) { + return state.defs.get(oldPlace.identifier); + } + if (block.preds.size == 0) { + __classPrivateFieldGet(this, _SSABuilder_unknown, "f").add(oldPlace.identifier); + return oldPlace.identifier; + } + if (this.unsealedPreds.get(block) > 0) { + const newId = this.makeId(oldPlace.identifier); + state.incompletePhis.push({ + oldPlace, + newPlace: Object.assign(Object.assign({}, oldPlace), { identifier: newId }), + }); + state.defs.set(oldPlace.identifier, newId); + return newId; + } + if (block.preds.size == 1) { + const [pred] = block.preds; + const newId = this.getIdAt(oldPlace, pred); + state.defs.set(oldPlace.identifier, newId); + return newId; + } + const newId = this.makeId(oldPlace.identifier); + state.defs.set(oldPlace.identifier, newId); + return this.addPhi(block, oldPlace, Object.assign(Object.assign({}, oldPlace), { identifier: newId })); + } + addPhi(block, oldPlace, newPlace) { + const predDefs = new Map(); + for (const predBlockId of block.preds) { + const predId = this.getIdAt(oldPlace, predBlockId); + predDefs.set(predBlockId, Object.assign(Object.assign({}, oldPlace), { identifier: predId })); + } + const phi = { + kind: 'Phi', + place: newPlace, + operands: predDefs, + }; + block.phis.add(phi); + return newPlace.identifier; + } + fixIncompletePhis(block) { + const state = __classPrivateFieldGet(this, _SSABuilder_states, "f").get(block); + for (const phi of state.incompletePhis) { + this.addPhi(block, phi.oldPlace, phi.newPlace); + } + } + startBlock(block) { + __classPrivateFieldSet(this, _SSABuilder_current, block, "f"); + __classPrivateFieldGet(this, _SSABuilder_states, "f").set(block, { + defs: new Map(), + incompletePhis: [], + }); + } + print() { + var _a; + const text = []; + for (const [block, state] of __classPrivateFieldGet(this, _SSABuilder_states, "f")) { + text.push(`bb${block.id}:`); + for (const [oldId, newId] of state.defs) { + text.push(` \$${printIdentifier(oldId)}: \$${printIdentifier(newId)}`); + } + for (const incompletePhi of state.incompletePhis) { + text.push(` iphi \$${printPlace(incompletePhi.newPlace)} = \$${printPlace(incompletePhi.oldPlace)}`); + } + } + text.push(`current block: bb${(_a = __classPrivateFieldGet(this, _SSABuilder_current, "f")) === null || _a === void 0 ? void 0 : _a.id}`); + console.log(text.join('\n')); + } +} +_SSABuilder_states = new WeakMap(), _SSABuilder_current = new WeakMap(), _SSABuilder_blocks = new WeakMap(), _SSABuilder_env = new WeakMap(), _SSABuilder_unknown = new WeakMap(), _SSABuilder_context = new WeakMap(); +function enterSSA(func) { + const builder = new SSABuilder(func.env, func.body.blocks); + enterSSAImpl(func, builder, func.body.entry); +} +function enterSSAImpl(func, builder, rootEntry) { + const visitedBlocks = new Set(); + for (const [blockId, block] of func.body.blocks) { + CompilerError.invariant(!visitedBlocks.has(block), { + reason: `found a cycle! visiting bb${block.id} again`, + description: null, + loc: null, + suggestions: null, + }); + visitedBlocks.add(block); + builder.startBlock(block); + if (blockId === rootEntry) { + CompilerError.invariant(func.context.length === 0, { + reason: `Expected function context to be empty for outer function declarations`, + description: null, + loc: func.loc, + suggestions: null, + }); + func.params = func.params.map(param => { + if (param.kind === 'Identifier') { + return builder.definePlace(param); + } + else { + return { + kind: 'Spread', + place: builder.definePlace(param.place), + }; + } + }); + } + for (const instr of block.instructions) { + mapInstructionOperands(instr, place => builder.getPlace(place)); + mapInstructionLValues(instr, lvalue => builder.definePlace(lvalue)); + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + const loweredFunc = instr.value.loweredFunc.func; + const entry = loweredFunc.body.blocks.get(loweredFunc.body.entry); + CompilerError.invariant(entry.preds.size === 0, { + reason: 'Expected function expression entry block to have zero predecessors', + description: null, + loc: null, + suggestions: null, + }); + entry.preds.add(blockId); + builder.defineFunction(loweredFunc); + builder.enter(() => { + loweredFunc.params = loweredFunc.params.map(param => { + if (param.kind === 'Identifier') { + return builder.definePlace(param); + } + else { + return { + kind: 'Spread', + place: builder.definePlace(param.place), + }; + } + }); + enterSSAImpl(loweredFunc, builder, rootEntry); + }); + entry.preds.clear(); + } + } + mapTerminalOperands(block.terminal, place => builder.getPlace(place)); + for (const outputId of eachTerminalSuccessor(block.terminal)) { + const output = func.body.blocks.get(outputId); + let count; + if (builder.unsealedPreds.has(output)) { + count = builder.unsealedPreds.get(output) - 1; + } + else { + count = output.preds.size - 1; + } + builder.unsealedPreds.set(output, count); + if (count === 0 && visitedBlocks.has(output)) { + builder.fixIncompletePhis(output); + } + } + } +} + +function rewriteInstructionKindsBasedOnReassignment(fn) { + const declarations = new Map(); + for (const param of fn.params) { + let place = param.kind === 'Identifier' ? param : param.place; + if (place.identifier.name !== null) { + declarations.set(place.identifier.declarationId, { + kind: InstructionKind.Let, + place, + }); + } + } + for (const place of fn.context) { + if (place.identifier.name !== null) { + declarations.set(place.identifier.declarationId, { + kind: InstructionKind.Let, + place, + }); + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'DeclareLocal': { + const lvalue = value.lvalue; + CompilerError.invariant(!declarations.has(lvalue.place.identifier.declarationId), { + reason: `Expected variable not to be defined prior to declaration`, + description: `${printPlace(lvalue.place)} was already defined`, + loc: lvalue.place.loc, + }); + declarations.set(lvalue.place.identifier.declarationId, lvalue); + break; + } + case 'StoreLocal': { + const lvalue = value.lvalue; + if (lvalue.place.identifier.name !== null) { + const declaration = declarations.get(lvalue.place.identifier.declarationId); + if (declaration === undefined) { + CompilerError.invariant(!declarations.has(lvalue.place.identifier.declarationId), { + reason: `Expected variable not to be defined prior to declaration`, + description: `${printPlace(lvalue.place)} was already defined`, + loc: lvalue.place.loc, + }); + declarations.set(lvalue.place.identifier.declarationId, lvalue); + lvalue.kind = InstructionKind.Const; + } + else { + declaration.kind = InstructionKind.Let; + lvalue.kind = InstructionKind.Reassign; + } + } + break; + } + case 'Destructure': { + const lvalue = value.lvalue; + let kind = null; + for (const place of eachPatternOperand(lvalue.pattern)) { + if (place.identifier.name === null) { + CompilerError.invariant(kind === null || kind === InstructionKind.Const, { + reason: `Expected consistent kind for destructuring`, + description: `other places were \`${kind}\` but '${printPlace(place)}' is const`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Const; + } + else { + const declaration = declarations.get(place.identifier.declarationId); + if (declaration === undefined) { + CompilerError.invariant(block.kind !== 'value', { + reason: `TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE)`, + description: null, + loc: place.loc, + suggestions: null, + }); + declarations.set(place.identifier.declarationId, lvalue); + CompilerError.invariant(kind === null || kind === InstructionKind.Const, { + reason: `Expected consistent kind for destructuring`, + description: `Other places were \`${kind}\` but '${printPlace(place)}' is const`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Const; + } + else { + CompilerError.invariant(kind === null || kind === InstructionKind.Reassign, { + reason: `Expected consistent kind for destructuring`, + description: `Other places were \`${kind}\` but '${printPlace(place)}' is reassigned`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Reassign; + declaration.kind = InstructionKind.Let; + } + } + } + CompilerError.invariant(kind !== null, { + reason: 'Expected at least one operand', + description: null, + loc: null, + suggestions: null, + }); + lvalue.kind = kind; + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + const lvalue = value.lvalue; + const declaration = declarations.get(lvalue.identifier.declarationId); + CompilerError.invariant(declaration !== undefined, { + reason: `Expected variable to have been defined`, + description: `No declaration for ${printPlace(lvalue)}`, + loc: lvalue.loc, + }); + declaration.kind = InstructionKind.Let; + break; + } + } + } + } +} + +function constantPropagation(fn) { + const constants = new Map(); + constantPropagationImpl(fn, constants); +} +function constantPropagationImpl(fn, constants) { + while (true) { + const haveTerminalsChanged = applyConstantPropagation(fn, constants); + if (!haveTerminalsChanged) { + break; + } + reversePostorderBlocks(fn.body); + removeUnreachableForUpdates(fn.body); + removeDeadDoWhileStatements(fn.body); + removeUnnecessaryTryCatch(fn.body); + markInstructionIds(fn.body); + markPredecessors(fn.body); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const [predecessor] of phi.operands) { + if (!block.preds.has(predecessor)) { + phi.operands.delete(predecessor); + } + } + } + } + eliminateRedundantPhi(fn); + mergeConsecutiveBlocks(fn); + assertConsistentIdentifiers(fn); + assertTerminalSuccessorsExist(fn); + } +} +function applyConstantPropagation(fn, constants) { + let hasChanges = false; + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + let value = evaluatePhi(phi, constants); + if (value !== null) { + constants.set(phi.place.identifier.id, value); + } + } + for (let i = 0; i < block.instructions.length; i++) { + if (block.kind === 'sequence' && i === block.instructions.length - 1) { + continue; + } + const instr = block.instructions[i]; + const value = evaluateInstruction(constants, instr); + if (value !== null) { + constants.set(instr.lvalue.identifier.id, value); + } + } + const terminal = block.terminal; + switch (terminal.kind) { + case 'if': { + const testValue = read(constants, terminal.test); + if (testValue !== null && testValue.kind === 'Primitive') { + hasChanges = true; + const targetBlockId = testValue.value + ? terminal.consequent + : terminal.alternate; + block.terminal = { + kind: 'goto', + variant: GotoVariant.Break, + block: targetBlockId, + id: terminal.id, + loc: terminal.loc, + }; + } + break; + } + } + } + return hasChanges; +} +function evaluatePhi(phi, constants) { + var _a; + let value = null; + for (const [, operand] of phi.operands) { + const operandValue = (_a = constants.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : null; + if (operandValue === null) { + return null; + } + if (value === null) { + value = operandValue; + continue; + } + if (operandValue.kind !== value.kind) { + return null; + } + switch (operandValue.kind) { + case 'Primitive': { + CompilerError.invariant(value.kind === 'Primitive', { + reason: 'value kind expected to be Primitive', + loc: null, + suggestions: null, + }); + if (operandValue.value !== value.value) { + return null; + } + break; + } + case 'LoadGlobal': { + CompilerError.invariant(value.kind === 'LoadGlobal', { + reason: 'value kind expected to be LoadGlobal', + loc: null, + suggestions: null, + }); + if (operandValue.binding.name !== value.binding.name) { + return null; + } + break; + } + default: + return null; + } + } + return value; +} +function evaluateInstruction(constants, instr) { + const value = instr.value; + switch (value.kind) { + case 'Primitive': { + return value; + } + case 'LoadGlobal': { + return value; + } + case 'ComputedLoad': { + const property = read(constants, value.property); + if (property !== null && + property.kind === 'Primitive' && + ((typeof property.value === 'string' && + libExports$1.isValidIdentifier(property.value)) || + typeof property.value === 'number')) { + const nextValue = { + kind: 'PropertyLoad', + loc: value.loc, + property: makePropertyLiteral(property.value), + object: value.object, + }; + instr.value = nextValue; + } + return null; + } + case 'ComputedStore': { + const property = read(constants, value.property); + if (property !== null && + property.kind === 'Primitive' && + ((typeof property.value === 'string' && + libExports$1.isValidIdentifier(property.value)) || + typeof property.value === 'number')) { + const nextValue = { + kind: 'PropertyStore', + loc: value.loc, + property: makePropertyLiteral(property.value), + object: value.object, + value: value.value, + }; + instr.value = nextValue; + } + return null; + } + case 'PostfixUpdate': { + const previous = read(constants, value.value); + if (previous !== null && + previous.kind === 'Primitive' && + typeof previous.value === 'number') { + const next = value.operation === '++' ? previous.value + 1 : previous.value - 1; + constants.set(value.lvalue.identifier.id, { + kind: 'Primitive', + value: next, + loc: value.loc, + }); + return previous; + } + return null; + } + case 'PrefixUpdate': { + const previous = read(constants, value.value); + if (previous !== null && + previous.kind === 'Primitive' && + typeof previous.value === 'number') { + const next = { + kind: 'Primitive', + value: value.operation === '++' ? previous.value + 1 : previous.value - 1, + loc: value.loc, + }; + constants.set(value.lvalue.identifier.id, next); + return next; + } + return null; + } + case 'UnaryExpression': { + switch (value.operator) { + case '!': { + const operand = read(constants, value.value); + if (operand !== null && operand.kind === 'Primitive') { + const result = { + kind: 'Primitive', + value: !operand.value, + loc: value.loc, + }; + instr.value = result; + return result; + } + return null; + } + default: + return null; + } + } + case 'BinaryExpression': { + const lhsValue = read(constants, value.left); + const rhsValue = read(constants, value.right); + if (lhsValue !== null && + rhsValue !== null && + lhsValue.kind === 'Primitive' && + rhsValue.kind === 'Primitive') { + const lhs = lhsValue.value; + const rhs = rhsValue.value; + let result = null; + switch (value.operator) { + case '+': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs + rhs, loc: value.loc }; + } + else if (typeof lhs === 'string' && typeof rhs === 'string') { + result = { kind: 'Primitive', value: lhs + rhs, loc: value.loc }; + } + break; + } + case '-': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs - rhs, loc: value.loc }; + } + break; + } + case '*': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs * rhs, loc: value.loc }; + } + break; + } + case '/': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs / rhs, loc: value.loc }; + } + break; + } + case '|': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs | rhs, loc: value.loc }; + } + break; + } + case '&': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs & rhs, loc: value.loc }; + } + break; + } + case '^': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs ^ rhs, loc: value.loc }; + } + break; + } + case '<<': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs << rhs, loc: value.loc }; + } + break; + } + case '>>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs >> rhs, loc: value.loc }; + } + break; + } + case '>>>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { + kind: 'Primitive', + value: lhs >>> rhs, + loc: value.loc, + }; + } + break; + } + case '%': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs % rhs, loc: value.loc }; + } + break; + } + case '**': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: Math.pow(lhs, rhs), loc: value.loc }; + } + break; + } + case '<': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs < rhs, loc: value.loc }; + } + break; + } + case '<=': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs <= rhs, loc: value.loc }; + } + break; + } + case '>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs > rhs, loc: value.loc }; + } + break; + } + case '>=': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs >= rhs, loc: value.loc }; + } + break; + } + case '==': { + result = { kind: 'Primitive', value: lhs == rhs, loc: value.loc }; + break; + } + case '===': { + result = { kind: 'Primitive', value: lhs === rhs, loc: value.loc }; + break; + } + case '!=': { + result = { kind: 'Primitive', value: lhs != rhs, loc: value.loc }; + break; + } + case '!==': { + result = { kind: 'Primitive', value: lhs !== rhs, loc: value.loc }; + break; + } + } + if (result !== null) { + instr.value = result; + return result; + } + } + return null; + } + case 'PropertyLoad': { + const objectValue = read(constants, value.object); + if (objectValue !== null) { + if (objectValue.kind === 'Primitive' && + typeof objectValue.value === 'string' && + value.property === 'length') { + const result = { + kind: 'Primitive', + value: objectValue.value.length, + loc: value.loc, + }; + instr.value = result; + return result; + } + } + return null; + } + case 'LoadLocal': { + const placeValue = read(constants, value.place); + if (placeValue !== null) { + instr.value = placeValue; + } + return placeValue; + } + case 'StoreLocal': { + const placeValue = read(constants, value.value); + if (placeValue !== null) { + constants.set(value.lvalue.place.identifier.id, placeValue); + } + return placeValue; + } + case 'ObjectMethod': + case 'FunctionExpression': { + constantPropagationImpl(value.loweredFunc.func, constants); + return null; + } + default: { + return null; + } + } +} +function read(constants, place) { + var _a; + return (_a = constants.get(place.identifier.id)) !== null && _a !== void 0 ? _a : null; +} + +function deadCodeElimination(fn) { + const state = findReferencedIdentifiers(fn); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (!state.isIdOrNameUsed(phi.place.identifier)) { + block.phis.delete(phi); + } + } + retainWhere(block.instructions, instr => state.isIdOrNameUsed(instr.lvalue.identifier)); + for (let i = 0; i < block.instructions.length; i++) { + const isBlockValue = block.kind !== 'block' && i === block.instructions.length - 1; + if (!isBlockValue) { + rewriteInstruction(block.instructions[i], state); + } + } + } + retainWhere(fn.context, contextVar => state.isIdOrNameUsed(contextVar.identifier)); +} +let State$2 = class State { + constructor() { + this.named = new Set(); + this.identifiers = new Set(); + } + reference(identifier) { + this.identifiers.add(identifier.id); + if (identifier.name !== null) { + this.named.add(identifier.name.value); + } + } + isIdOrNameUsed(identifier) { + return (this.identifiers.has(identifier.id) || + (identifier.name !== null && this.named.has(identifier.name.value))); + } + isIdUsed(identifier) { + return this.identifiers.has(identifier.id); + } + get count() { + return this.identifiers.size; + } +}; +function findReferencedIdentifiers(fn) { + const hasLoop = hasBackEdge(fn); + const reversedBlocks = [...fn.body.blocks.values()].reverse(); + const state = new State$2(); + let size = state.count; + do { + size = state.count; + for (const block of reversedBlocks) { + for (const operand of eachTerminalOperand(block.terminal)) { + state.reference(operand.identifier); + } + for (let i = block.instructions.length - 1; i >= 0; i--) { + const instr = block.instructions[i]; + const isBlockValue = block.kind !== 'block' && i === block.instructions.length - 1; + if (isBlockValue) { + state.reference(instr.lvalue.identifier); + for (const place of eachInstructionValueOperand(instr.value)) { + state.reference(place.identifier); + } + } + else if (state.isIdOrNameUsed(instr.lvalue.identifier) || + !pruneableValue(instr.value, state)) { + state.reference(instr.lvalue.identifier); + if (instr.value.kind === 'StoreLocal') { + if (instr.value.lvalue.kind === InstructionKind.Reassign || + state.isIdUsed(instr.value.lvalue.place.identifier)) { + state.reference(instr.value.value.identifier); + } + } + else { + for (const operand of eachInstructionValueOperand(instr.value)) { + state.reference(operand.identifier); + } + } + } + } + for (const phi of block.phis) { + if (state.isIdOrNameUsed(phi.place.identifier)) { + for (const [_pred, operand] of phi.operands) { + state.reference(operand.identifier); + } + } + } + } + } while (state.count > size && hasLoop); + return state; +} +function rewriteInstruction(instr, state) { + if (instr.value.kind === 'Destructure') { + switch (instr.value.lvalue.pattern.kind) { + case 'ArrayPattern': { + let lastEntryIndex = 0; + const items = instr.value.lvalue.pattern.items; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (item.kind === 'Identifier') { + if (!state.isIdOrNameUsed(item.identifier)) { + items[i] = { kind: 'Hole' }; + } + else { + lastEntryIndex = i; + } + } + else if (item.kind === 'Spread') { + if (!state.isIdOrNameUsed(item.place.identifier)) { + items[i] = { kind: 'Hole' }; + } + else { + lastEntryIndex = i; + } + } + } + items.length = lastEntryIndex + 1; + break; + } + case 'ObjectPattern': { + let nextProperties = null; + for (const property of instr.value.lvalue.pattern.properties) { + if (property.kind === 'ObjectProperty') { + if (state.isIdOrNameUsed(property.place.identifier)) { + nextProperties !== null && nextProperties !== void 0 ? nextProperties : (nextProperties = []); + nextProperties.push(property); + } + } + else { + if (state.isIdOrNameUsed(property.place.identifier)) { + nextProperties = null; + break; + } + } + } + if (nextProperties !== null) { + instr.value.lvalue.pattern.properties = nextProperties; + } + break; + } + default: { + assertExhaustive$1(instr.value.lvalue.pattern, `Unexpected pattern kind '${instr.value.lvalue.pattern.kind}'`); + } + } + } + else if (instr.value.kind === 'StoreLocal') { + if (instr.value.lvalue.kind !== InstructionKind.Reassign && + !state.isIdUsed(instr.value.lvalue.place.identifier)) { + instr.value = { + kind: 'DeclareLocal', + lvalue: instr.value.lvalue, + type: instr.value.type, + loc: instr.value.loc, + }; + } + } +} +function pruneableValue(value, state) { + switch (value.kind) { + case 'DeclareLocal': { + return !state.isIdOrNameUsed(value.lvalue.place.identifier); + } + case 'StoreLocal': { + if (value.lvalue.kind === InstructionKind.Reassign) { + return !state.isIdUsed(value.lvalue.place.identifier); + } + return !state.isIdOrNameUsed(value.lvalue.place.identifier); + } + case 'Destructure': { + let isIdOrNameUsed = false; + let isIdUsed = false; + for (const place of eachPatternOperand(value.lvalue.pattern)) { + if (state.isIdUsed(place.identifier)) { + isIdOrNameUsed = true; + isIdUsed = true; + } + else if (state.isIdOrNameUsed(place.identifier)) { + isIdOrNameUsed = true; + } + } + if (value.lvalue.kind === InstructionKind.Reassign) { + return !isIdUsed; + } + else { + return !isIdOrNameUsed; + } + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + return !state.isIdUsed(value.lvalue.identifier); + } + case 'Debugger': { + return false; + } + case 'Await': + case 'CallExpression': + case 'ComputedDelete': + case 'ComputedStore': + case 'PropertyDelete': + case 'MethodCall': + case 'PropertyStore': + case 'StoreGlobal': { + return false; + } + case 'NewExpression': + case 'UnsupportedNode': + case 'TaggedTemplateExpression': { + return false; + } + case 'GetIterator': + case 'NextPropertyOf': + case 'IteratorNext': { + return false; + } + case 'LoadContext': + case 'DeclareContext': + case 'StoreContext': { + return false; + } + case 'StartMemoize': + case 'FinishMemoize': { + return false; + } + case 'RegExpLiteral': + case 'MetaProperty': + case 'LoadGlobal': + case 'ArrayExpression': + case 'BinaryExpression': + case 'ComputedLoad': + case 'ObjectMethod': + case 'FunctionExpression': + case 'LoadLocal': + case 'JsxExpression': + case 'JsxFragment': + case 'JSXText': + case 'ObjectExpression': + case 'Primitive': + case 'PropertyLoad': + case 'TemplateLiteral': + case 'TypeCastExpression': + case 'UnaryExpression': { + return true; + } + default: { + assertExhaustive$1(value, `Unexepcted value kind \`${value.kind}\``); + } + } +} +function hasBackEdge(fn) { + return findBlocksWithBackEdges(fn).size > 0; +} +function findBlocksWithBackEdges(fn) { + const visited = new Set(); + const blocks = new Set(); + for (const [blockId, block] of fn.body.blocks) { + for (const predId of block.preds) { + if (!visited.has(predId)) { + blocks.add(blockId); + } + } + visited.add(blockId); + } + return blocks; +} + +function pruneMaybeThrows(fn) { + const terminalMapping = pruneMaybeThrowsImpl(fn); + if (terminalMapping) { + reversePostorderBlocks(fn.body); + removeUnreachableForUpdates(fn.body); + removeDeadDoWhileStatements(fn.body); + removeUnnecessaryTryCatch(fn.body); + markInstructionIds(fn.body); + mergeConsecutiveBlocks(fn); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const [predecessor, operand] of phi.operands) { + if (!block.preds.has(predecessor)) { + const mappedTerminal = terminalMapping.get(predecessor); + CompilerError.invariant(mappedTerminal != null, { + reason: `Expected non-existing phi operand's predecessor to have been mapped to a new terminal`, + loc: GeneratedSource, + description: `Could not find mapping for predecessor bb${predecessor} in block bb${block.id} for phi ${printPlace(phi.place)}`, + suggestions: null, + }); + phi.operands.delete(predecessor); + phi.operands.set(mappedTerminal, operand); + } + } + } + } + assertConsistentIdentifiers(fn); + assertTerminalSuccessorsExist(fn); + } +} +function pruneMaybeThrowsImpl(fn) { + var _a; + const terminalMapping = new Map(); + for (const [_, block] of fn.body.blocks) { + const terminal = block.terminal; + if (terminal.kind !== 'maybe-throw') { + continue; + } + const canThrow = block.instructions.some(instr => instructionMayThrow(instr)); + if (!canThrow) { + const source = (_a = terminalMapping.get(block.id)) !== null && _a !== void 0 ? _a : block.id; + terminalMapping.set(terminal.continuation, source); + block.terminal = { + kind: 'goto', + block: terminal.continuation, + variant: GotoVariant.Break, + id: terminal.id, + loc: terminal.loc, + }; + } + } + return terminalMapping.size > 0 ? terminalMapping : null; +} +function instructionMayThrow(instr) { + switch (instr.value.kind) { + case 'Primitive': + case 'ArrayExpression': + case 'ObjectExpression': { + return false; + } + default: { + return true; + } + } +} + +function inlineJsxTransform(fn, inlineJsxTransformConfig) { + var _a; + const inlinedJsxDeclarations = new Map(); + for (const [_, currentBlock] of [...fn.body.blocks]) { + let fallthroughBlockInstructions = null; + const instructionCount = currentBlock.instructions.length; + for (let i = 0; i < instructionCount; i++) { + const instr = currentBlock.instructions[i]; + if (currentBlock.kind === 'value') { + (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.logEvent(fn.env.filename, { + kind: 'CompileDiagnostic', + fnLoc: null, + detail: { + reason: 'JSX Inlining is not supported on value blocks', + loc: instr.loc, + }, + }); + continue; + } + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + const currentBlockInstructions = currentBlock.instructions.slice(0, i); + const thenBlockInstructions = currentBlock.instructions.slice(i, i + 1); + const elseBlockInstructions = []; + fallthroughBlockInstructions !== null && fallthroughBlockInstructions !== void 0 ? fallthroughBlockInstructions : (fallthroughBlockInstructions = currentBlock.instructions.slice(i + 1)); + const fallthroughBlockId = fn.env.nextBlockId; + const fallthroughBlock = { + kind: currentBlock.kind, + id: fallthroughBlockId, + instructions: fallthroughBlockInstructions, + terminal: currentBlock.terminal, + preds: new Set(), + phis: new Set(), + }; + const varPlace = createTemporaryPlace(fn.env, instr.value.loc); + promoteTemporary(varPlace.identifier); + const varLValuePlace = createTemporaryPlace(fn.env, instr.value.loc); + const thenVarPlace = Object.assign(Object.assign({}, varPlace), { identifier: forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier) }); + const elseVarPlace = Object.assign(Object.assign({}, varPlace), { identifier: forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier) }); + const varInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, varLValuePlace), + value: { + kind: 'DeclareLocal', + lvalue: { place: Object.assign({}, varPlace), kind: InstructionKind.Let }, + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + currentBlockInstructions.push(varInstruction); + const devGlobalPlace = createTemporaryPlace(fn.env, instr.value.loc); + const devGlobalInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, devGlobalPlace), { effect: Effect.Mutate }), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: inlineJsxTransformConfig.globalDevVar, + }, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + currentBlockInstructions.push(devGlobalInstruction); + const thenBlockId = fn.env.nextBlockId; + const elseBlockId = fn.env.nextBlockId; + const ifTerminal = { + kind: 'if', + test: Object.assign(Object.assign({}, devGlobalPlace), { effect: Effect.Read }), + consequent: thenBlockId, + alternate: elseBlockId, + fallthrough: fallthroughBlockId, + loc: instr.loc, + id: makeInstructionId(0), + }; + currentBlock.instructions = currentBlockInstructions; + currentBlock.terminal = ifTerminal; + const thenBlock = { + id: thenBlockId, + instructions: thenBlockInstructions, + kind: 'block', + phis: new Set(), + preds: new Set(), + terminal: { + kind: 'goto', + block: fallthroughBlockId, + variant: GotoVariant.Break, + id: makeInstructionId(0), + loc: instr.loc, + }, + }; + fn.body.blocks.set(thenBlockId, thenBlock); + const resassignElsePlace = createTemporaryPlace(fn.env, instr.value.loc); + const reassignElseInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, resassignElsePlace), + value: { + kind: 'StoreLocal', + lvalue: { + place: elseVarPlace, + kind: InstructionKind.Reassign, + }, + value: Object.assign({}, instr.lvalue), + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + thenBlockInstructions.push(reassignElseInstruction); + const elseBlockTerminal = { + kind: 'goto', + block: fallthroughBlockId, + variant: GotoVariant.Break, + id: makeInstructionId(0), + loc: instr.loc, + }; + const elseBlock = { + id: elseBlockId, + instructions: elseBlockInstructions, + kind: 'block', + phis: new Set(), + preds: new Set(), + terminal: elseBlockTerminal, + }; + fn.body.blocks.set(elseBlockId, elseBlock); + const { refProperty, keyProperty, propsProperty } = createPropsProperties(fn, instr, elseBlockInstructions, instr.value.kind === 'JsxExpression' ? instr.value.props : [], instr.value.children); + const reactElementInstructionPlace = createTemporaryPlace(fn.env, instr.value.loc); + const reactElementInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, reactElementInstructionPlace), { effect: Effect.Store }), + value: { + kind: 'ObjectExpression', + properties: [ + createSymbolProperty(fn, instr, elseBlockInstructions, '$$typeof', inlineJsxTransformConfig.elementSymbol), + instr.value.kind === 'JsxExpression' + ? createTagProperty(fn, instr, elseBlockInstructions, instr.value.tag) + : createSymbolProperty(fn, instr, elseBlockInstructions, 'type', 'react.fragment'), + refProperty, + keyProperty, + propsProperty, + ], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + elseBlockInstructions.push(reactElementInstruction); + const reassignConditionalInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, createTemporaryPlace(fn.env, instr.value.loc)), + value: { + kind: 'StoreLocal', + lvalue: { + place: Object.assign({}, elseVarPlace), + kind: InstructionKind.Reassign, + }, + value: Object.assign({}, reactElementInstruction.lvalue), + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + elseBlockInstructions.push(reassignConditionalInstruction); + const operands = new Map(); + operands.set(thenBlockId, Object.assign({}, elseVarPlace)); + operands.set(elseBlockId, Object.assign({}, thenVarPlace)); + const phiIdentifier = forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier); + const phiPlace = Object.assign(Object.assign({}, createTemporaryPlace(fn.env, instr.value.loc)), { identifier: phiIdentifier }); + const phis = new Set([ + { + kind: 'Phi', + operands, + place: phiPlace, + }, + ]); + fallthroughBlock.phis = phis; + fn.body.blocks.set(fallthroughBlockId, fallthroughBlock); + inlinedJsxDeclarations.set(instr.lvalue.identifier.declarationId, { + identifier: phiIdentifier, + blockIdsToIgnore: new Set([thenBlockId, elseBlockId]), + }); + break; + } + case 'FunctionExpression': + case 'ObjectMethod': { + inlineJsxTransform(instr.value.loweredFunc.func, inlineJsxTransformConfig); + break; + } + } + } + } + for (const [blockId, block] of fn.body.blocks) { + for (const instr of block.instructions) { + mapInstructionOperands(instr, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + mapInstructionLValues(instr, lvalue => handlelValue(lvalue, blockId, inlinedJsxDeclarations)); + mapInstructionValueOperands(instr.value, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + } + mapTerminalOperands(block.terminal, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + if (block.terminal.kind === 'scope') { + const scope = block.terminal.scope; + for (const dep of scope.dependencies) { + dep.identifier = handleIdentifier(dep.identifier, inlinedJsxDeclarations); + } + for (const [origId, decl] of [...scope.declarations]) { + const newDecl = handleIdentifier(decl.identifier, inlinedJsxDeclarations); + if (newDecl.id !== origId) { + scope.declarations.delete(origId); + scope.declarations.set(decl.identifier.id, { + identifier: newDecl, + scope: decl.scope, + }); + } + } + } + } + reversePostorderBlocks(fn.body); + markPredecessors(fn.body); + markInstructionIds(fn.body); + fixScopeAndIdentifierRanges(fn.body); +} +function createSymbolProperty(fn, instr, nextInstructions, propertyName, symbolName) { + const symbolPlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolPlace), { effect: Effect.Mutate }), + value: { + kind: 'LoadGlobal', + binding: { kind: 'Global', name: 'Symbol' }, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolInstruction); + const symbolForPlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolForInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolForPlace), { effect: Effect.Read }), + value: { + kind: 'PropertyLoad', + object: Object.assign({}, symbolInstruction.lvalue), + property: makePropertyLiteral('for'), + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolForInstruction); + const symbolValuePlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolValueInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolValuePlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: symbolName, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolValueInstruction); + const $$typeofPlace = createTemporaryPlace(fn.env, instr.value.loc); + const $$typeofInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, $$typeofPlace), { effect: Effect.Mutate }), + value: { + kind: 'MethodCall', + receiver: symbolInstruction.lvalue, + property: symbolForInstruction.lvalue, + args: [symbolValueInstruction.lvalue], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + const $$typeofProperty = { + kind: 'ObjectProperty', + key: { name: propertyName, kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, $$typeofPlace), { effect: Effect.Capture }), + }; + nextInstructions.push($$typeofInstruction); + return $$typeofProperty; +} +function createTagProperty(fn, instr, nextInstructions, componentTag) { + let tagProperty; + switch (componentTag.kind) { + case 'BuiltinTag': { + const tagPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const tagInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, tagPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: componentTag.name, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + tagProperty = { + kind: 'ObjectProperty', + key: { name: 'type', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, tagPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(tagInstruction); + break; + } + case 'Identifier': { + tagProperty = { + kind: 'ObjectProperty', + key: { name: 'type', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, componentTag), { effect: Effect.Capture }), + }; + break; + } + } + return tagProperty; +} +function createPropsProperties(fn, instr, nextInstructions, propAttributes, children) { + let refProperty; + let keyProperty; + const props = []; + const jsxAttributesWithoutKey = propAttributes.filter(p => p.kind === 'JsxAttribute' && p.name !== 'key'); + const jsxSpreadAttributes = propAttributes.filter(p => p.kind === 'JsxSpreadAttribute'); + const spreadPropsOnly = jsxAttributesWithoutKey.length === 0 && jsxSpreadAttributes.length === 1; + propAttributes.forEach(prop => { + switch (prop.kind) { + case 'JsxAttribute': { + switch (prop.name) { + case 'key': { + keyProperty = { + kind: 'ObjectProperty', + key: { name: 'key', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + break; + } + case 'ref': { + refProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + const refPropProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + props.push(refPropProperty); + break; + } + default: { + const attributeProperty = { + kind: 'ObjectProperty', + key: { name: prop.name, kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + props.push(attributeProperty); + } + } + break; + } + case 'JsxSpreadAttribute': { + props.push({ + kind: 'Spread', + place: Object.assign({}, prop.argument), + }); + break; + } + } + }); + const propsPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + if (children) { + let childrenPropProperty; + if (children.length === 1) { + childrenPropProperty = { + kind: 'ObjectProperty', + key: { name: 'children', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, children[0]), { effect: Effect.Capture }), + }; + } + else { + const childrenPropPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const childrenPropInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, childrenPropPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'ArrayExpression', + elements: [...children], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(childrenPropInstruction); + childrenPropProperty = { + kind: 'ObjectProperty', + key: { name: 'children', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, childrenPropPropertyPlace), { effect: Effect.Capture }), + }; + } + props.push(childrenPropProperty); + } + if (refProperty == null) { + const refPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const refInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, refPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + refProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, refPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(refInstruction); + } + if (keyProperty == null) { + const keyPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const keyInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, keyPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + keyProperty = { + kind: 'ObjectProperty', + key: { name: 'key', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, keyPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(keyInstruction); + } + let propsProperty; + if (spreadPropsOnly) { + const spreadProp = jsxSpreadAttributes[0]; + CompilerError.invariant(spreadProp.kind === 'JsxSpreadAttribute', { + reason: 'Spread prop attribute must be of kind JSXSpreadAttribute', + loc: instr.loc, + }); + propsProperty = { + kind: 'ObjectProperty', + key: { name: 'props', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, spreadProp.argument), { effect: Effect.Mutate }), + }; + } + else { + const propsInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, propsPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'ObjectExpression', + properties: props, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + propsProperty = { + kind: 'ObjectProperty', + key: { name: 'props', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, propsPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(propsInstruction); + } + return { refProperty, keyProperty, propsProperty }; +} +function handlePlace(place, blockId, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(place.identifier.declarationId); + if (inlinedJsxDeclaration == null || + inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)) { + return place; + } + return Object.assign(Object.assign({}, place), { identifier: inlinedJsxDeclaration.identifier }); +} +function handlelValue(lvalue, blockId, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(lvalue.identifier.declarationId); + if (inlinedJsxDeclaration == null || + inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)) { + return lvalue; + } + return Object.assign(Object.assign({}, lvalue), { identifier: inlinedJsxDeclaration.identifier }); +} +function handleIdentifier(identifier, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(identifier.declarationId); + return inlinedJsxDeclaration == null + ? identifier + : inlinedJsxDeclaration.identifier; +} + +function findScopesToMerge(fn) { + const objectMethodDecls = new Set(); + const mergeScopesBuilder = new DisjointSet(); + for (const [_, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'ObjectMethod') { + objectMethodDecls.add(lvalue.identifier); + } + else if (value.kind === 'ObjectExpression') { + for (const operand of eachInstructionValueOperand(value)) { + if (objectMethodDecls.has(operand.identifier)) { + const operandScope = operand.identifier.scope; + const lvalueScope = lvalue.identifier.scope; + CompilerError.invariant(operandScope != null && lvalueScope != null, { + reason: 'Internal error: Expected all ObjectExpressions and ObjectMethods to have non-null scope.', + suggestions: null, + loc: GeneratedSource, + }); + mergeScopesBuilder.union([operandScope, lvalueScope]); + } + } + } + } + } + return mergeScopesBuilder; +} +function alignObjectMethodScopes(fn) { + for (const [_, block] of fn.body.blocks) { + for (const { value } of block.instructions) { + if (value.kind === 'ObjectMethod' || + value.kind === 'FunctionExpression') { + alignObjectMethodScopes(value.loweredFunc.func); + } + } + } + const scopeGroupsMap = findScopesToMerge(fn).canonicalize(); + for (const [scope, root] of scopeGroupsMap) { + if (scope !== root) { + root.range.start = makeInstructionId(Math.min(scope.range.start, root.range.start)); + root.range.end = makeInstructionId(Math.max(scope.range.end, root.range.end)); + } + } + for (const [_, block] of fn.body.blocks) { + for (const { lvalue: { identifier }, } of block.instructions) { + if (identifier.scope != null) { + const root = scopeGroupsMap.get(identifier.scope); + if (root != null) { + identifier.scope = root; + } + } + } + } +} + +function visitReactiveFunction(fn, visitor, state) { + visitor.visitBlock(fn.body, state); +} +class ReactiveFunctionVisitor { + visitID(_id, _state) { } + visitParam(_place, _state) { } + visitLValue(_id, _lvalue, _state) { } + visitPlace(_id, _place, _state) { } + visitReactiveFunctionValue(_id, _dependencies, _fn, _state) { } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + } + traverseValue(id, value, state) { + switch (value.kind) { + case 'OptionalExpression': { + this.visitValue(id, value.value, state); + break; + } + case 'LogicalExpression': { + this.visitValue(id, value.left, state); + this.visitValue(id, value.right, state); + break; + } + case 'ConditionalExpression': { + this.visitValue(id, value.test, state); + this.visitValue(id, value.consequent, state); + this.visitValue(id, value.alternate, state); + break; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + this.visitValue(value.id, value.value, state); + break; + } + default: { + for (const place of eachInstructionValueOperand(value)) { + this.visitPlace(id, place, state); + } + } + } + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + } + traverseInstruction(instruction, state) { + this.visitID(instruction.id, state); + for (const operand of eachInstructionLValue(instruction)) { + this.visitLValue(instruction.id, operand, state); + } + this.visitValue(instruction.id, instruction.value, state); + } + visitTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + } + traverseTerminal(stmt, state) { + const { terminal } = stmt; + if (terminal.id !== null) { + this.visitID(terminal.id, state); + } + switch (terminal.kind) { + case 'break': + case 'continue': { + break; + } + case 'return': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'throw': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'for': { + this.visitValue(terminal.id, terminal.init, state); + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + if (terminal.update !== null) { + this.visitValue(terminal.id, terminal.update, state); + } + break; + } + case 'for-of': { + this.visitValue(terminal.id, terminal.init, state); + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'for-in': { + this.visitValue(terminal.id, terminal.init, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'do-while': { + this.visitBlock(terminal.loop, state); + this.visitValue(terminal.id, terminal.test, state); + break; + } + case 'while': { + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'if': { + this.visitPlace(terminal.id, terminal.test, state); + this.visitBlock(terminal.consequent, state); + if (terminal.alternate !== null) { + this.visitBlock(terminal.alternate, state); + } + break; + } + case 'switch': { + this.visitPlace(terminal.id, terminal.test, state); + for (const case_ of terminal.cases) { + if (case_.test !== null) { + this.visitPlace(terminal.id, case_.test, state); + } + if (case_.block !== undefined) { + this.visitBlock(case_.block, state); + } + } + break; + } + case 'label': { + this.visitBlock(terminal.block, state); + break; + } + case 'try': { + this.visitBlock(terminal.block, state); + this.visitBlock(terminal.handler, state); + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } + visitScope(scope, state) { + this.traverseScope(scope, state); + } + traverseScope(scope, state) { + this.visitBlock(scope.instructions, state); + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + } + traversePrunedScope(scopeBlock, state) { + this.visitBlock(scopeBlock.instructions, state); + } + visitBlock(block, state) { + this.traverseBlock(block, state); + } + traverseBlock(block, state) { + for (const instr of block) { + switch (instr.kind) { + case 'instruction': { + this.visitInstruction(instr.instruction, state); + break; + } + case 'scope': { + this.visitScope(instr, state); + break; + } + case 'pruned-scope': { + this.visitPrunedScope(instr, state); + break; + } + case 'terminal': { + this.visitTerminal(instr, state); + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + } + } + visitHirFunction(fn, state) { + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + this.visitParam(place, state); + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + this.visitInstruction(instr, state); + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + this.visitHirFunction(instr.value.loweredFunc.func, state); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + this.visitPlace(block.terminal.id, operand, state); + } + } + } +} +class ReactiveFunctionTransform extends ReactiveFunctionVisitor { + traverseBlock(block, state) { + let nextBlock = null; + for (let i = 0; i < block.length; i++) { + const instr = block[i]; + let transformed; + switch (instr.kind) { + case 'instruction': { + transformed = this.transformInstruction(instr.instruction, state); + break; + } + case 'scope': { + transformed = this.transformScope(instr, state); + break; + } + case 'pruned-scope': { + transformed = this.transformPrunedScope(instr, state); + break; + } + case 'terminal': { + transformed = this.transformTerminal(instr, state); + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + switch (transformed.kind) { + case 'keep': { + if (nextBlock !== null) { + nextBlock.push(instr); + } + break; + } + case 'remove': { + if (nextBlock === null) { + nextBlock = block.slice(0, i); + } + break; + } + case 'replace': { + nextBlock !== null && nextBlock !== void 0 ? nextBlock : (nextBlock = block.slice(0, i)); + nextBlock.push(transformed.value); + break; + } + case 'replace-many': { + nextBlock !== null && nextBlock !== void 0 ? nextBlock : (nextBlock = block.slice(0, i)); + nextBlock.push(...transformed.value); + break; + } + } + } + if (nextBlock !== null) { + block.length = 0; + block.push(...nextBlock); + } + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + return { kind: 'keep' }; + } + transformTerminal(stmt, state) { + this.visitTerminal(stmt, state); + return { kind: 'keep' }; + } + transformScope(scope, state) { + this.visitScope(scope, state); + return { kind: 'keep' }; + } + transformPrunedScope(scope, state) { + this.visitPrunedScope(scope, state); + return { kind: 'keep' }; + } + transformValue(id, value, state) { + this.visitValue(id, value, state); + return { kind: 'keep' }; + } + transformReactiveFunctionValue(id, dependencies, fn, state) { + this.visitReactiveFunctionValue(id, dependencies, fn, state); + return { kind: 'keep' }; + } + traverseValue(id, value, state) { + switch (value.kind) { + case 'OptionalExpression': { + const nextValue = this.transformValue(id, value.value, state); + if (nextValue.kind === 'replace') { + value.value = nextValue.value; + } + break; + } + case 'LogicalExpression': { + const left = this.transformValue(id, value.left, state); + if (left.kind === 'replace') { + value.left = left.value; + } + const right = this.transformValue(id, value.right, state); + if (right.kind === 'replace') { + value.right = right.value; + } + break; + } + case 'ConditionalExpression': { + const test = this.transformValue(id, value.test, state); + if (test.kind === 'replace') { + value.test = test.value; + } + const consequent = this.transformValue(id, value.consequent, state); + if (consequent.kind === 'replace') { + value.consequent = consequent.value; + } + const alternate = this.transformValue(id, value.alternate, state); + if (alternate.kind === 'replace') { + value.alternate = alternate.value; + } + break; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + const nextValue = this.transformValue(value.id, value.value, state); + if (nextValue.kind === 'replace') { + value.value = nextValue.value; + } + break; + } + default: { + for (const place of eachInstructionValueOperand(value)) { + this.visitPlace(id, place, state); + } + } + } + } + traverseInstruction(instruction, state) { + this.visitID(instruction.id, state); + for (const operand of eachInstructionLValue(instruction)) { + this.visitLValue(instruction.id, operand, state); + } + const nextValue = this.transformValue(instruction.id, instruction.value, state); + if (nextValue.kind === 'replace') { + instruction.value = nextValue.value; + } + } + traverseTerminal(stmt, state) { + const { terminal } = stmt; + if (terminal.id !== null) { + this.visitID(terminal.id, state); + } + switch (terminal.kind) { + case 'break': + case 'continue': { + break; + } + case 'return': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'throw': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'for': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + if (terminal.update !== null) { + const update = this.transformValue(terminal.id, terminal.update, state); + if (update.kind === 'replace') { + terminal.update = update.value; + } + } + this.visitBlock(terminal.loop, state); + break; + } + case 'for-of': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'for-in': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'do-while': { + this.visitBlock(terminal.loop, state); + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + break; + } + case 'while': { + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'if': { + this.visitPlace(terminal.id, terminal.test, state); + this.visitBlock(terminal.consequent, state); + if (terminal.alternate !== null) { + this.visitBlock(terminal.alternate, state); + } + break; + } + case 'switch': { + this.visitPlace(terminal.id, terminal.test, state); + for (const case_ of terminal.cases) { + if (case_.test !== null) { + this.visitPlace(terminal.id, case_.test, state); + } + if (case_.block !== undefined) { + this.visitBlock(case_.block, state); + } + } + break; + } + case 'label': { + this.visitBlock(terminal.block, state); + break; + } + case 'try': { + this.visitBlock(terminal.block, state); + if (terminal.handlerBinding !== null) { + this.visitPlace(terminal.id, terminal.handlerBinding, state); + } + this.visitBlock(terminal.handler, state); + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } +} +function* eachReactiveValueOperand(instrValue) { + switch (instrValue.kind) { + case 'OptionalExpression': { + yield* eachReactiveValueOperand(instrValue.value); + break; + } + case 'LogicalExpression': { + yield* eachReactiveValueOperand(instrValue.left); + yield* eachReactiveValueOperand(instrValue.right); + break; + } + case 'SequenceExpression': { + for (const instr of instrValue.instructions) { + yield* eachReactiveValueOperand(instr.value); + } + yield* eachReactiveValueOperand(instrValue.value); + break; + } + case 'ConditionalExpression': { + yield* eachReactiveValueOperand(instrValue.test); + yield* eachReactiveValueOperand(instrValue.consequent); + yield* eachReactiveValueOperand(instrValue.alternate); + break; + } + default: { + yield* eachInstructionValueOperand(instrValue); + } + } +} + +function assertScopeInstructionsWithinScopes(fn) { + const existingScopes = new Set(); + visitReactiveFunction(fn, new FindAllScopesVisitor(), existingScopes); + visitReactiveFunction(fn, new CheckInstructionsAgainstScopesVisitor(), existingScopes); +} +class FindAllScopesVisitor extends ReactiveFunctionVisitor { + visitScope(block, state) { + this.traverseScope(block, state); + state.add(block.scope.id); + } +} +class CheckInstructionsAgainstScopesVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.activeScopes = new Set(); + } + visitPlace(id, place, state) { + const scope = getPlaceScope(id, place); + if (scope !== null && + state.has(scope.id) && + !this.activeScopes.has(scope.id)) { + CompilerError.invariant(false, { + description: `Instruction [${id}] is part of scope @${scope.id}, but that scope has already completed.`, + loc: place.loc, + reason: 'Encountered an instruction that should be part of a scope, but where that scope has already completed', + suggestions: null, + }); + } + } + visitScope(block, state) { + this.activeScopes.add(block.scope.id); + this.traverseScope(block, state); + this.activeScopes.delete(block.scope.id); + } +} + +function assertWellFormedBreakTargets(fn) { + visitReactiveFunction(fn, new Visitor$a(), new Set()); +} +let Visitor$a = class Visitor extends ReactiveFunctionVisitor { + visitTerminal(stmt, seenLabels) { + if (stmt.label != null) { + seenLabels.add(stmt.label.id); + } + const terminal = stmt.terminal; + if (terminal.kind === 'break' || terminal.kind === 'continue') { + CompilerError.invariant(seenLabels.has(terminal.target), { + reason: 'Unexpected break to invalid label', + loc: stmt.terminal.loc, + }); + } + } +}; + +var _Context_nextScheduleId, _Context_scheduled, _Context_catchHandlers, _Context_controlFlowStack; +function buildReactiveFunction(fn) { + const cx = new Context$2(fn.body); + const driver = new Driver(cx); + const body = driver.traverseBlock(cx.block(fn.body.entry)); + return { + loc: fn.loc, + id: fn.id, + params: fn.params, + generator: fn.generator, + async: fn.async, + body, + env: fn.env, + directives: fn.directives, + }; +} +class Driver { + constructor(cx) { + this.cx = cx; + } + traverseBlock(block) { + const blockValue = []; + this.visitBlock(block, blockValue); + return blockValue; + } + visitBlock(block, blockValue) { + var _a; + CompilerError.invariant(!this.cx.emitted.has(block.id), { + reason: `Cannot emit the same block twice: bb${block.id}`, + description: null, + loc: null, + suggestions: null, + }); + this.cx.emitted.add(block.id); + for (const instruction of block.instructions) { + blockValue.push({ + kind: 'instruction', + instruction, + }); + } + const terminal = block.terminal; + const scheduleIds = []; + switch (terminal.kind) { + case 'return': { + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'return', + loc: terminal.loc, + value: terminal.value, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'throw': { + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'throw', + loc: terminal.loc, + value: terminal.value, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'if': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const alternateId = terminal.alternate !== terminal.fallthrough + ? terminal.alternate + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + let consequent = null; + if (this.cx.isScheduled(terminal.consequent)) { + CompilerError.invariant(false, { + reason: `Unexpected 'if' where the consequent is already scheduled`, + loc: terminal.loc, + }); + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(terminal.consequent)); + } + let alternate = null; + if (alternateId !== null) { + if (this.cx.isScheduled(alternateId)) { + CompilerError.invariant(false, { + reason: `Unexpected 'if' where the alternate is already scheduled`, + loc: terminal.loc, + }); + } + else { + alternate = this.traverseBlock(this.cx.ir.blocks.get(alternateId)); + } + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'if', + loc: terminal.loc, + test: terminal.test, + consequent: consequent !== null && consequent !== void 0 ? consequent : this.emptyBlock(), + alternate: alternate, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'switch': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'switch'); + scheduleIds.push(scheduleId); + } + const cases = []; + [...terminal.cases].reverse().forEach((case_, _index) => { + const test = case_.test; + let consequent; + if (this.cx.isScheduled(case_.block)) { + CompilerError.invariant(case_.block === terminal.fallthrough, { + reason: `Unexpected 'switch' where a case is already scheduled and block is not the fallthrough`, + loc: terminal.loc, + }); + return; + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(case_.block)); + const scheduleId = this.cx.schedule(case_.block, 'case'); + scheduleIds.push(scheduleId); + } + cases.push({ test, block: consequent }); + }); + cases.reverse(); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'switch', + loc: terminal.loc, + test: terminal.test, + cases, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'do-while': { + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'do-while' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'do-while', + loc: terminal.loc, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'while': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'while' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'while', + loc: terminal.loc, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, (_a = terminal.update) !== null && _a !== void 0 ? _a : terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + const updateValue = terminal.update !== null + ? this.visitValueBlock(terminal.update, terminal.loc).value + : null; + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for', + loc: terminal.loc, + init: initValue, + test: testValue, + update: updateValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for-of': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.init, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + let testValue = test.value; + if (testValue.kind === 'SequenceExpression') { + const last = testBlock.instructions.at(-1); + testValue.instructions.push(last); + testValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + testValue = { + kind: 'SequenceExpression', + instructions: [testBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for-of' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for-of', + loc: terminal.loc, + init: initValue, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for-in': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.init, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for-in' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for-in', + loc: terminal.loc, + init: initValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'branch': { + let consequent = null; + if (this.cx.isScheduled(terminal.consequent)) { + const break_ = this.visitBreak(terminal.consequent, terminal.id, terminal.loc); + if (break_ !== null) { + consequent = [break_]; + } + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(terminal.consequent)); + } + let alternate = null; + if (this.cx.isScheduled(terminal.alternate)) { + CompilerError.invariant(false, { + reason: `Unexpected 'branch' where the alternate is already scheduled`, + loc: terminal.loc, + }); + } + else { + alternate = this.traverseBlock(this.cx.ir.blocks.get(terminal.alternate)); + } + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'if', + loc: terminal.loc, + test: terminal.test, + consequent: consequent !== null && consequent !== void 0 ? consequent : this.emptyBlock(), + alternate: alternate, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'label': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + let block; + if (this.cx.isScheduled(terminal.block)) { + CompilerError.invariant(false, { + reason: `Unexpected 'label' where the block is already scheduled`, + loc: terminal.loc, + }); + } + else { + block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'label', + loc: terminal.loc, + block, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'sequence': + case 'optional': + case 'ternary': + case 'logical': { + const fallthroughId = terminal.fallthrough !== null && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + const { place, value } = this.visitValueBlockTerminal(terminal); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'instruction', + instruction: { + id: terminal.id, + lvalue: place, + value, + loc: terminal.loc, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'goto': { + switch (terminal.variant) { + case GotoVariant.Break: { + const break_ = this.visitBreak(terminal.block, terminal.id, terminal.loc); + if (break_ !== null) { + blockValue.push(break_); + } + break; + } + case GotoVariant.Continue: { + const continue_ = this.visitContinue(terminal.block, terminal.id, terminal.loc); + if (continue_ !== null) { + blockValue.push(continue_); + } + break; + } + case GotoVariant.Try: { + break; + } + default: { + assertExhaustive$1(terminal.variant, `Unexpected goto variant \`${terminal.variant}\``); + } + } + break; + } + case 'maybe-throw': { + if (!this.cx.isScheduled(terminal.continuation)) { + this.visitBlock(this.cx.ir.blocks.get(terminal.continuation), blockValue); + } + break; + } + case 'try': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + this.cx.scheduleCatchHandler(terminal.handler); + const block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + const handler = this.traverseBlock(this.cx.ir.blocks.get(terminal.handler)); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + terminal: { + kind: 'try', + loc: terminal.loc, + block, + handlerBinding: terminal.handlerBinding, + handler, + id: terminal.id, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'pruned-scope': + case 'scope': { + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + this.cx.scopeFallthroughs.add(fallthroughId); + } + let block; + if (this.cx.isScheduled(terminal.block)) { + CompilerError.invariant(false, { + reason: `Unexpected 'scope' where the block is already scheduled`, + loc: terminal.loc, + }); + } + else { + block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: terminal.kind, + instructions: block, + scope: terminal.scope, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'unreachable': { + break; + } + case 'unsupported': { + CompilerError.invariant(false, { + reason: 'Unexpected unsupported terminal', + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(terminal, 'Unexpected terminal'); + } + } + } + visitValueBlock(id, loc) { + const defaultBlock = this.cx.ir.blocks.get(id); + if (defaultBlock.terminal.kind === 'branch') { + const instructions = defaultBlock.instructions; + if (instructions.length === 0) { + return { + block: defaultBlock.id, + place: defaultBlock.terminal.test, + value: { + kind: 'LoadLocal', + place: defaultBlock.terminal.test, + loc: defaultBlock.terminal.test.loc, + }, + id: defaultBlock.terminal.id, + }; + } + else if (defaultBlock.instructions.length === 1) { + const instr = defaultBlock.instructions[0]; + CompilerError.invariant(instr.lvalue.identifier.id === + defaultBlock.terminal.test.identifier.id, { + reason: 'Expected branch block to end in an instruction that sets the test value', + description: null, + loc: instr.lvalue.loc, + suggestions: null, + }); + return { + block: defaultBlock.id, + place: instr.lvalue, + value: instr.value, + id: instr.id, + }; + } + else { + const instr = defaultBlock.instructions.at(-1); + const sequence = { + kind: 'SequenceExpression', + instructions: defaultBlock.instructions.slice(0, -1), + id: instr.id, + value: instr.value, + loc: loc, + }; + return { + block: defaultBlock.id, + place: defaultBlock.terminal.test, + value: sequence, + id: defaultBlock.terminal.id, + }; + } + } + else if (defaultBlock.terminal.kind === 'goto') { + const instructions = defaultBlock.instructions; + if (instructions.length === 0) { + CompilerError.invariant(false, { + reason: 'Expected goto value block to have at least one instruction', + description: null, + loc: null, + suggestions: null, + }); + } + else if (defaultBlock.instructions.length === 1) { + const instr = defaultBlock.instructions[0]; + let place = instr.lvalue; + let value = instr.value; + if (value.kind === 'StoreLocal' && + value.lvalue.place.identifier.name === null) { + place = value.lvalue.place; + value = { + kind: 'LoadLocal', + place: value.value, + loc: value.value.loc, + }; + } + return { + block: defaultBlock.id, + place, + value, + id: instr.id, + }; + } + else { + const instr = defaultBlock.instructions.at(-1); + let place = instr.lvalue; + let value = instr.value; + if (value.kind === 'StoreLocal' && + value.lvalue.place.identifier.name === null) { + place = value.lvalue.place; + value = { + kind: 'LoadLocal', + place: value.value, + loc: value.value.loc, + }; + } + const sequence = { + kind: 'SequenceExpression', + instructions: defaultBlock.instructions.slice(0, -1), + id: instr.id, + value, + loc: loc, + }; + return { + block: defaultBlock.id, + place, + value: sequence, + id: instr.id, + }; + } + } + else { + const init = this.visitValueBlockTerminal(defaultBlock.terminal); + const final = this.visitValueBlock(init.fallthrough, loc); + const sequence = { + kind: 'SequenceExpression', + instructions: [ + ...defaultBlock.instructions, + { + id: init.id, + loc, + lvalue: init.place, + value: init.value, + }, + ], + id: final.id, + value: final.value, + loc, + }; + return { + block: init.fallthrough, + value: sequence, + place: final.place, + id: final.id, + }; + } + } + visitValueBlockTerminal(terminal) { + switch (terminal.kind) { + case 'sequence': { + const block = this.visitValueBlock(terminal.block, terminal.loc); + return { + value: block.value, + place: block.place, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'optional': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const consequent = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const call = { + kind: 'SequenceExpression', + instructions: [ + { + id: test.id, + loc: testBlock.terminal.loc, + lvalue: test.place, + value: test.value, + }, + ], + id: consequent.id, + value: consequent.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, consequent.place), + value: { + kind: 'OptionalExpression', + optional: terminal.optional, + value: call, + id: terminal.id, + loc: terminal.loc, + }, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'logical': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for logical test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const leftFinal = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const left = { + kind: 'SequenceExpression', + instructions: [ + { + id: test.id, + loc: terminal.loc, + lvalue: test.place, + value: test.value, + }, + ], + id: leftFinal.id, + value: leftFinal.value, + loc: terminal.loc, + }; + const right = this.visitValueBlock(testBlock.terminal.alternate, terminal.loc); + const value = { + kind: 'LogicalExpression', + operator: terminal.operator, + left: left, + right: right.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, leftFinal.place), + value, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'ternary': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for ternary test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const consequent = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const alternate = this.visitValueBlock(testBlock.terminal.alternate, terminal.loc); + const value = { + kind: 'ConditionalExpression', + test: test.value, + consequent: consequent.value, + alternate: alternate.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, consequent.place), + value, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'maybe-throw': { + CompilerError.throwTodo({ + reason: `Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + case 'label': { + CompilerError.throwTodo({ + reason: `Support labeled statements combined with value blocks (conditional, logical, optional chaining, etc)`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + default: { + CompilerError.throwTodo({ + reason: `Support \`${terminal.kind}\` as a value block terminal (conditional, logical, optional chaining, etc)`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + } + } + emptyBlock() { + return []; + } + visitBreak(block, id, loc) { + const target = this.cx.getBreakTarget(block); + if (target === null) { + CompilerError.invariant(false, { + reason: 'Expected a break target', + description: null, + loc: null, + suggestions: null, + }); + } + if (this.cx.scopeFallthroughs.has(target.block)) { + CompilerError.invariant(target.type === 'implicit', { + reason: 'Expected reactive scope to implicitly break to fallthrough', + loc, + }); + return null; + } + return { + kind: 'terminal', + terminal: { + kind: 'break', + loc, + target: target.block, + id, + targetKind: target.type, + }, + label: null, + }; + } + visitContinue(block, id, loc) { + const target = this.cx.getContinueTarget(block); + CompilerError.invariant(target !== null, { + reason: `Expected continue target to be scheduled for bb${block}`, + description: null, + loc: null, + suggestions: null, + }); + return { + kind: 'terminal', + terminal: { + kind: 'continue', + loc, + target: target.block, + id, + targetKind: target.type, + }, + label: null, + }; + } +} +let Context$2 = class Context { + constructor(ir) { + _Context_nextScheduleId.set(this, 0); + this.emitted = new Set(); + this.scopeFallthroughs = new Set(); + _Context_scheduled.set(this, new Set()); + _Context_catchHandlers.set(this, new Set()); + _Context_controlFlowStack.set(this, []); + this.ir = ir; + } + block(id) { + return this.ir.blocks.get(id); + } + scheduleCatchHandler(block) { + __classPrivateFieldGet(this, _Context_catchHandlers, "f").add(block); + } + reachable(id) { + const block = this.ir.blocks.get(id); + return block.terminal.kind !== 'unreachable'; + } + schedule(block, type) { + var _a, _b; + const id = (__classPrivateFieldSet(this, _Context_nextScheduleId, (_b = __classPrivateFieldGet(this, _Context_nextScheduleId, "f"), _a = _b++, _b), "f"), _a); + CompilerError.invariant(!__classPrivateFieldGet(this, _Context_scheduled, "f").has(block), { + reason: `Break block is already scheduled: bb${block}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(block); + __classPrivateFieldGet(this, _Context_controlFlowStack, "f").push({ block, id, type }); + return id; + } + scheduleLoop(fallthroughBlock, continueBlock, loopBlock) { + var _a, _b; + const id = (__classPrivateFieldSet(this, _Context_nextScheduleId, (_b = __classPrivateFieldGet(this, _Context_nextScheduleId, "f"), _a = _b++, _b), "f"), _a); + const ownsBlock = !__classPrivateFieldGet(this, _Context_scheduled, "f").has(fallthroughBlock); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(fallthroughBlock); + CompilerError.invariant(!__classPrivateFieldGet(this, _Context_scheduled, "f").has(continueBlock), { + reason: `Continue block is already scheduled: bb${continueBlock}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(continueBlock); + let ownsLoop = false; + if (loopBlock !== null) { + ownsLoop = !__classPrivateFieldGet(this, _Context_scheduled, "f").has(loopBlock); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(loopBlock); + } + __classPrivateFieldGet(this, _Context_controlFlowStack, "f").push({ + block: fallthroughBlock, + ownsBlock, + id, + type: 'loop', + continueBlock, + loopBlock, + ownsLoop, + }); + return id; + } + unschedule(scheduleId) { + const last = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").pop(); + CompilerError.invariant(last !== undefined && last.id === scheduleId, { + reason: 'Can only unschedule the last target', + description: null, + loc: null, + suggestions: null, + }); + if (last.type !== 'loop' || last.ownsBlock !== null) { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.block); + } + if (last.type === 'loop') { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.continueBlock); + if (last.ownsLoop && last.loopBlock !== null) { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.loopBlock); + } + } + } + unscheduleAll(scheduleIds) { + for (let i = scheduleIds.length - 1; i >= 0; i--) { + this.unschedule(scheduleIds[i]); + } + } + isScheduled(block) { + return __classPrivateFieldGet(this, _Context_scheduled, "f").has(block) || __classPrivateFieldGet(this, _Context_catchHandlers, "f").has(block); + } + getBreakTarget(block) { + let hasPrecedingLoop = false; + for (let i = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1; i >= 0; i--) { + const target = __classPrivateFieldGet(this, _Context_controlFlowStack, "f")[i]; + if (target.block === block) { + let type; + if (target.type === 'loop') { + type = hasPrecedingLoop ? 'labeled' : 'unlabeled'; + } + else if (i === __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1) { + type = 'implicit'; + } + else { + type = 'labeled'; + } + return { + block: target.block, + type, + }; + } + hasPrecedingLoop || (hasPrecedingLoop = target.type === 'loop'); + } + CompilerError.invariant(false, { + reason: 'Expected a break target', + description: null, + loc: null, + suggestions: null, + }); + } + getContinueTarget(block) { + let hasPrecedingLoop = false; + for (let i = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1; i >= 0; i--) { + const target = __classPrivateFieldGet(this, _Context_controlFlowStack, "f")[i]; + if (target.type == 'loop' && target.continueBlock === block) { + let type; + if (hasPrecedingLoop) { + type = 'labeled'; + } + else if (i === __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1) { + type = 'implicit'; + } + else { + type = 'unlabeled'; + } + return { + block: target.block, + type, + }; + } + hasPrecedingLoop || (hasPrecedingLoop = target.type === 'loop'); + } + return null; + } + debugBreakTargets() { + return __classPrivateFieldGet(this, _Context_controlFlowStack, "f").map(target => (Object.assign({}, target))); + } +}; +_Context_nextScheduleId = new WeakMap(), _Context_scheduled = new WeakMap(), _Context_catchHandlers = new WeakMap(), _Context_controlFlowStack = new WeakMap(); + +var GuardKind; +(function (GuardKind) { + GuardKind[GuardKind["PushHookGuard"] = 0] = "PushHookGuard"; + GuardKind[GuardKind["PopHookGuard"] = 1] = "PopHookGuard"; + GuardKind[GuardKind["AllowHook"] = 2] = "AllowHook"; + GuardKind[GuardKind["DisallowHook"] = 3] = "DisallowHook"; +})(GuardKind || (GuardKind = {})); + +function memoizeFbtAndMacroOperandsInSameScope(fn) { + var _a; + const fbtMacroTags = new Set([ + ...Array.from(FBT_TAGS).map((tag) => [tag, []]), + ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []), + ]); + const fbtValues = new Set(); + const macroMethods = new Map(); + while (true) { + let vsize = fbtValues.size; + let msize = macroMethods.size; + visit$1(fn, fbtMacroTags, fbtValues, macroMethods); + if (vsize === fbtValues.size && msize === macroMethods.size) { + break; + } + } + return fbtValues; +} +const FBT_TAGS = new Set([ + 'fbt', + 'fbt:param', + 'fbs', + 'fbs:param', +]); +const SINGLE_CHILD_FBT_TAGS = new Set([ + 'fbt:param', + 'fbs:param', +]); +function visit$1(fn, fbtMacroTags, fbtValues, macroMethods) { + for (const [, block] of fn.body.blocks) { + for (const instruction of block.instructions) { + const { lvalue, value } = instruction; + if (lvalue === null) { + continue; + } + if (value.kind === 'Primitive' && + typeof value.value === 'string' && + matchesExactTag(value.value, fbtMacroTags)) { + fbtValues.add(lvalue.identifier.id); + } + else if (value.kind === 'LoadGlobal' && + matchesExactTag(value.binding.name, fbtMacroTags)) { + fbtValues.add(lvalue.identifier.id); + } + else if (value.kind === 'LoadGlobal' && + matchTagRoot(value.binding.name, fbtMacroTags) !== null) { + const methods = matchTagRoot(value.binding.name, fbtMacroTags); + macroMethods.set(lvalue.identifier.id, methods); + } + else if (value.kind === 'PropertyLoad' && + macroMethods.has(value.object.identifier.id)) { + const methods = macroMethods.get(value.object.identifier.id); + const newMethods = []; + for (const method of methods) { + if (method.length > 0 && + (method[0].type === 'wildcard' || + (method[0].type === 'name' && method[0].name === value.property))) { + if (method.length > 1) { + newMethods.push(method.slice(1)); + } + else { + fbtValues.add(lvalue.identifier.id); + } + } + } + if (newMethods.length > 0) { + macroMethods.set(lvalue.identifier.id, newMethods); + } + } + else if (isFbtCallExpression(fbtValues, value)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + continue; + } + for (const operand of eachReactiveValueOperand(value)) { + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + fbtValues.add(operand.identifier.id); + } + } + else if (isFbtJsxExpression(fbtMacroTags, fbtValues, value) || + isFbtJsxChild(fbtValues, lvalue, value)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + continue; + } + for (const operand of eachReactiveValueOperand(value)) { + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + fbtValues.add(operand.identifier.id); + } + } + else if (fbtValues.has(lvalue.identifier.id)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + return; + } + for (const operand of eachReactiveValueOperand(value)) { + if (operand.identifier.name !== null && + operand.identifier.name.kind === 'named') { + continue; + } + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + } + } + } + } +} +function matchesExactTag(s, tags) { + return Array.from(tags).some(macro => typeof macro === 'string' + ? s === macro + : macro[1].length === 0 && macro[0] === s); +} +function matchTagRoot(s, tags) { + const methods = []; + for (const macro of tags) { + if (typeof macro === 'string') { + continue; + } + const [tag, rest] = macro; + if (tag === s && rest.length > 0) { + methods.push(rest); + } + } + if (methods.length > 0) { + return methods; + } + else { + return null; + } +} +function isFbtCallExpression(fbtValues, value) { + return ((value.kind === 'CallExpression' && + fbtValues.has(value.callee.identifier.id)) || + (value.kind === 'MethodCall' && fbtValues.has(value.property.identifier.id))); +} +function isFbtJsxExpression(fbtMacroTags, fbtValues, value) { + return (value.kind === 'JsxExpression' && + ((value.tag.kind === 'Identifier' && + fbtValues.has(value.tag.identifier.id)) || + (value.tag.kind === 'BuiltinTag' && + matchesExactTag(value.tag.name, fbtMacroTags)))); +} +function isFbtJsxChild(fbtValues, lvalue, value) { + return ((value.kind === 'JsxExpression' || value.kind === 'JsxFragment') && + lvalue !== null && + fbtValues.has(lvalue.identifier.id)); +} +function expandFbtScopeRange(fbtRange, extendWith) { + if (extendWith.start !== 0) { + fbtRange.start = makeInstructionId(Math.min(fbtRange.start, extendWith.start)); + } +} + +var _Context_nextCacheIndex, _Context_declarations; +const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel'; +const EARLY_RETURN_SENTINEL = 'react.early_return_sentinel'; +function codegenFunction(fn, { uniqueIdentifiers, fbtOperands, }) { + var _a, _b, _c; + const cx = new Context$1(fn.env, (_a = fn.id) !== null && _a !== void 0 ? _a : '[[ anonymous ]]', uniqueIdentifiers, fbtOperands, null); + let fastRefreshState = null; + if (fn.env.config.enableResetCacheOnSourceFileChanges && + fn.env.code !== null) { + const hash = crypto.createHmac('sha256', fn.env.code).digest('hex'); + fastRefreshState = { + cacheIndex: cx.nextCacheIndex, + hash, + }; + } + const compileResult = codegenReactiveFunction(cx, fn); + if (compileResult.isErr()) { + return compileResult; + } + const compiled = compileResult.unwrap(); + const hookGuard = fn.env.config.enableEmitHookGuards; + if (hookGuard != null && fn.env.isInferredMemoEnabled) { + compiled.body = libExports$1.blockStatement([ + createHookGuard(hookGuard, fn.env.programContext, compiled.body.body, GuardKind.PushHookGuard, GuardKind.PopHookGuard), + ]); + } + const cacheCount = compiled.memoSlotsUsed; + if (cacheCount !== 0) { + const preface = []; + const useMemoCacheIdentifier = fn.env.programContext.addMemoCacheImport().name; + preface.push(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.callExpression(libExports$1.identifier(useMemoCacheIdentifier), [ + libExports$1.numericLiteral(cacheCount), + ])), + ])); + if (fastRefreshState !== null) { + const index = cx.synthesizeName('$i'); + preface.push(libExports$1.ifStatement(libExports$1.binaryExpression('!==', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(fastRefreshState.cacheIndex), true), libExports$1.stringLiteral(fastRefreshState.hash)), libExports$1.blockStatement([ + libExports$1.forStatement(libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(index), libExports$1.numericLiteral(0)), + ]), libExports$1.binaryExpression('<', libExports$1.identifier(index), libExports$1.numericLiteral(cacheCount)), libExports$1.assignmentExpression('+=', libExports$1.identifier(index), libExports$1.numericLiteral(1)), libExports$1.blockStatement([ + libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.identifier(index), true), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(MEMO_CACHE_SENTINEL)]))), + ])), + libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(fastRefreshState.cacheIndex), true), libExports$1.stringLiteral(fastRefreshState.hash))), + ]))); + } + compiled.body.body.unshift(...preface); + } + const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget; + if (emitInstrumentForget != null && + fn.id != null && + fn.env.isInferredMemoEnabled) { + const gating = emitInstrumentForget.gating != null + ? libExports$1.identifier(fn.env.programContext.addImportSpecifier(emitInstrumentForget.gating).name) + : null; + const globalGating = emitInstrumentForget.globalGating != null + ? libExports$1.identifier(emitInstrumentForget.globalGating) + : null; + if (emitInstrumentForget.globalGating != null) { + const assertResult = fn.env.programContext.assertGlobalBinding(emitInstrumentForget.globalGating); + if (assertResult.isErr()) { + return assertResult; + } + } + let ifTest; + if (gating != null && globalGating != null) { + ifTest = libExports$1.logicalExpression('&&', globalGating, gating); + } + else if (gating != null) { + ifTest = gating; + } + else { + CompilerError.invariant(globalGating != null, { + reason: 'Bad config not caught! Expected at least one of gating or globalGating', + loc: null, + suggestions: null, + }); + ifTest = globalGating; + } + const instrumentFnIdentifier = fn.env.programContext.addImportSpecifier(emitInstrumentForget.fn).name; + const test = libExports$1.ifStatement(ifTest, libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(instrumentFnIdentifier), [ + libExports$1.stringLiteral(fn.id), + libExports$1.stringLiteral((_b = fn.env.filename) !== null && _b !== void 0 ? _b : ''), + ]))); + compiled.body.body.unshift(test); + } + const outlined = []; + for (const { fn: outlinedFunction, type } of cx.env.getOutlinedFunctions()) { + const reactiveFunction = buildReactiveFunction(outlinedFunction); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + pruneHoistedContexts(reactiveFunction); + const identifiers = renameVariables(reactiveFunction); + const codegen = codegenReactiveFunction(new Context$1(cx.env, (_c = reactiveFunction.id) !== null && _c !== void 0 ? _c : '[[ anonymous ]]', identifiers, cx.fbtOperands), reactiveFunction); + if (codegen.isErr()) { + return codegen; + } + outlined.push({ fn: codegen.unwrap(), type }); + } + compiled.outlined = outlined; + return compileResult; +} +function codegenReactiveFunction(cx, fn) { + for (const param of fn.params) { + if (param.kind === 'Identifier') { + cx.temp.set(param.identifier.declarationId, null); + } + else { + cx.temp.set(param.place.identifier.declarationId, null); + } + } + const params = fn.params.map(param => convertParameter(param)); + const body = codegenBlock(cx, fn.body); + body.directives = fn.directives.map(d => libExports$1.directive(libExports$1.directiveLiteral(d))); + const statements = body.body; + if (statements.length !== 0) { + const last = statements[statements.length - 1]; + if (last.type === 'ReturnStatement' && last.argument == null) { + statements.pop(); + } + } + if (cx.errors.hasErrors()) { + return Err(cx.errors); + } + const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env); + visitReactiveFunction(fn, countMemoBlockVisitor, undefined); + return Ok({ + type: 'CodegenFunction', + loc: fn.loc, + id: fn.id !== null ? libExports$1.identifier(fn.id) : null, + params, + body, + generator: fn.generator, + async: fn.async, + memoSlotsUsed: cx.nextCacheIndex, + memoBlocks: countMemoBlockVisitor.memoBlocks, + memoValues: countMemoBlockVisitor.memoValues, + prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks, + prunedMemoValues: countMemoBlockVisitor.prunedMemoValues, + outlined: [], + hasFireRewrite: fn.env.hasFireRewrite, + hasInferredEffect: fn.env.hasInferredEffect, + inferredEffectLocations: fn.env.inferredEffectLocations, + }); +} +class CountMemoBlockVisitor extends ReactiveFunctionVisitor { + constructor(env) { + super(); + this.memoBlocks = 0; + this.memoValues = 0; + this.prunedMemoBlocks = 0; + this.prunedMemoValues = 0; + this.env = env; + } + visitScope(scopeBlock, state) { + this.memoBlocks += 1; + this.memoValues += scopeBlock.scope.declarations.size; + this.traverseScope(scopeBlock, state); + } + visitPrunedScope(scopeBlock, state) { + this.prunedMemoBlocks += 1; + this.prunedMemoValues += scopeBlock.scope.declarations.size; + this.traversePrunedScope(scopeBlock, state); + } +} +function convertParameter(param) { + if (param.kind === 'Identifier') { + return convertIdentifier(param.identifier); + } + else { + return libExports$1.restElement(convertIdentifier(param.place.identifier)); + } +} +let Context$1 = class Context { + constructor(env, fnName, uniqueIdentifiers, fbtOperands, temporaries = null) { + _Context_nextCacheIndex.set(this, 0); + _Context_declarations.set(this, new Set()); + this.errors = new CompilerError(); + this.objectMethods = new Map(); + this.synthesizedNames = new Map(); + this.env = env; + this.fnName = fnName; + this.uniqueIdentifiers = uniqueIdentifiers; + this.fbtOperands = fbtOperands; + this.temp = temporaries !== null ? new Map(temporaries) : new Map(); + } + get nextCacheIndex() { + var _a, _b; + return __classPrivateFieldSet(this, _Context_nextCacheIndex, (_b = __classPrivateFieldGet(this, _Context_nextCacheIndex, "f"), _a = _b++, _b), "f"), _a; + } + declare(identifier) { + __classPrivateFieldGet(this, _Context_declarations, "f").add(identifier.declarationId); + } + hasDeclared(identifier) { + return __classPrivateFieldGet(this, _Context_declarations, "f").has(identifier.declarationId); + } + synthesizeName(name) { + const previous = this.synthesizedNames.get(name); + if (previous !== undefined) { + return previous; + } + let validated = makeIdentifierName(name).value; + let index = 0; + while (this.uniqueIdentifiers.has(validated)) { + validated = makeIdentifierName(`${name}${index++}`).value; + } + this.uniqueIdentifiers.add(validated); + this.synthesizedNames.set(name, validated); + return validated; + } +}; +_Context_nextCacheIndex = new WeakMap(), _Context_declarations = new WeakMap(); +function codegenBlock(cx, block) { + const temp = new Map(cx.temp); + const result = codegenBlockNoReset(cx, block); + for (const [key, value] of cx.temp) { + if (!temp.has(key)) { + continue; + } + CompilerError.invariant(temp.get(key) === value, { + loc: null, + reason: 'Expected temporary value to be unchanged', + description: null, + suggestions: null, + }); + } + cx.temp = temp; + return result; +} +function codegenBlockNoReset(cx, block) { + const statements = []; + for (const item of block) { + switch (item.kind) { + case 'instruction': { + const statement = codegenInstructionNullable(cx, item.instruction); + if (statement !== null) { + statements.push(statement); + } + break; + } + case 'pruned-scope': { + const scopeBlock = codegenBlockNoReset(cx, item.instructions); + statements.push(...scopeBlock.body); + break; + } + case 'scope': { + const temp = new Map(cx.temp); + codegenReactiveScope(cx, statements, item.scope, item.instructions); + cx.temp = temp; + break; + } + case 'terminal': { + const statement = codegenTerminal(cx, item.terminal); + if (statement === null) { + break; + } + if (item.label !== null && !item.label.implicit) { + const block = statement.type === 'BlockStatement' && statement.body.length === 1 + ? statement.body[0] + : statement; + statements.push(libExports$1.labeledStatement(libExports$1.identifier(codegenLabel(item.label.id)), block)); + } + else if (statement.type === 'BlockStatement') { + statements.push(...statement.body); + } + else { + statements.push(statement); + } + break; + } + default: { + assertExhaustive$1(item, `Unexpected item kind \`${item.kind}\``); + } + } + } + return libExports$1.blockStatement(statements); +} +function wrapCacheDep(cx, value) { + if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) { + const emitFreezeIdentifier = cx.env.programContext.addImportSpecifier(cx.env.config.enableEmitFreeze).name; + cx.env.programContext + .assertGlobalBinding(EMIT_FREEZE_GLOBAL_GATING, cx.env.scope) + .unwrap(); + return libExports$1.conditionalExpression(libExports$1.identifier(EMIT_FREEZE_GLOBAL_GATING), libExports$1.callExpression(libExports$1.identifier(emitFreezeIdentifier), [ + value, + libExports$1.stringLiteral(cx.fnName), + ]), value); + } + else { + return value; + } +} +function codegenReactiveScope(cx, statements, scope, block) { + const cacheStoreStatements = []; + const cacheLoadStatements = []; + const cacheLoads = []; + const changeExpressions = []; + const changeExpressionComments = []; + const outputComments = []; + for (const dep of [...scope.dependencies].sort(compareScopeDependency)) { + const index = cx.nextCacheIndex; + changeExpressionComments.push(printDependencyComment(dep)); + const comparison = libExports$1.binaryExpression('!==', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), codegenDependency(cx, dep)); + if (cx.env.config.enableChangeVariableCodegen) { + const changeIdentifier = libExports$1.identifier(cx.synthesizeName(`c_${index}`)); + statements.push(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(changeIdentifier, comparison), + ])); + changeExpressions.push(changeIdentifier); + } + else { + changeExpressions.push(comparison); + } + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), codegenDependency(cx, dep)))); + } + let firstOutputIndex = null; + for (const [, { identifier }] of [...scope.declarations].sort(([, a], [, b]) => compareScopeDeclaration(a, b))) { + const index = cx.nextCacheIndex; + if (firstOutputIndex === null) { + firstOutputIndex = index; + } + CompilerError.invariant(identifier.name != null, { + reason: `Expected scope declaration identifier to be named`, + description: `Declaration \`${printIdentifier(identifier)}\` is unnamed in scope @${scope.id}`, + loc: null, + suggestions: null, + }); + const name = convertIdentifier(identifier); + outputComments.push(name.name); + if (!cx.hasDeclared(identifier)) { + statements.push(libExports$1.variableDeclaration('let', [libExports$1.variableDeclarator(name)])); + } + cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) }); + cx.declare(identifier); + } + for (const reassignment of scope.reassignments) { + const index = cx.nextCacheIndex; + if (firstOutputIndex === null) { + firstOutputIndex = index; + } + const name = convertIdentifier(reassignment); + outputComments.push(name.name); + cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) }); + } + let testCondition = changeExpressions.reduce((acc, ident) => { + if (acc == null) { + return ident; + } + return libExports$1.logicalExpression('||', acc, ident); + }, null); + if (testCondition === null) { + CompilerError.invariant(firstOutputIndex !== null, { + reason: `Expected scope to have at least one declaration`, + description: `Scope '@${scope.id}' has no declarations`, + loc: null, + suggestions: null, + }); + testCondition = libExports$1.binaryExpression('===', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(firstOutputIndex), true), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(MEMO_CACHE_SENTINEL)])); + } + if (cx.env.config.disableMemoizationForDebugging) { + CompilerError.invariant(cx.env.config.enableChangeDetectionForDebugging == null, { + reason: `Expected to not have both change detection enabled and memoization disabled`, + description: `Incompatible config options`, + loc: null, + }); + testCondition = libExports$1.logicalExpression('||', testCondition, libExports$1.booleanLiteral(true)); + } + let computationBlock = codegenBlock(cx, block); + let memoStatement; + const detectionFunction = cx.env.config.enableChangeDetectionForDebugging; + if (detectionFunction != null && changeExpressions.length > 0) { + const loc = typeof scope.loc === 'symbol' + ? 'unknown location' + : `(${scope.loc.start.line}:${scope.loc.end.line})`; + const importedDetectionFunctionIdentifier = cx.env.programContext.addImportSpecifier(detectionFunction).name; + const cacheLoadOldValueStatements = []; + const changeDetectionStatements = []; + const idempotenceDetectionStatements = []; + for (const { name, index, value } of cacheLoads) { + const loadName = cx.synthesizeName(`old$${name.name}`); + const slot = libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true); + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', slot, value))); + cacheLoadOldValueStatements.push(libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(loadName), slot), + ])); + changeDetectionStatements.push(libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(importedDetectionFunctionIdentifier), [ + libExports$1.identifier(loadName), + libExports$1.cloneNode(name, true), + libExports$1.stringLiteral(name.name), + libExports$1.stringLiteral(cx.fnName), + libExports$1.stringLiteral('cached'), + libExports$1.stringLiteral(loc), + ]))); + idempotenceDetectionStatements.push(libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(importedDetectionFunctionIdentifier), [ + libExports$1.cloneNode(slot, true), + libExports$1.cloneNode(name, true), + libExports$1.stringLiteral(name.name), + libExports$1.stringLiteral(cx.fnName), + libExports$1.stringLiteral('recomputed'), + libExports$1.stringLiteral(loc), + ]))); + idempotenceDetectionStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', name, slot))); + } + const condition = cx.synthesizeName('condition'); + const recomputationBlock = libExports$1.cloneNode(computationBlock, true); + memoStatement = libExports$1.blockStatement([ + ...computationBlock.body, + libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(condition), testCondition), + ]), + libExports$1.ifStatement(libExports$1.unaryExpression('!', libExports$1.identifier(condition)), libExports$1.blockStatement([ + ...cacheLoadOldValueStatements, + ...changeDetectionStatements, + ])), + ...cacheStoreStatements, + libExports$1.ifStatement(libExports$1.identifier(condition), libExports$1.blockStatement([ + ...recomputationBlock.body, + ...idempotenceDetectionStatements, + ])), + ]); + } + else { + for (const { name, index, value } of cacheLoads) { + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), value))); + cacheLoadStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', name, libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true)))); + } + computationBlock.body.push(...cacheStoreStatements); + memoStatement = libExports$1.ifStatement(testCondition, computationBlock, libExports$1.blockStatement(cacheLoadStatements)); + } + if (cx.env.config.enableMemoizationComments) { + if (changeExpressionComments.length) { + libExports$1.addComment(memoStatement, 'leading', ` check if ${printDelimitedCommentList(changeExpressionComments, 'or')} changed`, true); + libExports$1.addComment(memoStatement, 'leading', ` "useMemo" for ${printDelimitedCommentList(outputComments, 'and')}:`, true); + } + else { + libExports$1.addComment(memoStatement, 'leading', ' cache value with no dependencies', true); + libExports$1.addComment(memoStatement, 'leading', ` "useMemo" for ${printDelimitedCommentList(outputComments, 'and')}:`, true); + } + if (computationBlock.body.length > 0) { + libExports$1.addComment(computationBlock.body[0], 'leading', ` Inputs changed, recompute`, true); + } + if (cacheLoadStatements.length > 0) { + libExports$1.addComment(cacheLoadStatements[0], 'leading', ` Inputs did not change, use cached value`, true); + } + } + statements.push(memoStatement); + const earlyReturnValue = scope.earlyReturnValue; + if (earlyReturnValue !== null) { + CompilerError.invariant(earlyReturnValue.value.name !== null && + earlyReturnValue.value.name.kind === 'named', { + reason: `Expected early return value to be promoted to a named variable`, + loc: earlyReturnValue.loc, + description: null, + suggestions: null, + }); + const name = earlyReturnValue.value.name.value; + statements.push(libExports$1.ifStatement(libExports$1.binaryExpression('!==', libExports$1.identifier(name), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(EARLY_RETURN_SENTINEL)])), libExports$1.blockStatement([libExports$1.returnStatement(libExports$1.identifier(name))]))); + } +} +function codegenTerminal(cx, terminal) { + switch (terminal.kind) { + case 'break': { + if (terminal.targetKind === 'implicit') { + return null; + } + return libExports$1.breakStatement(terminal.targetKind === 'labeled' + ? libExports$1.identifier(codegenLabel(terminal.target)) + : null); + } + case 'continue': { + if (terminal.targetKind === 'implicit') { + return null; + } + return libExports$1.continueStatement(terminal.targetKind === 'labeled' + ? libExports$1.identifier(codegenLabel(terminal.target)) + : null); + } + case 'for': { + return libExports$1.forStatement(codegenForInit(cx, terminal.init), codegenInstructionValueToExpression(cx, terminal.test), terminal.update !== null + ? codegenInstructionValueToExpression(cx, terminal.update) + : null, codegenBlock(cx, terminal.loop)); + } + case 'for-in': { + CompilerError.invariant(terminal.init.kind === 'SequenceExpression', { + reason: `Expected a sequence expression init for for..in`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.init.loc, + suggestions: null, + }); + if (terminal.init.instructions.length !== 2) { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..in inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + const iterableCollection = terminal.init.instructions[0]; + const iterableItem = terminal.init.instructions[1]; + let lval; + switch (iterableItem.value.kind) { + case 'StoreLocal': { + lval = codegenLValue(cx, iterableItem.value.lvalue.place); + break; + } + case 'Destructure': { + lval = codegenLValue(cx, iterableItem.value.lvalue.pattern); + break; + } + case 'StoreContext': { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..in inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + default: + CompilerError.invariant(false, { + reason: `Expected a StoreLocal or Destructure to be assigned to the collection`, + description: `Found ${iterableItem.value.kind}`, + loc: iterableItem.value.loc, + suggestions: null, + }); + } + let varDeclKind; + switch (iterableItem.value.lvalue.kind) { + case InstructionKind.Const: + varDeclKind = 'const'; + break; + case InstructionKind.Let: + varDeclKind = 'let'; + break; + case InstructionKind.Reassign: + CompilerError.invariant(false, { + reason: 'Destructure should never be Reassign as it would be an Object/ArrayPattern', + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + case InstructionKind.Catch: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedLet: + case InstructionKind.HoistedFunction: + case InstructionKind.Function: + CompilerError.invariant(false, { + reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..in collection`, + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + default: + assertExhaustive$1(iterableItem.value.lvalue.kind, `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`); + } + return libExports$1.forInStatement(createVariableDeclaration(iterableItem.value.loc, varDeclKind, [ + libExports$1.variableDeclarator(lval, null), + ]), codegenInstructionValueToExpression(cx, iterableCollection.value), codegenBlock(cx, terminal.loop)); + } + case 'for-of': { + CompilerError.invariant(terminal.init.kind === 'SequenceExpression' && + terminal.init.instructions.length === 1 && + terminal.init.instructions[0].value.kind === 'GetIterator', { + reason: `Expected a single-expression sequence expression init for for..of`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.init.loc, + suggestions: null, + }); + const iterableCollection = terminal.init.instructions[0].value; + CompilerError.invariant(terminal.test.kind === 'SequenceExpression', { + reason: `Expected a sequence expression test for for..of`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.test.loc, + suggestions: null, + }); + if (terminal.test.instructions.length !== 2) { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..of inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + const iterableItem = terminal.test.instructions[1]; + let lval; + switch (iterableItem.value.kind) { + case 'StoreLocal': { + lval = codegenLValue(cx, iterableItem.value.lvalue.place); + break; + } + case 'Destructure': { + lval = codegenLValue(cx, iterableItem.value.lvalue.pattern); + break; + } + case 'StoreContext': { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..of inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + default: + CompilerError.invariant(false, { + reason: `Expected a StoreLocal or Destructure to be assigned to the collection`, + description: `Found ${iterableItem.value.kind}`, + loc: iterableItem.value.loc, + suggestions: null, + }); + } + let varDeclKind; + switch (iterableItem.value.lvalue.kind) { + case InstructionKind.Const: + varDeclKind = 'const'; + break; + case InstructionKind.Let: + varDeclKind = 'let'; + break; + case InstructionKind.Reassign: + case InstructionKind.Catch: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedLet: + case InstructionKind.HoistedFunction: + case InstructionKind.Function: + CompilerError.invariant(false, { + reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..of collection`, + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + default: + assertExhaustive$1(iterableItem.value.lvalue.kind, `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`); + } + return libExports$1.forOfStatement(createVariableDeclaration(iterableItem.value.loc, varDeclKind, [ + libExports$1.variableDeclarator(lval, null), + ]), codegenInstructionValueToExpression(cx, iterableCollection), codegenBlock(cx, terminal.loop)); + } + case 'if': { + const test = codegenPlaceToExpression(cx, terminal.test); + const consequent = codegenBlock(cx, terminal.consequent); + let alternate = null; + if (terminal.alternate !== null) { + const block = codegenBlock(cx, terminal.alternate); + if (block.body.length !== 0) { + alternate = block; + } + } + return libExports$1.ifStatement(test, consequent, alternate); + } + case 'return': { + const value = codegenPlaceToExpression(cx, terminal.value); + if (value.type === 'Identifier' && value.name === 'undefined') { + return libExports$1.returnStatement(); + } + return libExports$1.returnStatement(value); + } + case 'switch': { + return libExports$1.switchStatement(codegenPlaceToExpression(cx, terminal.test), terminal.cases.map(case_ => { + const test = case_.test !== null + ? codegenPlaceToExpression(cx, case_.test) + : null; + const block = codegenBlock(cx, case_.block); + return libExports$1.switchCase(test, [block]); + })); + } + case 'throw': { + return libExports$1.throwStatement(codegenPlaceToExpression(cx, terminal.value)); + } + case 'do-while': { + const test = codegenInstructionValueToExpression(cx, terminal.test); + return libExports$1.doWhileStatement(test, codegenBlock(cx, terminal.loop)); + } + case 'while': { + const test = codegenInstructionValueToExpression(cx, terminal.test); + return libExports$1.whileStatement(test, codegenBlock(cx, terminal.loop)); + } + case 'label': { + return codegenBlock(cx, terminal.block); + } + case 'try': { + let catchParam = null; + if (terminal.handlerBinding !== null) { + catchParam = convertIdentifier(terminal.handlerBinding.identifier); + cx.temp.set(terminal.handlerBinding.identifier.declarationId, null); + } + return libExports$1.tryStatement(codegenBlock(cx, terminal.block), libExports$1.catchClause(catchParam, codegenBlock(cx, terminal.handler))); + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } +} +function codegenInstructionNullable(cx, instr) { + if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext' || + instr.value.kind === 'Destructure' || + instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + let kind = instr.value.lvalue.kind; + let lvalue; + let value; + if (instr.value.kind === 'StoreLocal') { + kind = cx.hasDeclared(instr.value.lvalue.place.identifier) + ? InstructionKind.Reassign + : kind; + lvalue = instr.value.lvalue.place; + value = codegenPlaceToExpression(cx, instr.value.value); + } + else if (instr.value.kind === 'StoreContext') { + lvalue = instr.value.lvalue.place; + value = codegenPlaceToExpression(cx, instr.value.value); + } + else if (instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + if (cx.hasDeclared(instr.value.lvalue.place.identifier)) { + return null; + } + kind = instr.value.lvalue.kind; + lvalue = instr.value.lvalue.place; + value = null; + } + else { + lvalue = instr.value.lvalue.pattern; + let hasReassign = false; + let hasDeclaration = false; + for (const place of eachPatternOperand(lvalue)) { + if (kind !== InstructionKind.Reassign && + place.identifier.name === null) { + cx.temp.set(place.identifier.declarationId, null); + } + const isDeclared = cx.hasDeclared(place.identifier); + hasReassign || (hasReassign = isDeclared); + hasDeclaration || (hasDeclaration = !isDeclared); + } + if (hasReassign && hasDeclaration) { + CompilerError.invariant(false, { + reason: 'Encountered a destructuring operation where some identifiers are already declared (reassignments) but others are not (declarations)', + description: null, + loc: instr.loc, + suggestions: null, + }); + } + else if (hasReassign) { + kind = InstructionKind.Reassign; + } + value = codegenPlaceToExpression(cx, instr.value.value); + } + switch (kind) { + case InstructionKind.Const: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Const declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createVariableDeclaration(instr.loc, 'const', [ + libExports$1.variableDeclarator(codegenLValue(cx, lvalue), value), + ]); + } + case InstructionKind.Function: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Function declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + const genLvalue = codegenLValue(cx, lvalue); + CompilerError.invariant(genLvalue.type === 'Identifier', { + reason: 'Expected an identifier as a function declaration lvalue', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + CompilerError.invariant((value === null || value === void 0 ? void 0 : value.type) === 'FunctionExpression', { + reason: 'Expected a function as a function declaration value', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createFunctionDeclaration(instr.loc, genLvalue, value.params, value.body, value.generator, value.async); + } + case InstructionKind.Let: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Const declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createVariableDeclaration(instr.loc, 'let', [ + libExports$1.variableDeclarator(codegenLValue(cx, lvalue), value), + ]); + } + case InstructionKind.Reassign: { + CompilerError.invariant(value !== null, { + reason: 'Expected a value for reassignment', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + const expr = libExports$1.assignmentExpression('=', codegenLValue(cx, lvalue), value); + if (instr.lvalue !== null) { + if (instr.value.kind !== 'StoreContext') { + cx.temp.set(instr.lvalue.identifier.declarationId, expr); + return null; + } + else { + const statement = codegenInstruction(cx, instr, expr); + if (statement.type === 'EmptyStatement') { + return null; + } + return statement; + } + } + else { + return createExpressionStatement(instr.loc, expr); + } + } + case InstructionKind.Catch: { + return libExports$1.emptyStatement(); + } + case InstructionKind.HoistedLet: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedFunction: { + CompilerError.invariant(false, { + reason: `Expected ${kind} to have been pruned in PruneHoistedContexts`, + description: null, + loc: instr.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(kind, `Unexpected instruction kind \`${kind}\``); + } + } + } + else if (instr.value.kind === 'StartMemoize' || + instr.value.kind === 'FinishMemoize') { + return null; + } + else if (instr.value.kind === 'Debugger') { + return libExports$1.debuggerStatement(); + } + else if (instr.value.kind === 'ObjectMethod') { + CompilerError.invariant(instr.lvalue, { + reason: 'Expected object methods to have a temp lvalue', + loc: null, + suggestions: null, + }); + cx.objectMethods.set(instr.lvalue.identifier.id, instr.value); + return null; + } + else { + const value = codegenInstructionValue(cx, instr.value); + const statement = codegenInstruction(cx, instr, value); + if (statement.type === 'EmptyStatement') { + return null; + } + return statement; + } +} +function codegenForInit(cx, init) { + if (init.kind === 'SequenceExpression') { + const body = codegenBlock(cx, init.instructions.map(instruction => ({ + kind: 'instruction', + instruction, + }))).body; + const declarators = []; + let kind = 'const'; + body.forEach(instr => { + var _a; + let top = undefined; + if (instr.type === 'ExpressionStatement' && + instr.expression.type === 'AssignmentExpression' && + instr.expression.operator === '=' && + instr.expression.left.type === 'Identifier' && + ((_a = (top = declarators.at(-1))) === null || _a === void 0 ? void 0 : _a.id.type) === 'Identifier' && + (top === null || top === void 0 ? void 0 : top.id.name) === instr.expression.left.name && + (top === null || top === void 0 ? void 0 : top.init) == null) { + top.init = instr.expression.right; + } + else { + CompilerError.invariant(instr.type === 'VariableDeclaration' && + (instr.kind === 'let' || instr.kind === 'const'), { + reason: 'Expected a variable declaration', + loc: init.loc, + description: `Got ${instr.type}`, + suggestions: null, + }); + if (instr.kind === 'let') { + kind = 'let'; + } + declarators.push(...instr.declarations); + } + }); + CompilerError.invariant(declarators.length > 0, { + reason: 'Expected a variable declaration', + loc: init.loc, + description: null, + suggestions: null, + }); + return libExports$1.variableDeclaration(kind, declarators); + } + else { + return codegenInstructionValueToExpression(cx, init); + } +} +function printDependencyComment(dependency) { + const identifier = convertIdentifier(dependency.identifier); + let name = identifier.name; + if (dependency.path !== null) { + for (const path of dependency.path) { + name += `.${path.property}`; + } + } + return name; +} +function printDelimitedCommentList(items, finalCompletion) { + if (items.length === 2) { + return items.join(` ${finalCompletion} `); + } + else if (items.length <= 1) { + return items.join(''); + } + let output = []; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (i < items.length - 2) { + output.push(`${item}, `); + } + else if (i === items.length - 2) { + output.push(`${item}, ${finalCompletion} `); + } + else { + output.push(item); + } + } + return output.join(''); +} +function codegenDependency(cx, dependency) { + let object = convertIdentifier(dependency.identifier); + if (dependency.path.length !== 0) { + const hasOptional = dependency.path.some(path => path.optional); + for (const path of dependency.path) { + const property = typeof path.property === 'string' + ? libExports$1.identifier(path.property) + : libExports$1.numericLiteral(path.property); + const isComputed = typeof path.property !== 'string'; + if (hasOptional) { + object = libExports$1.optionalMemberExpression(object, property, isComputed, path.optional); + } + else { + object = libExports$1.memberExpression(object, property, isComputed); + } + } + } + return object; +} +function withLoc(fn) { + return (loc, ...args) => { + const node = fn(...args); + if (loc != null && loc != GeneratedSource) { + node.loc = loc; + } + return node; + }; +} +const createBinaryExpression = withLoc(libExports$1.binaryExpression); +const createExpressionStatement = withLoc(libExports$1.expressionStatement); +const createVariableDeclaration = withLoc(libExports$1.variableDeclaration); +const createFunctionDeclaration = withLoc(libExports$1.functionDeclaration); +const createTaggedTemplateExpression = withLoc(libExports$1.taggedTemplateExpression); +const createLogicalExpression = withLoc(libExports$1.logicalExpression); +const createSequenceExpression = withLoc(libExports$1.sequenceExpression); +const createConditionalExpression = withLoc(libExports$1.conditionalExpression); +const createTemplateLiteral = withLoc(libExports$1.templateLiteral); +const createJsxNamespacedName = withLoc(libExports$1.jsxNamespacedName); +const createJsxElement = withLoc(libExports$1.jsxElement); +const createJsxAttribute = withLoc(libExports$1.jsxAttribute); +const createJsxIdentifier = withLoc(libExports$1.jsxIdentifier); +const createJsxExpressionContainer = withLoc(libExports$1.jsxExpressionContainer); +const createJsxText = withLoc(libExports$1.jsxText); +const createJsxClosingElement = withLoc(libExports$1.jsxClosingElement); +const createJsxOpeningElement = withLoc(libExports$1.jsxOpeningElement); +const createStringLiteral = withLoc(libExports$1.stringLiteral); +function createHookGuard(guard, context, stmts, before, after) { + const guardFnName = context.addImportSpecifier(guard).name; + function createHookGuardImpl(kind) { + return libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(guardFnName), [libExports$1.numericLiteral(kind)])); + } + return libExports$1.tryStatement(libExports$1.blockStatement([createHookGuardImpl(before), ...stmts]), null, libExports$1.blockStatement([createHookGuardImpl(after)])); +} +function createCallExpression(env, callee, args, loc, isHook) { + const callExpr = libExports$1.callExpression(callee, args); + if (loc != null && loc != GeneratedSource) { + callExpr.loc = loc; + } + const hookGuard = env.config.enableEmitHookGuards; + if (hookGuard != null && isHook && env.isInferredMemoEnabled) { + const iife = libExports$1.functionExpression(null, [], libExports$1.blockStatement([ + createHookGuard(hookGuard, env.programContext, [libExports$1.returnStatement(callExpr)], GuardKind.AllowHook, GuardKind.DisallowHook), + ])); + return libExports$1.callExpression(iife, []); + } + else { + return callExpr; + } +} +function codegenLabel(id) { + return `bb${id}`; +} +function codegenInstruction(cx, instr, value) { + if (libExports$1.isStatement(value)) { + return value; + } + if (instr.lvalue === null) { + return libExports$1.expressionStatement(convertValueToExpression(value)); + } + if (instr.lvalue.identifier.name === null) { + cx.temp.set(instr.lvalue.identifier.declarationId, value); + return libExports$1.emptyStatement(); + } + else { + const expressionValue = convertValueToExpression(value); + if (cx.hasDeclared(instr.lvalue.identifier)) { + return createExpressionStatement(instr.loc, libExports$1.assignmentExpression('=', convertIdentifier(instr.lvalue.identifier), expressionValue)); + } + else { + return createVariableDeclaration(instr.loc, 'const', [ + libExports$1.variableDeclarator(convertIdentifier(instr.lvalue.identifier), expressionValue), + ]); + } + } +} +function convertValueToExpression(value) { + if (value.type === 'JSXText') { + return createStringLiteral(value.loc, value.value); + } + return value; +} +function codegenInstructionValueToExpression(cx, instrValue) { + const value = codegenInstructionValue(cx, instrValue); + return convertValueToExpression(value); +} +function codegenInstructionValue(cx, instrValue) { + var _a, _b, _c, _d, _e, _f, _g, _h; + let value; + switch (instrValue.kind) { + case 'ArrayExpression': { + const elements = instrValue.elements.map(element => { + if (element.kind === 'Identifier') { + return codegenPlaceToExpression(cx, element); + } + else if (element.kind === 'Spread') { + return libExports$1.spreadElement(codegenPlaceToExpression(cx, element.place)); + } + else { + return null; + } + }); + value = libExports$1.arrayExpression(elements); + break; + } + case 'BinaryExpression': { + const left = codegenPlaceToExpression(cx, instrValue.left); + const right = codegenPlaceToExpression(cx, instrValue.right); + value = createBinaryExpression(instrValue.loc, instrValue.operator, left, right); + break; + } + case 'UnaryExpression': { + value = libExports$1.unaryExpression(instrValue.operator, codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'Primitive': { + value = codegenValue(cx, instrValue.loc, instrValue.value); + break; + } + case 'CallExpression': { + if (cx.env.config.enableForest) { + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = libExports$1.callExpression(callee, args); + if (instrValue.typeArguments != null) { + value.typeArguments = libExports$1.typeParameterInstantiation(instrValue.typeArguments); + } + break; + } + const isHook = getHookKind(cx.env, instrValue.callee.identifier) != null; + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = createCallExpression(cx.env, callee, args, instrValue.loc, isHook); + break; + } + case 'OptionalExpression': { + const optionalValue = codegenInstructionValueToExpression(cx, instrValue.value); + switch (optionalValue.type) { + case 'OptionalCallExpression': + case 'CallExpression': { + CompilerError.invariant(libExports$1.isExpression(optionalValue.callee), { + reason: 'v8 intrinsics are validated during lowering', + description: null, + loc: (_a = optionalValue.callee.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + value = libExports$1.optionalCallExpression(optionalValue.callee, optionalValue.arguments, instrValue.optional); + break; + } + case 'OptionalMemberExpression': + case 'MemberExpression': { + const property = optionalValue.property; + CompilerError.invariant(libExports$1.isExpression(property), { + reason: 'Private names are validated during lowering', + description: null, + loc: (_b = property.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + value = libExports$1.optionalMemberExpression(optionalValue.object, property, optionalValue.computed, instrValue.optional); + break; + } + default: { + CompilerError.invariant(false, { + reason: 'Expected an optional value to resolve to a call expression or member expression', + description: `Got a \`${optionalValue.type}\``, + loc: instrValue.loc, + suggestions: null, + }); + } + } + break; + } + case 'MethodCall': { + const isHook = getHookKind(cx.env, instrValue.property.identifier) != null; + const memberExpr = codegenPlaceToExpression(cx, instrValue.property); + CompilerError.invariant(libExports$1.isMemberExpression(memberExpr) || + libExports$1.isOptionalMemberExpression(memberExpr), { + reason: '[Codegen] Internal error: MethodCall::property must be an unpromoted + unmemoized MemberExpression. ' + + `Got a \`${memberExpr.type}\``, + description: null, + loc: (_c = memberExpr.loc) !== null && _c !== void 0 ? _c : null, + suggestions: null, + }); + CompilerError.invariant(libExports$1.isNodesEquivalent(memberExpr.object, codegenPlaceToExpression(cx, instrValue.receiver)), { + reason: '[Codegen] Internal error: Forget should always generate MethodCall::property ' + + 'as a MemberExpression of MethodCall::receiver', + description: null, + loc: (_d = memberExpr.loc) !== null && _d !== void 0 ? _d : null, + suggestions: null, + }); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = createCallExpression(cx.env, memberExpr, args, instrValue.loc, isHook); + break; + } + case 'NewExpression': { + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = libExports$1.newExpression(callee, args); + break; + } + case 'ObjectExpression': { + const properties = []; + for (const property of instrValue.properties) { + if (property.kind === 'ObjectProperty') { + const key = codegenObjectPropertyKey(cx, property.key); + switch (property.type) { + case 'property': { + const value = codegenPlaceToExpression(cx, property.place); + properties.push(libExports$1.objectProperty(key, value, property.key.kind === 'computed', key.type === 'Identifier' && + value.type === 'Identifier' && + value.name === key.name)); + break; + } + case 'method': { + const method = cx.objectMethods.get(property.place.identifier.id); + CompilerError.invariant(method, { + reason: 'Expected ObjectMethod instruction', + loc: null, + suggestions: null, + }); + const loweredFunc = method.loweredFunc; + const reactiveFunction = buildReactiveFunction(loweredFunc.func); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + const fn = codegenReactiveFunction(new Context$1(cx.env, (_e = reactiveFunction.id) !== null && _e !== void 0 ? _e : '[[ anonymous ]]', cx.uniqueIdentifiers, cx.fbtOperands, cx.temp), reactiveFunction).unwrap(); + const babelNode = libExports$1.objectMethod('method', key, fn.params, fn.body, false); + babelNode.async = fn.async; + babelNode.generator = fn.generator; + properties.push(babelNode); + break; + } + default: + assertExhaustive$1(property.type, `Unexpected property type: ${property.type}`); + } + } + else { + properties.push(libExports$1.spreadElement(codegenPlaceToExpression(cx, property.place))); + } + } + value = libExports$1.objectExpression(properties); + break; + } + case 'JSXText': { + value = createJsxText(instrValue.loc, instrValue.value); + break; + } + case 'JsxExpression': { + const attributes = []; + for (const attribute of instrValue.props) { + attributes.push(codegenJsxAttribute(cx, attribute)); + } + let tagValue = instrValue.tag.kind === 'Identifier' + ? codegenPlaceToExpression(cx, instrValue.tag) + : libExports$1.stringLiteral(instrValue.tag.name); + let tag; + if (tagValue.type === 'Identifier') { + tag = createJsxIdentifier(instrValue.tag.loc, tagValue.name); + } + else if (tagValue.type === 'MemberExpression') { + tag = convertMemberExpressionToJsx(tagValue); + } + else { + CompilerError.invariant(tagValue.type === 'StringLiteral', { + reason: `Expected JSX tag to be an identifier or string, got \`${tagValue.type}\``, + description: null, + loc: (_f = tagValue.loc) !== null && _f !== void 0 ? _f : null, + suggestions: null, + }); + if (tagValue.value.indexOf(':') >= 0) { + const [namespace, name] = tagValue.value.split(':', 2); + tag = createJsxNamespacedName(instrValue.tag.loc, createJsxIdentifier(instrValue.tag.loc, namespace), createJsxIdentifier(instrValue.tag.loc, name)); + } + else { + tag = createJsxIdentifier(instrValue.loc, tagValue.value); + } + } + let children; + if (tagValue.type === 'StringLiteral' && + SINGLE_CHILD_FBT_TAGS.has(tagValue.value)) { + CompilerError.invariant(instrValue.children != null, { + loc: instrValue.loc, + reason: 'Expected fbt element to have children', + suggestions: null, + description: null, + }); + children = instrValue.children.map(child => codegenJsxFbtChildElement(cx, child)); + } + else { + children = + instrValue.children !== null + ? instrValue.children.map(child => codegenJsxElement(cx, child)) + : []; + } + value = createJsxElement(instrValue.loc, createJsxOpeningElement(instrValue.openingLoc, tag, attributes, instrValue.children === null), instrValue.children !== null + ? createJsxClosingElement(instrValue.closingLoc, tag) + : null, children, instrValue.children === null); + break; + } + case 'JsxFragment': { + value = libExports$1.jsxFragment(libExports$1.jsxOpeningFragment(), libExports$1.jsxClosingFragment(), instrValue.children.map(child => codegenJsxElement(cx, child))); + break; + } + case 'UnsupportedNode': { + const node = instrValue.node; + if (!libExports$1.isExpression(node)) { + return node; + } + value = node; + break; + } + case 'PropertyStore': + case 'PropertyLoad': + case 'PropertyDelete': { + let memberExpr; + if (typeof instrValue.property === 'string') { + memberExpr = libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), libExports$1.identifier(instrValue.property)); + } + else { + memberExpr = libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), libExports$1.numericLiteral(instrValue.property), true); + } + if (instrValue.kind === 'PropertyStore') { + value = libExports$1.assignmentExpression('=', memberExpr, codegenPlaceToExpression(cx, instrValue.value)); + } + else if (instrValue.kind === 'PropertyLoad') { + value = memberExpr; + } + else { + value = libExports$1.unaryExpression('delete', memberExpr); + } + break; + } + case 'ComputedStore': { + value = libExports$1.assignmentExpression('=', libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), codegenPlaceToExpression(cx, instrValue.property), true), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'ComputedLoad': { + const object = codegenPlaceToExpression(cx, instrValue.object); + const property = codegenPlaceToExpression(cx, instrValue.property); + value = libExports$1.memberExpression(object, property, true); + break; + } + case 'ComputedDelete': { + value = libExports$1.unaryExpression('delete', libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), codegenPlaceToExpression(cx, instrValue.property), true)); + break; + } + case 'LoadLocal': + case 'LoadContext': { + value = codegenPlaceToExpression(cx, instrValue.place); + break; + } + case 'FunctionExpression': { + const loweredFunc = instrValue.loweredFunc.func; + const reactiveFunction = buildReactiveFunction(loweredFunc); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + pruneHoistedContexts(reactiveFunction); + const fn = codegenReactiveFunction(new Context$1(cx.env, (_g = reactiveFunction.id) !== null && _g !== void 0 ? _g : '[[ anonymous ]]', cx.uniqueIdentifiers, cx.fbtOperands, cx.temp), reactiveFunction).unwrap(); + if (instrValue.type === 'ArrowFunctionExpression') { + let body = fn.body; + if (body.body.length === 1 && loweredFunc.directives.length == 0) { + const stmt = body.body[0]; + if (stmt.type === 'ReturnStatement' && stmt.argument != null) { + body = stmt.argument; + } + } + value = libExports$1.arrowFunctionExpression(fn.params, body, fn.async); + } + else { + value = libExports$1.functionExpression((_h = fn.id) !== null && _h !== void 0 ? _h : (instrValue.name != null ? libExports$1.identifier(instrValue.name) : null), fn.params, fn.body, fn.generator, fn.async); + } + break; + } + case 'TaggedTemplateExpression': { + value = createTaggedTemplateExpression(instrValue.loc, codegenPlaceToExpression(cx, instrValue.tag), libExports$1.templateLiteral([libExports$1.templateElement(instrValue.value)], [])); + break; + } + case 'TypeCastExpression': { + if (libExports$1.isTSType(instrValue.typeAnnotation)) { + if (instrValue.typeAnnotationKind === 'satisfies') { + value = libExports$1.tsSatisfiesExpression(codegenPlaceToExpression(cx, instrValue.value), instrValue.typeAnnotation); + } + else { + value = libExports$1.tsAsExpression(codegenPlaceToExpression(cx, instrValue.value), instrValue.typeAnnotation); + } + } + else { + value = libExports$1.typeCastExpression(codegenPlaceToExpression(cx, instrValue.value), libExports$1.typeAnnotation(instrValue.typeAnnotation)); + } + break; + } + case 'LogicalExpression': { + value = createLogicalExpression(instrValue.loc, instrValue.operator, codegenInstructionValueToExpression(cx, instrValue.left), codegenInstructionValueToExpression(cx, instrValue.right)); + break; + } + case 'ConditionalExpression': { + value = createConditionalExpression(instrValue.loc, codegenInstructionValueToExpression(cx, instrValue.test), codegenInstructionValueToExpression(cx, instrValue.consequent), codegenInstructionValueToExpression(cx, instrValue.alternate)); + break; + } + case 'SequenceExpression': { + const body = codegenBlockNoReset(cx, instrValue.instructions.map(instruction => ({ + kind: 'instruction', + instruction, + }))).body; + const expressions = body.map(stmt => { + var _a, _b; + if (stmt.type === 'ExpressionStatement') { + return stmt.expression; + } + else { + if (libExports$1.isVariableDeclaration(stmt)) { + const declarator = stmt.declarations[0]; + cx.errors.push({ + reason: `(CodegenReactiveFunction::codegenInstructionValue) Cannot declare variables in a value block, tried to declare '${declarator.id.name}'`, + severity: ErrorSeverity.Todo, + loc: (_a = declarator.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + return libExports$1.stringLiteral(`TODO handle ${declarator.id}`); + } + else { + cx.errors.push({ + reason: `(CodegenReactiveFunction::codegenInstructionValue) Handle conversion of ${stmt.type} to expression`, + severity: ErrorSeverity.Todo, + loc: (_b = stmt.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + return libExports$1.stringLiteral(`TODO handle ${stmt.type}`); + } + } + }); + if (expressions.length === 0) { + value = codegenInstructionValueToExpression(cx, instrValue.value); + } + else { + value = createSequenceExpression(instrValue.loc, [ + ...expressions, + codegenInstructionValueToExpression(cx, instrValue.value), + ]); + } + break; + } + case 'TemplateLiteral': { + value = createTemplateLiteral(instrValue.loc, instrValue.quasis.map(q => libExports$1.templateElement(q)), instrValue.subexprs.map(p => codegenPlaceToExpression(cx, p))); + break; + } + case 'LoadGlobal': { + value = libExports$1.identifier(instrValue.binding.name); + break; + } + case 'RegExpLiteral': { + value = libExports$1.regExpLiteral(instrValue.pattern, instrValue.flags); + break; + } + case 'MetaProperty': { + value = libExports$1.metaProperty(libExports$1.identifier(instrValue.meta), libExports$1.identifier(instrValue.property)); + break; + } + case 'Await': { + value = libExports$1.awaitExpression(codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'GetIterator': { + value = codegenPlaceToExpression(cx, instrValue.collection); + break; + } + case 'IteratorNext': { + value = codegenPlaceToExpression(cx, instrValue.iterator); + break; + } + case 'NextPropertyOf': { + value = codegenPlaceToExpression(cx, instrValue.value); + break; + } + case 'PostfixUpdate': { + value = libExports$1.updateExpression(instrValue.operation, codegenPlaceToExpression(cx, instrValue.lvalue), false); + break; + } + case 'PrefixUpdate': { + value = libExports$1.updateExpression(instrValue.operation, codegenPlaceToExpression(cx, instrValue.lvalue), true); + break; + } + case 'StoreLocal': { + CompilerError.invariant(instrValue.lvalue.kind === InstructionKind.Reassign, { + reason: `Unexpected StoreLocal in codegenInstructionValue`, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + value = libExports$1.assignmentExpression('=', codegenLValue(cx, instrValue.lvalue.place), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'StoreGlobal': { + value = libExports$1.assignmentExpression('=', libExports$1.identifier(instrValue.name), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'StartMemoize': + case 'FinishMemoize': + case 'Debugger': + case 'DeclareLocal': + case 'DeclareContext': + case 'Destructure': + case 'ObjectMethod': + case 'StoreContext': { + CompilerError.invariant(false, { + reason: `Unexpected ${instrValue.kind} in codegenInstructionValue`, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(instrValue, `Unexpected instruction value kind \`${instrValue.kind}\``); + } + } + return value; +} +const STRING_REQUIRES_EXPR_CONTAINER_PATTERN = /[\u{0000}-\u{001F}\u{007F}\u{0080}-\u{FFFF}]|"|\\/u; +function codegenJsxAttribute(cx, attribute) { + switch (attribute.kind) { + case 'JsxAttribute': { + let propName; + if (attribute.name.indexOf(':') === -1) { + propName = createJsxIdentifier(attribute.place.loc, attribute.name); + } + else { + const [namespace, name] = attribute.name.split(':', 2); + propName = createJsxNamespacedName(attribute.place.loc, createJsxIdentifier(attribute.place.loc, namespace), createJsxIdentifier(attribute.place.loc, name)); + } + const innerValue = codegenPlaceToExpression(cx, attribute.place); + let value; + switch (innerValue.type) { + case 'StringLiteral': { + value = innerValue; + if (STRING_REQUIRES_EXPR_CONTAINER_PATTERN.test(value.value) && + !cx.fbtOperands.has(attribute.place.identifier.id)) { + value = createJsxExpressionContainer(value.loc, value); + } + break; + } + default: { + value = createJsxExpressionContainer(attribute.place.loc, innerValue); + break; + } + } + return createJsxAttribute(attribute.place.loc, propName, value); + } + case 'JsxSpreadAttribute': { + return libExports$1.jsxSpreadAttribute(codegenPlaceToExpression(cx, attribute.argument)); + } + default: { + assertExhaustive$1(attribute, `Unexpected attribute kind \`${attribute.kind}\``); + } + } +} +const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/; +function codegenJsxElement(cx, place) { + const value = codegenPlace(cx, place); + switch (value.type) { + case 'JSXText': { + if (JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN.test(value.value)) { + return createJsxExpressionContainer(place.loc, createStringLiteral(place.loc, value.value)); + } + return createJsxText(place.loc, value.value); + } + case 'JSXElement': + case 'JSXFragment': { + return value; + } + default: { + return createJsxExpressionContainer(place.loc, value); + } + } +} +function codegenJsxFbtChildElement(cx, place) { + const value = codegenPlace(cx, place); + switch (value.type) { + case 'JSXText': + case 'JSXElement': { + return value; + } + default: { + return createJsxExpressionContainer(place.loc, value); + } + } +} +function convertMemberExpressionToJsx(expr) { + var _a, _b; + CompilerError.invariant(expr.property.type === 'Identifier', { + reason: 'Expected JSX member expression property to be a string', + description: null, + loc: (_a = expr.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + const property = libExports$1.jsxIdentifier(expr.property.name); + if (expr.object.type === 'Identifier') { + return libExports$1.jsxMemberExpression(libExports$1.jsxIdentifier(expr.object.name), property); + } + else { + CompilerError.invariant(expr.object.type === 'MemberExpression', { + reason: 'Expected JSX member expression to be an identifier or nested member expression', + description: null, + loc: (_b = expr.object.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + const object = convertMemberExpressionToJsx(expr.object); + return libExports$1.jsxMemberExpression(object, property); + } +} +function codegenObjectPropertyKey(cx, key) { + switch (key.kind) { + case 'string': { + return libExports$1.stringLiteral(key.name); + } + case 'identifier': { + return libExports$1.identifier(key.name); + } + case 'computed': { + const expr = codegenPlace(cx, key.name); + CompilerError.invariant(libExports$1.isExpression(expr), { + reason: 'Expected object property key to be an expression', + description: null, + loc: key.name.loc, + suggestions: null, + }); + return expr; + } + case 'number': { + return libExports$1.numericLiteral(key.name); + } + } +} +function codegenArrayPattern(cx, pattern) { + const hasHoles = !pattern.items.every(e => e.kind !== 'Hole'); + if (hasHoles) { + const result = libExports$1.arrayPattern([]); + for (const item of pattern.items) { + if (item.kind === 'Hole') { + result.elements.push(null); + } + else { + result.elements.push(codegenLValue(cx, item)); + } + } + return result; + } + else { + return libExports$1.arrayPattern(pattern.items.map(item => { + if (item.kind === 'Hole') { + return null; + } + return codegenLValue(cx, item); + })); + } +} +function codegenLValue(cx, pattern) { + switch (pattern.kind) { + case 'ArrayPattern': { + return codegenArrayPattern(cx, pattern); + } + case 'ObjectPattern': { + return libExports$1.objectPattern(pattern.properties.map(property => { + if (property.kind === 'ObjectProperty') { + const key = codegenObjectPropertyKey(cx, property.key); + const value = codegenLValue(cx, property.place); + return libExports$1.objectProperty(key, value, property.key.kind === 'computed', key.type === 'Identifier' && + value.type === 'Identifier' && + value.name === key.name); + } + else { + return libExports$1.restElement(codegenLValue(cx, property.place)); + } + })); + } + case 'Spread': { + return libExports$1.restElement(codegenLValue(cx, pattern.place)); + } + case 'Identifier': { + return convertIdentifier(pattern.identifier); + } + default: { + assertExhaustive$1(pattern, `Unexpected pattern kind \`${pattern.kind}\``); + } + } +} +function codegenValue(cx, loc, value) { + if (typeof value === 'number') { + return libExports$1.numericLiteral(value); + } + else if (typeof value === 'boolean') { + return libExports$1.booleanLiteral(value); + } + else if (typeof value === 'string') { + return createStringLiteral(loc, value); + } + else if (value === null) { + return libExports$1.nullLiteral(); + } + else if (value === undefined) { + return libExports$1.identifier('undefined'); + } + else { + assertExhaustive$1(value, 'Unexpected primitive value kind'); + } +} +function codegenArgument(cx, arg) { + if (arg.kind === 'Identifier') { + return codegenPlaceToExpression(cx, arg); + } + else { + return libExports$1.spreadElement(codegenPlaceToExpression(cx, arg.place)); + } +} +function codegenPlaceToExpression(cx, place) { + const value = codegenPlace(cx, place); + return convertValueToExpression(value); +} +function codegenPlace(cx, place) { + let tmp = cx.temp.get(place.identifier.declarationId); + if (tmp != null) { + return tmp; + } + CompilerError.invariant(place.identifier.name !== null || tmp !== undefined, { + reason: `[Codegen] No value found for temporary`, + description: `Value for '${printPlace(place)}' was not set in the codegen context`, + loc: place.loc, + suggestions: null, + }); + const identifier = convertIdentifier(place.identifier); + identifier.loc = place.loc; + return identifier; +} +function convertIdentifier(identifier) { + CompilerError.invariant(identifier.name !== null && identifier.name.kind === 'named', { + reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`, + loc: GeneratedSource, + description: `identifier ${identifier.id} is unnamed`, + suggestions: null, + }); + return libExports$1.identifier(identifier.name.value); +} +function compareScopeDependency(a, b) { + var _a, _b; + CompilerError.invariant(((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' && ((_b = b.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named', { + reason: '[Codegen] Expected named identifier for dependency', + loc: a.identifier.loc, + }); + const aName = [ + a.identifier.name.value, + ...a.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`), + ].join('.'); + const bName = [ + b.identifier.name.value, + ...b.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`), + ].join('.'); + if (aName < bName) + return -1; + else if (aName > bName) + return 1; + else + return 0; +} +function compareScopeDeclaration(a, b) { + var _a, _b; + CompilerError.invariant(((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' && ((_b = b.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named', { + reason: '[Codegen] Expected named identifier for declaration', + loc: a.identifier.loc, + }); + const aName = a.identifier.name.value; + const bName = b.identifier.name.value; + if (aName < bName) + return -1; + else if (aName > bName) + return 1; + else + return 0; +} + +function extractScopeDeclarationsFromDestructuring(fn) { + const state = new State$1(fn.env); + visitReactiveFunction(fn, new Visitor$9(), state); +} +let State$1 = class State { + constructor(env) { + this.declared = new Set(); + this.env = env; + } +}; +let Visitor$9 = class Visitor extends ReactiveFunctionTransform { + visitScope(scope, state) { + for (const [, declaration] of scope.scope.declarations) { + state.declared.add(declaration.identifier.declarationId); + } + this.traverseScope(scope, state); + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + if (instruction.value.kind === 'Destructure') { + const transformed = transformDestructuring(state, instruction, instruction.value); + if (transformed) { + return { + kind: 'replace-many', + value: transformed.map(instruction => ({ + kind: 'instruction', + instruction, + })), + }; + } + } + return { kind: 'keep' }; + } +}; +function transformDestructuring(state, instr, destructure) { + let reassigned = new Set(); + let hasDeclaration = false; + for (const place of eachPatternOperand(destructure.lvalue.pattern)) { + const isDeclared = state.declared.has(place.identifier.declarationId); + if (isDeclared) { + reassigned.add(place.identifier.id); + } + hasDeclaration || (hasDeclaration = !isDeclared); + } + if (reassigned.size === 0 || !hasDeclaration) { + return null; + } + const instructions = []; + const renamed = new Map(); + mapPatternOperands(destructure.lvalue.pattern, place => { + if (!reassigned.has(place.identifier.id)) { + return place; + } + const temporary = clonePlaceToTemporary(state.env, place); + promoteTemporary(temporary.identifier); + renamed.set(place, temporary); + return temporary; + }); + instructions.push(instr); + for (const [original, temporary] of renamed) { + instructions.push({ + id: instr.id, + lvalue: null, + value: { + kind: 'StoreLocal', + lvalue: { + kind: InstructionKind.Reassign, + place: original, + }, + value: temporary, + type: null, + loc: destructure.loc, + }, + loc: instr.loc, + }); + } + return instructions; +} + +function mergeReactiveScopesThatInvalidateTogether(fn) { + const lastUsageVisitor = new FindLastUsageVisitor(); + visitReactiveFunction(fn, lastUsageVisitor, undefined); + visitReactiveFunction(fn, new Transform$4(lastUsageVisitor.lastUsage), null); +} +function log(msg) { +} +class FindLastUsageVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.lastUsage = new Map(); + } + visitPlace(id, place, _state) { + const previousUsage = this.lastUsage.get(place.identifier.declarationId); + const lastUsage = previousUsage !== undefined + ? makeInstructionId(Math.max(previousUsage, id)) + : id; + this.lastUsage.set(place.identifier.declarationId, lastUsage); + } +} +let Transform$4 = class Transform extends ReactiveFunctionTransform { + constructor(lastUsage) { + super(); + this.lastUsage = lastUsage; + } + transformScope(scopeBlock, state) { + this.visitScope(scopeBlock, scopeBlock.scope.dependencies); + if (state !== null && + areEqualDependencies(state, scopeBlock.scope.dependencies)) { + return { kind: 'replace-many', value: scopeBlock.instructions }; + } + else { + return { kind: 'keep' }; + } + } + visitBlock(block, state) { + this.traverseBlock(block, state); + let current = null; + const merged = []; + function reset() { + CompilerError.invariant(current !== null, { + loc: null, + reason: 'MergeConsecutiveScopes: expected current scope to be non-null if reset()', + suggestions: null, + description: null, + }); + if (current.to > current.from + 1) { + merged.push(current); + } + current = null; + } + for (let i = 0; i < block.length; i++) { + const instr = block[i]; + switch (instr.kind) { + case 'terminal': { + if (current !== null) { + reset(); + } + break; + } + case 'pruned-scope': { + if (current !== null) { + reset(); + } + break; + } + case 'instruction': { + switch (instr.instruction.value.kind) { + case 'BinaryExpression': + case 'ComputedLoad': + case 'JSXText': + case 'LoadGlobal': + case 'LoadLocal': + case 'Primitive': + case 'PropertyLoad': + case 'TemplateLiteral': + case 'UnaryExpression': { + if (current !== null && instr.instruction.lvalue !== null) { + current.lvalues.add(instr.instruction.lvalue.identifier.declarationId); + } + break; + } + case 'StoreLocal': { + if (current !== null) { + if (instr.instruction.value.lvalue.kind === InstructionKind.Const) { + for (const lvalue of eachInstructionLValue(instr.instruction)) { + current.lvalues.add(lvalue.identifier.declarationId); + } + } + else { + reset(); + } + } + break; + } + default: { + if (current !== null) { + reset(); + } + } + } + break; + } + case 'scope': { + if (current !== null && + canMergeScopes(current.block, instr) && + areLValuesLastUsedByScope(instr.scope, current.lvalues, this.lastUsage)) { + current.block.scope.range.end = makeInstructionId(Math.max(current.block.scope.range.end, instr.scope.range.end)); + for (const [key, value] of instr.scope.declarations) { + current.block.scope.declarations.set(key, value); + } + updateScopeDeclarations(current.block.scope, this.lastUsage); + current.to = i + 1; + current.lvalues.clear(); + if (!scopeIsEligibleForMerging(instr)) { + reset(); + } + } + else { + if (current !== null) { + reset(); + } + if (scopeIsEligibleForMerging(instr)) { + current = { + block: instr, + from: i, + to: i + 1, + lvalues: new Set(), + }; + } + } + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + } + if (current !== null) { + reset(); + } + if (merged.length) { + for (const entry of merged) { + log(printReactiveScopeSummary(entry.block.scope) + + ` from=${entry.from} to=${entry.to}`); + } + } + if (merged.length === 0) { + return; + } + const nextInstructions = []; + let index = 0; + for (const entry of merged) { + if (index < entry.from) { + nextInstructions.push(...block.slice(index, entry.from)); + index = entry.from; + } + const mergedScope = block[entry.from]; + CompilerError.invariant(mergedScope.kind === 'scope', { + loc: null, + reason: 'MergeConsecutiveScopes: Expected scope starting index to be a scope', + description: null, + suggestions: null, + }); + nextInstructions.push(mergedScope); + index++; + while (index < entry.to) { + const instr = block[index++]; + if (instr.kind === 'scope') { + mergedScope.instructions.push(...instr.instructions); + mergedScope.scope.merged.add(instr.scope.id); + } + else { + mergedScope.instructions.push(instr); + } + } + } + while (index < block.length) { + nextInstructions.push(block[index++]); + } + block.length = 0; + block.push(...nextInstructions); + } +}; +function updateScopeDeclarations(scope, lastUsage) { + for (const [id, decl] of scope.declarations) { + const lastUsedAt = lastUsage.get(decl.identifier.declarationId); + if (lastUsedAt < scope.range.end) { + scope.declarations.delete(id); + } + } +} +function areLValuesLastUsedByScope(scope, lvalues, lastUsage) { + for (const lvalue of lvalues) { + const lastUsedAt = lastUsage.get(lvalue); + if (lastUsedAt >= scope.range.end) { + return false; + } + } + return true; +} +function canMergeScopes(current, next) { + if (current.scope.reassignments.size !== 0 || + next.scope.reassignments.size !== 0) { + return false; + } + if (areEqualDependencies(current.scope.dependencies, next.scope.dependencies)) { + return true; + } + if (areEqualDependencies(new Set([...current.scope.declarations.values()].map(declaration => ({ + identifier: declaration.identifier, + path: [], + }))), next.scope.dependencies) || + (next.scope.dependencies.size !== 0 && + [...next.scope.dependencies].every(dep => isAlwaysInvalidatingType(dep.identifier.type) && + Iterable_some(current.scope.declarations.values(), decl => decl.identifier.declarationId === dep.identifier.declarationId)))) { + return true; + } + log(` ${printReactiveScopeSummary(current.scope)}`); + log(` ${printReactiveScopeSummary(next.scope)}`); + return false; +} +function isAlwaysInvalidatingType(type) { + switch (type.kind) { + case 'Object': { + switch (type.shapeId) { + case BuiltInArrayId: + case BuiltInObjectId: + case BuiltInFunctionId: + case BuiltInJsxId: { + return true; + } + } + break; + } + case 'Function': { + return true; + } + } + return false; +} +function areEqualDependencies(a, b) { + if (a.size !== b.size) { + return false; + } + for (const aValue of a) { + let found = false; + for (const bValue of b) { + if (aValue.identifier.declarationId === bValue.identifier.declarationId && + areEqualPaths(aValue.path, bValue.path)) { + found = true; + break; + } + } + if (!found) { + return false; + } + } + return true; +} +function scopeIsEligibleForMerging(scopeBlock) { + if (scopeBlock.scope.dependencies.size === 0) { + return true; + } + return [...scopeBlock.scope.declarations].some(([, decl]) => isAlwaysInvalidatingType(decl.identifier.type)); +} + +var _PromoteInterposedTemporaries_promotable, _PromoteInterposedTemporaries_consts, _PromoteInterposedTemporaries_globals; +class PromoteTemporaries extends ReactiveFunctionVisitor { + visitScope(scopeBlock, state) { + for (const dep of scopeBlock.scope.dependencies) { + const { identifier } = dep; + if (identifier.name == null) { + promoteIdentifier(identifier, state); + } + } + for (const [, declaration] of scopeBlock.scope.declarations) { + if (declaration.identifier.name == null) { + promoteIdentifier(declaration.identifier, state); + } + } + this.traverseScope(scopeBlock, state); + } + visitPrunedScope(scopeBlock, state) { + var _a; + for (const [, declaration] of scopeBlock.scope.declarations) { + if (declaration.identifier.name == null && + ((_a = state.pruned.get(declaration.identifier.declarationId)) === null || _a === void 0 ? void 0 : _a.usedOutsideScope) === true) { + promoteIdentifier(declaration.identifier, state); + } + } + this.traversePrunedScope(scopeBlock, state); + } + visitParam(place, state) { + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + for (const operand of fn.params) { + const place = operand.kind === 'Identifier' ? operand : operand.place; + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitReactiveFunction(fn, this, state); + } +} +class PromoteAllInstancedOfPromotedTemporaries extends ReactiveFunctionVisitor { + visitPlace(_id, place, state) { + if (place.identifier.name === null && + state.promoted.has(place.identifier.declarationId)) { + promoteIdentifier(place.identifier, state); + } + } + visitLValue(_id, _lvalue, _state) { + this.visitPlace(_id, _lvalue, _state); + } + traverseScopeIdentifiers(scope, state) { + for (const [, decl] of scope.declarations) { + if (decl.identifier.name === null && + state.promoted.has(decl.identifier.declarationId)) { + promoteIdentifier(decl.identifier, state); + } + } + for (const dep of scope.dependencies) { + if (dep.identifier.name === null && + state.promoted.has(dep.identifier.declarationId)) { + promoteIdentifier(dep.identifier, state); + } + } + for (const reassignment of scope.reassignments) { + if (reassignment.name === null && + state.promoted.has(reassignment.declarationId)) { + promoteIdentifier(reassignment, state); + } + } + } + visitScope(scope, state) { + this.traverseScope(scope, state); + this.traverseScopeIdentifiers(scope.scope, state); + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + this.traverseScopeIdentifiers(scopeBlock.scope, state); + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +} +class CollectPromotableTemporaries extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.activeScopes = []; + } + visitPlace(_id, place, state) { + if (this.activeScopes.length !== 0 && + state.pruned.has(place.identifier.declarationId)) { + const prunedPlace = state.pruned.get(place.identifier.declarationId); + if (prunedPlace.activeScopes.indexOf(this.activeScopes.at(-1)) === -1) { + prunedPlace.usedOutsideScope = true; + } + } + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'JsxExpression' && value.tag.kind === 'Identifier') { + state.tags.add(value.tag.identifier.declarationId); + } + } + visitPrunedScope(scopeBlock, state) { + for (const [_id, decl] of scopeBlock.scope.declarations) { + state.pruned.set(decl.identifier.declarationId, { + activeScopes: [...this.activeScopes], + usedOutsideScope: false, + }); + } + this.visitBlock(scopeBlock.instructions, state); + } + visitScope(scopeBlock, state) { + this.activeScopes.push(scopeBlock.scope.id); + this.traverseScope(scopeBlock, state); + this.activeScopes.pop(); + } +} +class PromoteInterposedTemporaries extends ReactiveFunctionVisitor { + constructor(promotable, params) { + super(); + _PromoteInterposedTemporaries_promotable.set(this, void 0); + _PromoteInterposedTemporaries_consts.set(this, new Set()); + _PromoteInterposedTemporaries_globals.set(this, new Set()); + params.forEach(param => { + switch (param.kind) { + case 'Identifier': + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(param.identifier.id); + break; + case 'Spread': + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(param.place.identifier.id); + break; + } + }); + __classPrivateFieldSet(this, _PromoteInterposedTemporaries_promotable, promotable, "f"); + } + visitPlace(_id, place, state) { + const promo = state.get(place.identifier.id); + if (promo) { + const [identifier, needsPromotion] = promo; + if (needsPromotion && + identifier.name === null && + !__classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").has(identifier.id)) { + promoteIdentifier(identifier, __classPrivateFieldGet(this, _PromoteInterposedTemporaries_promotable, "f")); + } + } + } + visitInstruction(instruction, state) { + for (const lval of eachInstructionValueLValue(instruction.value)) { + CompilerError.invariant(lval.identifier.name != null, { + reason: 'PromoteInterposedTemporaries: Assignment targets not expected to be temporaries', + loc: instruction.loc, + }); + } + switch (instruction.value.kind) { + case 'CallExpression': + case 'MethodCall': + case 'Await': + case 'PropertyStore': + case 'PropertyDelete': + case 'ComputedStore': + case 'ComputedDelete': + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'StoreLocal': + case 'StoreContext': + case 'StoreGlobal': + case 'Destructure': { + let constStore = false; + if ((instruction.value.kind === 'StoreContext' || + instruction.value.kind === 'StoreLocal') && + (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst')) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.lvalue.place.identifier.id); + constStore = true; + } + if (instruction.value.kind === 'Destructure' && + (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst')) { + [...eachPatternOperand(instruction.value.lvalue.pattern)].forEach(ident => __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(ident.identifier.id)); + constStore = true; + } + if (instruction.value.kind === 'MethodCall') { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.property.identifier.id); + } + super.visitInstruction(instruction, state); + if (!constStore && + (instruction.lvalue == null || + instruction.lvalue.identifier.name != null)) { + for (const [key, [ident, _]] of state.entries()) { + state.set(key, [ident, true]); + } + } + if (instruction.lvalue && instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + break; + } + case 'DeclareContext': + case 'DeclareLocal': { + if (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst') { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.lvalue.place.identifier.id); + } + super.visitInstruction(instruction, state); + break; + } + case 'LoadContext': + case 'LoadLocal': { + if (instruction.lvalue && instruction.lvalue.identifier.name === null) { + if (__classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").has(instruction.value.place.identifier.id)) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.lvalue.identifier.id); + } + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + super.visitInstruction(instruction, state); + break; + } + case 'PropertyLoad': + case 'ComputedLoad': { + if (instruction.lvalue) { + if (__classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").has(instruction.value.object.identifier.id)) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").add(instruction.lvalue.identifier.id); + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.lvalue.identifier.id); + } + if (instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + } + super.visitInstruction(instruction, state); + break; + } + case 'LoadGlobal': { + instruction.lvalue && + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").add(instruction.lvalue.identifier.id); + super.visitInstruction(instruction, state); + break; + } + default: { + super.visitInstruction(instruction, state); + } + } + } +} +_PromoteInterposedTemporaries_promotable = new WeakMap(), _PromoteInterposedTemporaries_consts = new WeakMap(), _PromoteInterposedTemporaries_globals = new WeakMap(); +function promoteUsedTemporaries(fn) { + const state = { + tags: new Set(), + promoted: new Set(), + pruned: new Map(), + }; + visitReactiveFunction(fn, new CollectPromotableTemporaries(), state); + for (const operand of fn.params) { + const place = operand.kind === 'Identifier' ? operand : operand.place; + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitReactiveFunction(fn, new PromoteTemporaries(), state); + visitReactiveFunction(fn, new PromoteInterposedTemporaries(state, fn.params), new Map()); + visitReactiveFunction(fn, new PromoteAllInstancedOfPromotedTemporaries(), state); +} +function promoteIdentifier(identifier, state) { + CompilerError.invariant(identifier.name === null, { + reason: 'promoteTemporary: Expected to be called only for temporary variables', + description: null, + loc: GeneratedSource, + suggestions: null, + }); + if (state.tags.has(identifier.declarationId)) { + promoteTemporaryJsxTag(identifier); + } + else { + promoteTemporary(identifier); + } + state.promoted.add(identifier.declarationId); +} + +function propagateEarlyReturns(fn) { + visitReactiveFunction(fn, new Transform$3(fn.env), { + withinReactiveScope: false, + earlyReturnValue: null, + }); +} +let Transform$3 = class Transform extends ReactiveFunctionTransform { + constructor(env) { + super(); + this.env = env; + } + visitScope(scopeBlock, parentState) { + if (scopeBlock.scope.earlyReturnValue !== null) { + return; + } + const innerState = { + withinReactiveScope: true, + earlyReturnValue: parentState.earlyReturnValue, + }; + this.traverseScope(scopeBlock, innerState); + const earlyReturnValue = innerState.earlyReturnValue; + if (earlyReturnValue !== null) { + if (!parentState.withinReactiveScope) { + scopeBlock.scope.earlyReturnValue = earlyReturnValue; + scopeBlock.scope.declarations.set(earlyReturnValue.value.id, { + identifier: earlyReturnValue.value, + scope: scopeBlock.scope, + }); + const instructions = scopeBlock.instructions; + const loc = earlyReturnValue.loc; + const sentinelTemp = createTemporaryPlace(this.env, loc); + const symbolTemp = createTemporaryPlace(this.env, loc); + const forTemp = createTemporaryPlace(this.env, loc); + const argTemp = createTemporaryPlace(this.env, loc); + scopeBlock.instructions = [ + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, symbolTemp), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: 'Symbol', + }, + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, forTemp), + value: { + kind: 'PropertyLoad', + object: Object.assign({}, symbolTemp), + property: makePropertyLiteral('for'), + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, argTemp), + value: { + kind: 'Primitive', + value: EARLY_RETURN_SENTINEL, + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, sentinelTemp), + value: { + kind: 'MethodCall', + receiver: symbolTemp, + property: forTemp, + args: [argTemp], + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: null, + value: { + kind: 'StoreLocal', + loc, + type: null, + lvalue: { + kind: InstructionKind.Let, + place: { + kind: 'Identifier', + effect: Effect.ConditionallyMutate, + loc, + reactive: true, + identifier: earlyReturnValue.value, + }, + }, + value: Object.assign({}, sentinelTemp), + }, + }, + }, + { + kind: 'terminal', + label: { + id: earlyReturnValue.label, + implicit: false, + }, + terminal: { + kind: 'label', + id: makeInstructionId(0), + loc: GeneratedSource, + block: instructions, + }, + }, + ]; + } + else { + parentState.earlyReturnValue = earlyReturnValue; + } + } + } + transformTerminal(stmt, state) { + if (state.withinReactiveScope && stmt.terminal.kind === 'return') { + const loc = stmt.terminal.value.loc; + let earlyReturnValue; + if (state.earlyReturnValue !== null) { + earlyReturnValue = state.earlyReturnValue; + } + else { + const identifier = createTemporaryPlace(this.env, loc).identifier; + promoteTemporary(identifier); + earlyReturnValue = { + label: this.env.nextBlockId, + loc, + value: identifier, + }; + } + state.earlyReturnValue = earlyReturnValue; + return { + kind: 'replace-many', + value: [ + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: null, + value: { + kind: 'StoreLocal', + loc, + type: null, + lvalue: { + kind: InstructionKind.Reassign, + place: { + kind: 'Identifier', + identifier: earlyReturnValue.value, + effect: Effect.Capture, + loc, + reactive: true, + }, + }, + value: stmt.terminal.value, + }, + }, + }, + { + kind: 'terminal', + label: null, + terminal: { + kind: 'break', + id: makeInstructionId(0), + loc, + targetKind: 'labeled', + target: earlyReturnValue.label, + }, + }, + ], + }; + } + this.traverseTerminal(stmt, state); + return { kind: 'keep' }; + } +}; + +var _Node_value, _Node_next; +function empty() { + return EMPTY; +} +class Node { + constructor(value, next = EMPTY) { + _Node_value.set(this, void 0); + _Node_next.set(this, void 0); + __classPrivateFieldSet(this, _Node_value, value, "f"); + __classPrivateFieldSet(this, _Node_next, next, "f"); + } + push(value) { + return new Node(value, this); + } + pop() { + return __classPrivateFieldGet(this, _Node_next, "f"); + } + find(fn) { + return fn(__classPrivateFieldGet(this, _Node_value, "f")) ? true : __classPrivateFieldGet(this, _Node_next, "f").find(fn); + } + contains(value) { + return (value === __classPrivateFieldGet(this, _Node_value, "f") || + (__classPrivateFieldGet(this, _Node_next, "f") !== null && __classPrivateFieldGet(this, _Node_next, "f").contains(value))); + } + each(fn) { + fn(__classPrivateFieldGet(this, _Node_value, "f")); + __classPrivateFieldGet(this, _Node_next, "f").each(fn); + } + get value() { + return __classPrivateFieldGet(this, _Node_value, "f"); + } + print(fn) { + return fn(__classPrivateFieldGet(this, _Node_value, "f")) + __classPrivateFieldGet(this, _Node_next, "f").print(fn); + } +} +_Node_value = new WeakMap(), _Node_next = new WeakMap(); +class Empty { + push(value) { + return new Node(value, this); + } + pop() { + return this; + } + find(_fn) { + return false; + } + contains(_value) { + return false; + } + each(_fn) { + return; + } + get value() { + return null; + } + print(_) { + return ''; + } +} +const EMPTY = new Empty(); + +function pruneHoistedContexts(fn) { + visitReactiveFunction(fn, new Visitor$8(), { + activeScopes: empty(), + }); +} +let Visitor$8 = class Visitor extends ReactiveFunctionTransform { + visitScope(scope, state) { + state.activeScopes = state.activeScopes.push(new Set(scope.scope.declarations.keys())); + this.traverseScope(scope, state); + state.activeScopes.pop(); + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + if (instruction.value.kind === 'DeclareContext') { + const maybeNonHoisted = convertHoistedLValueKind(instruction.value.lvalue.kind); + if (maybeNonHoisted != null) { + return { kind: 'remove' }; + } + } + if (instruction.value.kind === 'StoreContext' && + instruction.value.lvalue.kind !== InstructionKind.Reassign) { + const lvalueId = instruction.value.lvalue.place.identifier.id; + const isDeclaredByScope = state.activeScopes.find(scope => scope.has(lvalueId)); + if (isDeclaredByScope) { + instruction.value.lvalue.kind = InstructionKind.Reassign; + } + } + return { kind: 'keep' }; + } +}; + +function inferOperandEffect(state, place) { + const value = state.kind(place); + CompilerError.invariant(value != null, { + reason: 'Expected operand to have a kind', + loc: null, + }); + switch (place.effect) { + case Effect.Store: + case Effect.Mutate: { + if (isRefOrRefValue(place.identifier)) { + break; + } + else if (value.kind === ValueKind.Context) { + CompilerError.invariant(value.context.size > 0, { + reason: "[InferFunctionEffects] Expected Context-kind value's capture list to be non-empty.", + loc: place.loc, + }); + return { + kind: 'ContextMutation', + loc: place.loc, + effect: place.effect, + places: value.context, + }; + } + else if (value.kind !== ValueKind.Mutable && + value.kind !== ValueKind.Primitive) { + let reason = getWriteErrorReason(value); + return { + kind: value.reason.size === 1 && value.reason.has(ValueReason.Global) + ? 'GlobalMutation' + : 'ReactMutation', + error: { + reason, + description: place.identifier.name !== null && + place.identifier.name.kind === 'named' + ? `Found mutation of \`${place.identifier.name.value}\`` + : null, + loc: place.loc, + suggestions: null, + severity: ErrorSeverity.InvalidReact, + }, + }; + } + break; + } + } + return null; +} +function inheritFunctionEffects(state, place) { + const effects = inferFunctionInstrEffects(state, place); + return effects + .flatMap(effect => { + if (effect.kind === 'GlobalMutation' || effect.kind === 'ReactMutation') { + return [effect]; + } + else { + const effects = []; + CompilerError.invariant(effect.kind === 'ContextMutation', { + reason: 'Expected ContextMutation', + loc: null, + }); + for (const place of effect.places) { + if (state.isDefined(place)) { + const replayedEffect = inferOperandEffect(state, Object.assign(Object.assign({}, place), { loc: effect.loc, effect: effect.effect })); + if (replayedEffect != null) { + if (replayedEffect.kind === 'ContextMutation') { + effects.push(effect); + } + else { + effects.push(replayedEffect); + } + } + } + } + return effects; + } + }) + .filter((effect) => effect != null); +} +function inferFunctionInstrEffects(state, place) { + const effects = []; + const instrs = state.values(place); + CompilerError.invariant(instrs != null, { + reason: 'Expected operand to have instructions', + loc: null, + }); + for (const instr of instrs) { + if ((instr.kind === 'FunctionExpression' || instr.kind === 'ObjectMethod') && + instr.loweredFunc.func.effects != null) { + effects.push(...instr.loweredFunc.func.effects); + } + } + return effects; +} +function operandEffects(state, place, filterRenderSafe) { + const functionEffects = []; + const effect = inferOperandEffect(state, place); + effect && functionEffects.push(effect); + functionEffects.push(...inheritFunctionEffects(state, place)); + if (filterRenderSafe) { + return functionEffects.filter(effect => !isEffectSafeOutsideRender(effect)); + } + else { + return functionEffects; + } +} +function inferInstructionFunctionEffects(env, state, instr) { + var _a, _b; + var _c; + const functionEffects = []; + switch (instr.value.kind) { + case 'JsxExpression': { + if (instr.value.tag.kind === 'Identifier') { + functionEffects.push(...operandEffects(state, instr.value.tag, false)); + } + (_a = instr.value.children) === null || _a === void 0 ? void 0 : _a.forEach(child => functionEffects.push(...operandEffects(state, child, false))); + for (const attr of instr.value.props) { + if (attr.kind === 'JsxSpreadAttribute') { + functionEffects.push(...operandEffects(state, attr.argument, false)); + } + else { + functionEffects.push(...operandEffects(state, attr.place, true)); + } + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + for (const operand of eachInstructionOperand(instr)) { + (_b = (_c = instr.value.loweredFunc.func).effects) !== null && _b !== void 0 ? _b : (_c.effects = []); + instr.value.loweredFunc.func.effects.push(...inferFunctionInstrEffects(state, operand)); + } + break; + } + case 'MethodCall': + case 'CallExpression': { + let callee; + if (instr.value.kind === 'MethodCall') { + callee = instr.value.property; + functionEffects.push(...operandEffects(state, instr.value.receiver, false)); + } + else { + callee = instr.value.callee; + } + functionEffects.push(...operandEffects(state, callee, false)); + let isHook = getHookKind(env, callee.identifier) != null; + for (const arg of instr.value.args) { + const place = arg.kind === 'Identifier' ? arg : arg.place; + functionEffects.push(...operandEffects(state, place, isHook)); + } + break; + } + case 'StartMemoize': + case 'FinishMemoize': + case 'LoadLocal': + case 'StoreLocal': { + break; + } + case 'StoreGlobal': { + functionEffects.push({ + kind: 'GlobalMutation', + error: { + reason: 'Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)', + loc: instr.loc, + suggestions: null, + severity: ErrorSeverity.InvalidReact, + }, + }); + break; + } + default: { + for (const operand of eachInstructionOperand(instr)) { + functionEffects.push(...operandEffects(state, operand, false)); + } + } + } + return functionEffects; +} +function inferTerminalFunctionEffects(state, block) { + const functionEffects = []; + for (const operand of eachTerminalOperand(block.terminal)) { + functionEffects.push(...operandEffects(state, operand, true)); + } + return functionEffects; +} +function transformFunctionEffectErrors(functionEffects) { + return functionEffects.map(eff => { + switch (eff.kind) { + case 'ReactMutation': + case 'GlobalMutation': { + return eff.error; + } + case 'ContextMutation': { + return { + severity: ErrorSeverity.Invariant, + reason: `Unexpected ContextMutation in top-level function effects`, + loc: eff.loc, + }; + } + default: + assertExhaustive$1(eff, `Unexpected function effect kind \`${eff.kind}\``); + } + }); +} +function isEffectSafeOutsideRender(effect) { + return effect.kind === 'GlobalMutation'; +} +function getWriteErrorReason(abstractValue) { + if (abstractValue.reason.has(ValueReason.Global)) { + return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect'; + } + else if (abstractValue.reason.has(ValueReason.JsxCaptured)) { + return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX'; + } + else if (abstractValue.reason.has(ValueReason.Context)) { + return `Mutating a value returned from 'useContext()', which should not be mutated`; + } + else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) { + return 'Mutating a value returned from a function whose return value should not be mutated'; + } + else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) { + return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead'; + } + else if (abstractValue.reason.has(ValueReason.State)) { + return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead"; + } + else if (abstractValue.reason.has(ValueReason.ReducerState)) { + return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead"; + } + else { + return 'This mutates a variable that React considers immutable'; + } +} + +var _InferenceState_isFunctionExpression, _InferenceState_values, _InferenceState_variables; +const UndefinedValue = { + kind: 'Primitive', + loc: GeneratedSource, + value: undefined, +}; +function inferReferenceEffects(fn, options = { isFunctionExpression: false }) { + var _a; + const initialState = InferenceState.empty(fn.env, options.isFunctionExpression); + const value = { + kind: 'Primitive', + loc: fn.loc, + value: undefined, + }; + initialState.initialize(value, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + for (const ref of fn.context) { + const value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.loc, + }; + initialState.initialize(value, { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set([ref]), + }); + initialState.define(ref, value); + } + const paramKind = options.isFunctionExpression + ? { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + } + : { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.ReactiveFunctionArgument]), + context: new Set(), + }; + if (fn.fnType === 'Component') { + CompilerError.invariant(fn.params.length <= 2, { + reason: 'Expected React component to have not more than two parameters: one for props and for ref', + description: null, + loc: fn.loc, + suggestions: null, + }); + const [props, ref] = fn.params; + let value; + let place; + if (props) { + inferParam(props, initialState, paramKind); + } + if (ref) { + if (ref.kind === 'Identifier') { + place = ref; + value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.loc, + }; + } + else { + place = ref.place; + value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.place.loc, + }; + } + initialState.initialize(value, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + initialState.define(place, value); + } + } + else { + for (const param of fn.params) { + inferParam(param, initialState, paramKind); + } + } + const statesByBlock = new Map(); + const queuedStates = new Map(); + function queue(blockId, state) { + var _a; + let queuedState = queuedStates.get(blockId); + if (queuedState != null) { + state = (_a = queuedState.merge(state)) !== null && _a !== void 0 ? _a : queuedState; + queuedStates.set(blockId, state); + } + else { + const prevState = statesByBlock.get(blockId); + const nextState = prevState != null ? prevState.merge(state) : state; + if (nextState != null) { + queuedStates.set(blockId, nextState); + } + } + } + queue(fn.body.entry, initialState); + const functionEffects = (_a = fn.effects) !== null && _a !== void 0 ? _a : []; + while (queuedStates.size !== 0) { + for (const [blockId, block] of fn.body.blocks) { + const incomingState = queuedStates.get(blockId); + queuedStates.delete(blockId); + if (incomingState == null) { + continue; + } + statesByBlock.set(blockId, incomingState); + const state = incomingState.clone(); + inferBlock(fn.env, state, block, functionEffects); + for (const nextBlockId of eachTerminalSuccessor(block.terminal)) { + queue(nextBlockId, state); + } + } + } + if (options.isFunctionExpression) { + fn.effects = functionEffects; + return []; + } + else { + return transformFunctionEffectErrors(functionEffects); + } +} +class InferenceState { + constructor(env, isFunctionExpression, values, variables) { + _InferenceState_isFunctionExpression.set(this, void 0); + _InferenceState_values.set(this, void 0); + _InferenceState_variables.set(this, void 0); + this.env = env; + __classPrivateFieldSet(this, _InferenceState_isFunctionExpression, isFunctionExpression, "f"); + __classPrivateFieldSet(this, _InferenceState_values, values, "f"); + __classPrivateFieldSet(this, _InferenceState_variables, variables, "f"); + } + static empty(env, isFunctionExpression) { + return new InferenceState(env, isFunctionExpression, new Map(), new Map()); + } + get isFunctionExpression() { + return __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"); + } + initialize(value, kind) { + CompilerError.invariant(value.kind !== 'LoadLocal', { + reason: 'Expected all top-level identifiers to be defined as variables, not values', + description: null, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_values, "f").set(value, kind); + } + values(place) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value kind to be initialized`, + description: `${printPlace(place)}`, + loc: place.loc, + suggestions: null, + }); + return Array.from(values); + } + kind(place) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value kind to be initialized`, + description: `${printPlace(place)}`, + loc: place.loc, + suggestions: null, + }); + let mergedKind = null; + for (const value of values) { + const kind = __classPrivateFieldGet(this, _InferenceState_values, "f").get(value); + mergedKind = + mergedKind !== null ? mergeAbstractValues(mergedKind, kind) : kind; + } + CompilerError.invariant(mergedKind !== null, { + reason: `InferReferenceEffects::kind: Expected at least one value`, + description: `No value found at \`${printPlace(place)}\``, + loc: place.loc, + suggestions: null, + }); + return mergedKind; + } + alias(place, value) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(value.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value for identifier to be initialized`, + description: `${printIdentifier(value.identifier)}`, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(place.identifier.id, new Set(values)); + } + define(place, value) { + CompilerError.invariant(__classPrivateFieldGet(this, _InferenceState_values, "f").has(value), { + reason: `Expected value to be initialized at '${printSourceLocation(value.loc)}'`, + description: null, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(place.identifier.id, new Set([value])); + } + isDefined(place) { + return __classPrivateFieldGet(this, _InferenceState_variables, "f").has(place.identifier.id); + } + referenceAndRecordEffects(freezeActions, place, effectKind, reason) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + if (values === undefined) { + CompilerError.invariant(effectKind !== Effect.Store, { + reason: '[InferReferenceEffects] Unhandled store reference effect', + description: null, + loc: place.loc, + suggestions: null, + }); + place.effect = + effectKind === Effect.ConditionallyMutate + ? Effect.ConditionallyMutate + : Effect.Read; + return; + } + const action = this.reference(place, effectKind, reason); + action && freezeActions.push(action); + } + freezeValues(values, reason) { + for (const value of values) { + if (value.kind === 'DeclareContext' || + (value.kind === 'StoreContext' && + (value.lvalue.kind === InstructionKind.Let || + value.lvalue.kind === InstructionKind.Const))) { + continue; + } + __classPrivateFieldGet(this, _InferenceState_values, "f").set(value, { + kind: ValueKind.Frozen, + reason, + context: new Set(), + }); + if (value.kind === 'FunctionExpression' && + (this.env.config.enablePreserveExistingMemoizationGuarantees || + this.env.config.enableTransitivelyFreezeFunctionExpressions)) { + for (const operand of value.loweredFunc.func.context) { + const operandValues = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(operand.identifier.id); + if (operandValues !== undefined) { + this.freezeValues(operandValues, reason); + } + } + } + } + } + reference(place, effectKind, reason) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values !== undefined, { + reason: '[InferReferenceEffects] Expected value to be initialized', + description: null, + loc: place.loc, + suggestions: null, + }); + let valueKind = this.kind(place); + let effect = null; + let freeze = null; + switch (effectKind) { + case Effect.Freeze: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context || + valueKind.kind === ValueKind.MaybeFrozen) { + const reasonSet = new Set([reason]); + effect = Effect.Freeze; + valueKind = { + kind: ValueKind.Frozen, + reason: reasonSet, + context: new Set(), + }; + freeze = { values, reason: reasonSet }; + } + else { + effect = Effect.Read; + } + break; + } + case Effect.ConditionallyMutate: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context) { + effect = Effect.ConditionallyMutate; + } + else { + effect = Effect.Read; + } + break; + } + case Effect.ConditionallyMutateIterator: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context) { + if (isArrayType(place.identifier) || + isSetType(place.identifier) || + isMapType(place.identifier)) { + effect = Effect.Capture; + } + else { + effect = Effect.ConditionallyMutate; + } + } + else { + effect = Effect.Read; + } + break; + } + case Effect.Mutate: { + effect = Effect.Mutate; + break; + } + case Effect.Store: { + effect = isObjectType(place.identifier) ? Effect.Store : Effect.Mutate; + break; + } + case Effect.Capture: { + if (valueKind.kind === ValueKind.Primitive || + valueKind.kind === ValueKind.Global || + valueKind.kind === ValueKind.Frozen || + valueKind.kind === ValueKind.MaybeFrozen) { + effect = Effect.Read; + } + else { + effect = Effect.Capture; + } + break; + } + case Effect.Read: { + effect = Effect.Read; + break; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect, expected to infer a precise effect kind', + description: null, + loc: place.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(effectKind, `Unexpected reference kind \`${effectKind}\``); + } + } + CompilerError.invariant(effect !== null, { + reason: 'Expected effect to be set', + description: null, + loc: place.loc, + suggestions: null, + }); + place.effect = effect; + return freeze; + } + merge(other) { + let nextValues = null; + let nextVariables = null; + for (const [id, thisValue] of __classPrivateFieldGet(this, _InferenceState_values, "f")) { + const otherValue = __classPrivateFieldGet(other, _InferenceState_values, "f").get(id); + if (otherValue !== undefined) { + const mergedValue = mergeAbstractValues(thisValue, otherValue); + if (mergedValue !== thisValue) { + nextValues = nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")); + nextValues.set(id, mergedValue); + } + } + } + for (const [id, otherValue] of __classPrivateFieldGet(other, _InferenceState_values, "f")) { + if (__classPrivateFieldGet(this, _InferenceState_values, "f").has(id)) { + continue; + } + nextValues = nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")); + nextValues.set(id, otherValue); + } + for (const [id, thisValues] of __classPrivateFieldGet(this, _InferenceState_variables, "f")) { + const otherValues = __classPrivateFieldGet(other, _InferenceState_variables, "f").get(id); + if (otherValues !== undefined) { + let mergedValues = null; + for (const otherValue of otherValues) { + if (!thisValues.has(otherValue)) { + mergedValues = mergedValues !== null && mergedValues !== void 0 ? mergedValues : new Set(thisValues); + mergedValues.add(otherValue); + } + } + if (mergedValues !== null) { + nextVariables = nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f")); + nextVariables.set(id, mergedValues); + } + } + } + for (const [id, otherValues] of __classPrivateFieldGet(other, _InferenceState_variables, "f")) { + if (__classPrivateFieldGet(this, _InferenceState_variables, "f").has(id)) { + continue; + } + nextVariables = nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f")); + nextVariables.set(id, new Set(otherValues)); + } + if (nextVariables === null && nextValues === null) { + return null; + } + else { + return new InferenceState(this.env, __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"), nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")), nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f"))); + } + } + clone() { + return new InferenceState(this.env, __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"), new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")), new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f"))); + } + debug() { + const result = { values: {}, variables: {} }; + const objects = new Map(); + function identify(value) { + let id = objects.get(value); + if (id == null) { + id = objects.size; + objects.set(value, id); + } + return id; + } + for (const [value, kind] of __classPrivateFieldGet(this, _InferenceState_values, "f")) { + const id = identify(value); + result.values[id] = { kind, value: printMixedHIR(value) }; + } + for (const [variable, values] of __classPrivateFieldGet(this, _InferenceState_variables, "f")) { + result.variables[`$${variable}`] = [...values].map(identify); + } + return result; + } + inferPhi(phi) { + const values = new Set(); + for (const [_, operand] of phi.operands) { + const operandValues = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(operand.identifier.id); + if (operandValues === undefined) + continue; + for (const v of operandValues) { + values.add(v); + } + } + if (values.size > 0) { + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(phi.place.identifier.id, values); + } + } +} +_InferenceState_isFunctionExpression = new WeakMap(), _InferenceState_values = new WeakMap(), _InferenceState_variables = new WeakMap(); +function inferParam(param, initialState, paramKind) { + let value; + let place; + if (param.kind === 'Identifier') { + place = param; + value = { + kind: 'Primitive', + loc: param.loc, + value: undefined, + }; + } + else { + place = param.place; + value = { + kind: 'Primitive', + loc: param.place.loc, + value: undefined, + }; + } + initialState.initialize(value, paramKind); + initialState.define(place, value); +} +function mergeValues(a, b) { + if (a === b) { + return a; + } + else if (a === ValueKind.MaybeFrozen || b === ValueKind.MaybeFrozen) { + return ValueKind.MaybeFrozen; + } + else if (a === ValueKind.Mutable || b === ValueKind.Mutable) { + if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.MaybeFrozen; + } + else if (a === ValueKind.Context || b === ValueKind.Context) { + return ValueKind.Context; + } + else { + return ValueKind.Mutable; + } + } + else if (a === ValueKind.Context || b === ValueKind.Context) { + if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.MaybeFrozen; + } + else { + return ValueKind.Context; + } + } + else if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.Frozen; + } + else if (a === ValueKind.Global || b === ValueKind.Global) { + return ValueKind.Global; + } + else { + CompilerError.invariant(a === ValueKind.Primitive && b == ValueKind.Primitive, { + reason: `Unexpected value kind in mergeValues()`, + description: `Found kinds ${a} and ${b}`, + loc: GeneratedSource, + }); + return ValueKind.Primitive; + } +} +function isSuperset(a, b) { + for (const v of b) { + if (!a.has(v)) { + return false; + } + } + return true; +} +function mergeAbstractValues(a, b) { + const kind = mergeValues(a.kind, b.kind); + if (kind === a.kind && + kind === b.kind && + isSuperset(a.reason, b.reason) && + isSuperset(a.context, b.context)) { + return a; + } + const reason = new Set(a.reason); + for (const r of b.reason) { + reason.add(r); + } + const context = new Set(a.context); + for (const c of b.context) { + context.add(c); + } + return { kind, reason, context }; +} +function inferBlock(env, state, block, functionEffects) { + var _a, _b, _c; + for (const phi of block.phis) { + state.inferPhi(phi); + } + for (const instr of block.instructions) { + const instrValue = instr.value; + const defaultLvalueEffect = Effect.ConditionallyMutate; + let continuation; + const freezeActions = []; + switch (instrValue.kind) { + case 'BinaryExpression': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.Read, + reason: ValueReason.Other, + }, + }; + break; + } + case 'ArrayExpression': { + const contextRefOperands = getContextRefOperand(state, instrValue); + const valueKind = contextRefOperands.length > 0 + ? { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set(contextRefOperands), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + for (const element of instrValue.elements) { + if (element.kind === 'Spread') { + state.referenceAndRecordEffects(freezeActions, element.place, Effect.ConditionallyMutateIterator, ValueReason.Other); + } + else if (element.kind === 'Identifier') { + state.referenceAndRecordEffects(freezeActions, element, Effect.Capture, ValueReason.Other); + } + else ; + } + state.initialize(instrValue, valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { + kind: 'funeffects', + }; + break; + } + case 'NewExpression': { + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.callee.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'ObjectExpression': { + const contextRefOperands = getContextRefOperand(state, instrValue); + const valueKind = contextRefOperands.length > 0 + ? { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set(contextRefOperands), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + for (const property of instrValue.properties) { + switch (property.kind) { + case 'ObjectProperty': { + if (property.key.kind === 'computed') { + state.referenceAndRecordEffects(freezeActions, property.key.name, Effect.Freeze, ValueReason.Other); + } + state.referenceAndRecordEffects(freezeActions, property.place, Effect.Capture, ValueReason.Other); + break; + } + case 'Spread': { + state.referenceAndRecordEffects(freezeActions, property.place, Effect.Capture, ValueReason.Other); + break; + } + default: { + assertExhaustive$1(property, `Unexpected property kind \`${property.kind}\``); + } + } + } + state.initialize(instrValue, valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'UnaryExpression': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Read, reason: ValueReason.Other }, + }; + break; + } + case 'UnsupportedNode': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'JsxExpression': { + if (instrValue.tag.kind === 'Identifier') { + state.referenceAndRecordEffects(freezeActions, instrValue.tag, Effect.Freeze, ValueReason.JsxCaptured); + } + if (instrValue.children !== null) { + for (const child of instrValue.children) { + state.referenceAndRecordEffects(freezeActions, child, Effect.Freeze, ValueReason.JsxCaptured); + } + } + for (const attr of instrValue.props) { + if (attr.kind === 'JsxSpreadAttribute') { + state.referenceAndRecordEffects(freezeActions, attr.argument, Effect.Freeze, ValueReason.JsxCaptured); + } + else { + state.referenceAndRecordEffects(freezeActions, attr.place, Effect.Freeze, ValueReason.JsxCaptured); + } + } + state.initialize(instrValue, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.ConditionallyMutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'JsxFragment': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.Freeze, + reason: ValueReason.Other, + }, + }; + break; + } + case 'TemplateLiteral': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Read, reason: ValueReason.Other }, + }; + break; + } + case 'RegExpLiteral': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.ConditionallyMutate, + reason: ValueReason.Other, + }, + }; + break; + } + case 'MetaProperty': { + if (instrValue.meta !== 'import' || instrValue.property !== 'meta') { + continuation = { kind: 'funeffects' }; + break; + } + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Global, + reason: new Set([ValueReason.Global]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'LoadGlobal': + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Global, + reason: new Set([ValueReason.Global]), + context: new Set(), + }, + effect: null, + }; + break; + case 'Debugger': + case 'JSXText': + case 'Primitive': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + let hasMutableOperand = false; + for (const operand of eachInstructionOperand(instr)) { + CompilerError.invariant(operand.effect !== Effect.Unknown, { + reason: 'Expected fn effects to be populated', + loc: operand.loc, + }); + state.referenceAndRecordEffects(freezeActions, operand, operand.effect, ValueReason.Other); + hasMutableOperand || (hasMutableOperand = isMutableEffect(operand.effect, operand.loc)); + } + state.initialize(instrValue, { + kind: hasMutableOperand ? ValueKind.Mutable : ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'TaggedTemplateExpression': { + const operands = [...eachInstructionValueOperand(instrValue)]; + if (operands.length !== 1) { + CompilerError.throwTodo({ + reason: 'Support tagged template expressions with interpolations', + loc: instrValue.loc, + }); + } + const signature = getFunctionCallSignature(env, instrValue.tag.identifier.type); + let calleeEffect = (_a = signature === null || signature === void 0 ? void 0 : signature.calleeEffect) !== null && _a !== void 0 ? _a : Effect.ConditionallyMutate; + const returnValueKind = signature !== null + ? { + kind: signature.returnValueKind, + reason: new Set([ + (_b = signature.returnValueReason) !== null && _b !== void 0 ? _b : ValueReason.KnownReturnSignature, + ]), + context: new Set(), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + state.referenceAndRecordEffects(freezeActions, instrValue.tag, calleeEffect, ValueReason.Other); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.ConditionallyMutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'CallExpression': { + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.callee.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'MethodCall': { + CompilerError.invariant(state.isDefined(instrValue.receiver), { + reason: '[InferReferenceEffects] Internal error: receiver of PropertyCall should have been defined by corresponding PropertyLoad', + description: null, + loc: instrValue.loc, + suggestions: null, + }); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.property.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'PropertyStore': { + const effect = state.kind(instrValue.object).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Store, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'PropertyDelete': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Mutate, reason: ValueReason.Other }, + }; + break; + } + case 'PropertyLoad': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, state.kind(instrValue.object)); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedStore': { + const effect = state.kind(instrValue.object).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Capture, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Store, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedDelete': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Mutate, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + state.initialize(instrValue, { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Mutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedLoad': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Read, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, state.kind(instrValue.object)); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'Await': { + state.initialize(instrValue, state.kind(instrValue.value)); + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.ConditionallyMutate, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.value); + continuation = { kind: 'funeffects' }; + break; + } + case 'TypeCastExpression': { + state.initialize(instrValue, state.kind(instrValue.value)); + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.value); + continuation = { kind: 'funeffects' }; + break; + } + case 'StartMemoize': + case 'FinishMemoize': { + for (const val of eachInstructionValueOperand(instrValue)) { + if (env.config.enablePreserveExistingMemoizationGuarantees) { + state.referenceAndRecordEffects(freezeActions, val, Effect.Freeze, ValueReason.Other); + } + else { + state.referenceAndRecordEffects(freezeActions, val, Effect.Read, ValueReason.Other); + } + } + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'LoadLocal': { + const lvalue = instr.lvalue; + state.referenceAndRecordEffects(freezeActions, instrValue.place, Effect.Capture, ValueReason.Other); + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.place); + continuation = { kind: 'funeffects' }; + break; + } + case 'LoadContext': { + state.referenceAndRecordEffects(freezeActions, instrValue.place, Effect.Capture, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + const valueKind = state.kind(instrValue.place); + state.initialize(instrValue, valueKind); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'DeclareLocal': { + const value = UndefinedValue; + state.initialize(value, instrValue.lvalue.kind === InstructionKind.Catch + ? { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + } + : { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, value); + continuation = { kind: 'funeffects' }; + break; + } + case 'DeclareContext': { + state.initialize(instrValue, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + const effect = state.isDefined(instrValue.lvalue) && + state.kind(instrValue.lvalue).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + state.alias(instrValue.lvalue, instrValue.value); + instrValue.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreLocal': { + const effect = state.isDefined(instrValue.lvalue.place) && + state.kind(instrValue.lvalue.place).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + state.alias(instrValue.lvalue.place, instrValue.value); + instrValue.lvalue.place.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreContext': { + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.ConditionallyMutate, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.lvalue.place, Effect.Mutate, ValueReason.Other); + const lvalue = instr.lvalue; + if (instrValue.lvalue.kind !== InstructionKind.Reassign) { + state.initialize(instrValue, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, instrValue); + } + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreGlobal': { + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.Capture, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'Destructure': { + let effect = Effect.Capture; + for (const place of eachPatternOperand(instrValue.lvalue.pattern)) { + if (state.isDefined(place) && + state.kind(place).kind === ValueKind.Context) { + effect = Effect.ConditionallyMutate; + break; + } + } + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + for (const place of eachPatternOperand(instrValue.lvalue.pattern)) { + state.alias(place, instrValue.value); + place.effect = Effect.Store; + } + continuation = { kind: 'funeffects' }; + break; + } + case 'GetIterator': { + const kind = state.kind(instrValue.collection).kind; + const isMutable = kind === ValueKind.Mutable || kind === ValueKind.Context; + let effect; + let valueKind; + const iterator = instrValue.collection.identifier; + if (!isMutable || + isArrayType(iterator) || + isMapType(iterator) || + isSetType(iterator)) { + effect = { + kind: Effect.Read, + reason: ValueReason.Other, + }; + valueKind = { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + } + else { + effect = { + kind: Effect.Capture, + reason: ValueReason.Other, + }; + valueKind = state.kind(instrValue.collection); + } + continuation = { + kind: 'initialize', + effect, + valueKind, + lvalueEffect: Effect.Store, + }; + break; + } + case 'IteratorNext': { + state.referenceAndRecordEffects(freezeActions, instrValue.iterator, Effect.ConditionallyMutateIterator, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.collection, Effect.Capture, ValueReason.Other); + state.initialize(instrValue, state.kind(instrValue.collection)); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'NextPropertyOf': { + continuation = { + kind: 'initialize', + effect: { kind: Effect.Read, reason: ValueReason.Other }, + lvalueEffect: Effect.Store, + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + }; + break; + } + default: { + assertExhaustive$1(instrValue, 'Unexpected instruction kind'); + } + } + if (continuation.kind === 'initialize') { + for (const operand of eachInstructionOperand(instr)) { + CompilerError.invariant(continuation.effect != null, { + reason: `effectKind must be set for instruction value \`${instrValue.kind}\``, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + state.referenceAndRecordEffects(freezeActions, operand, continuation.effect.kind, continuation.effect.reason); + } + state.initialize(instrValue, continuation.valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = (_c = continuation.lvalueEffect) !== null && _c !== void 0 ? _c : defaultLvalueEffect; + } + functionEffects.push(...inferInstructionFunctionEffects(env, state, instr)); + freezeActions.forEach(({ values, reason }) => state.freezeValues(values, reason)); + } + const terminalFreezeActions = []; + for (const operand of eachTerminalOperand(block.terminal)) { + let effect; + if (block.terminal.kind === 'return' || block.terminal.kind === 'throw') { + if (state.isDefined(operand) && + ((operand.identifier.type.kind === 'Function' && + state.isFunctionExpression) || + state.kind(operand).kind === ValueKind.Context)) { + effect = Effect.ConditionallyMutate; + } + else { + effect = Effect.Freeze; + } + } + else { + effect = Effect.Read; + } + state.referenceAndRecordEffects(terminalFreezeActions, operand, effect, ValueReason.Other); + } + functionEffects.push(...inferTerminalFunctionEffects(state, block)); + terminalFreezeActions.forEach(({ values, reason }) => state.freezeValues(values, reason)); +} +function getContextRefOperand(state, instrValue) { + const result = []; + for (const place of eachInstructionValueOperand(instrValue)) { + if (state.isDefined(place) && + state.kind(place).kind === ValueKind.Context) { + result.push(place); + } + } + return result; +} +function getFunctionCallSignature(env, type) { + if (type.kind !== 'Function') { + return null; + } + return env.getFunctionSignature(type); +} +function getFunctionEffects(fn, sig) { + const results = []; + for (let i = 0; i < fn.args.length; i++) { + const arg = fn.args[i]; + if (i < sig.positionalParams.length) { + if (arg.kind === 'Identifier') { + results.push(sig.positionalParams[i]); + } + else { + return null; + } + } + else if (sig.restParam !== null) { + results.push(sig.restParam); + } + else { + return null; + } + } + return results; +} +function isKnownMutableEffect(effect) { + switch (effect) { + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + return true; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: GeneratedSource, + suggestions: null, + }); + } + case Effect.Read: + case Effect.Capture: + case Effect.Freeze: { + return false; + } + default: { + assertExhaustive$1(effect, `Unexpected effect \`${effect}\``); + } + } +} +function areArgumentsImmutableAndNonMutating(state, args) { + for (const arg of args) { + if (arg.kind === 'Identifier' && arg.identifier.type.kind === 'Function') { + const fnShape = state.env.getFunctionSignature(arg.identifier.type); + if (fnShape != null) { + return (!fnShape.positionalParams.some(isKnownMutableEffect) && + (fnShape.restParam == null || + !isKnownMutableEffect(fnShape.restParam))); + } + } + const place = arg.kind === 'Identifier' ? arg : arg.place; + const kind = state.kind(place).kind; + switch (kind) { + case ValueKind.Primitive: + case ValueKind.Frozen: { + break; + } + default: { + return false; + } + } + const values = state.values(place); + for (const value of values) { + if (value.kind === 'FunctionExpression' && + value.loweredFunc.func.params.some(param => { + const place = param.kind === 'Identifier' ? param : param.place; + const range = place.identifier.mutableRange; + return range.end > range.start + 1; + })) { + return false; + } + } + } + return true; +} +function getArgumentEffect(signatureEffect, arg) { + if (signatureEffect != null) { + if (arg.kind === 'Identifier') { + return signatureEffect; + } + else if (signatureEffect === Effect.Mutate || + signatureEffect === Effect.ConditionallyMutate) { + return signatureEffect; + } + else { + if (signatureEffect === Effect.Freeze) { + CompilerError.throwTodo({ + reason: 'Support spread syntax for hook arguments', + loc: arg.place.loc, + }); + } + return Effect.ConditionallyMutateIterator; + } + } + else { + return Effect.ConditionallyMutate; + } +} +function inferCallEffects(state, instr, freezeActions, signature) { + var _a; + const instrValue = instr.value; + const returnValueKind = signature !== null + ? { + kind: signature.returnValueKind, + reason: new Set([ + (_a = signature.returnValueReason) !== null && _a !== void 0 ? _a : ValueReason.KnownReturnSignature, + ]), + context: new Set(), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + if (instrValue.kind === 'MethodCall' && + signature !== null && + signature.mutableOnlyIfOperandsAreMutable && + areArgumentsImmutableAndNonMutating(state, instrValue.args)) { + for (const arg of instrValue.args) { + const place = arg.kind === 'Identifier' ? arg : arg.place; + state.referenceAndRecordEffects(freezeActions, place, Effect.Read, ValueReason.Other); + } + state.referenceAndRecordEffects(freezeActions, instrValue.receiver, Effect.Capture, ValueReason.Other); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = + instrValue.receiver.effect === Effect.Capture + ? Effect.Store + : Effect.ConditionallyMutate; + return; + } + const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null; + let hasCaptureArgument = false; + for (let i = 0; i < instrValue.args.length; i++) { + const arg = instrValue.args[i]; + const place = arg.kind === 'Identifier' ? arg : arg.place; + state.referenceAndRecordEffects(freezeActions, place, getArgumentEffect(effects != null ? effects[i] : null, arg), ValueReason.Other); + hasCaptureArgument || (hasCaptureArgument = place.effect === Effect.Capture); + } + const callee = instrValue.kind === 'MethodCall' ? instrValue.receiver : instrValue.callee; + if (signature !== null) { + state.referenceAndRecordEffects(freezeActions, callee, signature.calleeEffect, ValueReason.Other); + } + else { + state.referenceAndRecordEffects(freezeActions, callee, instrValue.kind === 'NewExpression' + ? Effect.Read + : Effect.ConditionallyMutate, ValueReason.Other); + } + hasCaptureArgument || (hasCaptureArgument = callee.effect === Effect.Capture); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = hasCaptureArgument + ? Effect.Store + : Effect.ConditionallyMutate; +} + +function pruneNonEscapingScopes(fn) { + const state = new State(fn.env); + for (const param of fn.params) { + if (param.kind === 'Identifier') { + state.declare(param.identifier.declarationId); + } + else { + state.declare(param.place.identifier.declarationId); + } + } + visitReactiveFunction(fn, new CollectDependenciesVisitor(fn.env, state), []); + const memoized = computeMemoizedIdentifiers(state); + visitReactiveFunction(fn, new PruneScopesTransform(), memoized); +} +var MemoizationLevel; +(function (MemoizationLevel) { + MemoizationLevel["Memoized"] = "Memoized"; + MemoizationLevel["Conditional"] = "Conditional"; + MemoizationLevel["Unmemoized"] = "Unmemoized"; + MemoizationLevel["Never"] = "Never"; +})(MemoizationLevel || (MemoizationLevel = {})); +function joinAliases(kind1, kind2) { + if (kind1 === MemoizationLevel.Memoized || + kind2 === MemoizationLevel.Memoized) { + return MemoizationLevel.Memoized; + } + else if (kind1 === MemoizationLevel.Conditional || + kind2 === MemoizationLevel.Conditional) { + return MemoizationLevel.Conditional; + } + else if (kind1 === MemoizationLevel.Unmemoized || + kind2 === MemoizationLevel.Unmemoized) { + return MemoizationLevel.Unmemoized; + } + else { + return MemoizationLevel.Never; + } +} +class State { + constructor(env) { + this.definitions = new Map(); + this.identifiers = new Map(); + this.scopes = new Map(); + this.escapingValues = new Set(); + this.env = env; + } + declare(id) { + this.identifiers.set(id, { + level: MemoizationLevel.Never, + memoized: false, + dependencies: new Set(), + scopes: new Set(), + seen: false, + }); + } + visitOperand(id, place, identifier) { + const scope = getPlaceScope(id, place); + if (scope !== null) { + let node = this.scopes.get(scope.id); + if (node === undefined) { + node = { + dependencies: [...scope.dependencies].map(dep => dep.identifier.declarationId), + seen: false, + }; + this.scopes.set(scope.id, node); + } + const identifierNode = this.identifiers.get(identifier); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: `[${id}] operand=${printPlace(place)} for identifier declaration ${identifier}`, + loc: place.loc, + suggestions: null, + }); + identifierNode.scopes.add(scope.id); + } + } +} +function computeMemoizedIdentifiers(state) { + const memoized = new Set(); + function visit(id, forceMemoize = false) { + const node = state.identifiers.get(id); + CompilerError.invariant(node !== undefined, { + reason: `Expected a node for all identifiers, none found for \`${id}\``, + description: null, + loc: null, + suggestions: null, + }); + if (node.seen) { + return node.memoized; + } + node.seen = true; + node.memoized = false; + let hasMemoizedDependency = false; + for (const dep of node.dependencies) { + const isDepMemoized = visit(dep); + hasMemoizedDependency || (hasMemoizedDependency = isDepMemoized); + } + if (node.level === MemoizationLevel.Memoized || + (node.level === MemoizationLevel.Conditional && + (hasMemoizedDependency || forceMemoize)) || + (node.level === MemoizationLevel.Unmemoized && forceMemoize)) { + node.memoized = true; + memoized.add(id); + for (const scope of node.scopes) { + forceMemoizeScopeDependencies(scope); + } + } + return node.memoized; + } + function forceMemoizeScopeDependencies(id) { + const node = state.scopes.get(id); + CompilerError.invariant(node !== undefined, { + reason: 'Expected a node for all scopes', + description: null, + loc: null, + suggestions: null, + }); + if (node.seen) { + return; + } + node.seen = true; + for (const dep of node.dependencies) { + visit(dep, true); + } + return; + } + for (const value of state.escapingValues) { + visit(value); + } + return memoized; +} +function computePatternLValues(pattern) { + const lvalues = []; + switch (pattern.kind) { + case 'ArrayPattern': { + for (const item of pattern.items) { + if (item.kind === 'Identifier') { + lvalues.push({ place: item, level: MemoizationLevel.Conditional }); + } + else if (item.kind === 'Spread') { + lvalues.push({ place: item.place, level: MemoizationLevel.Memoized }); + } + } + break; + } + case 'ObjectPattern': { + for (const property of pattern.properties) { + if (property.kind === 'ObjectProperty') { + lvalues.push({ + place: property.place, + level: MemoizationLevel.Conditional, + }); + } + else { + lvalues.push({ + place: property.place, + level: MemoizationLevel.Memoized, + }); + } + } + break; + } + default: { + assertExhaustive$1(pattern, `Unexpected pattern kind \`${pattern.kind}\``); + } + } + return lvalues; +} +class CollectDependenciesVisitor extends ReactiveFunctionVisitor { + constructor(env, state) { + super(); + this.env = env; + this.state = state; + this.options = { + memoizeJsxElements: !this.env.config.enableForest, + forceMemoizePrimitives: this.env.config.enableForest, + }; + } + computeMemoizationInputs(value, lvalue) { + const env = this.env; + const options = this.options; + switch (value.kind) { + case 'ConditionalExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [ + ...this.computeMemoizationInputs(value.consequent, null).rvalues, + ...this.computeMemoizationInputs(value.alternate, null).rvalues, + ], + }; + } + case 'LogicalExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [ + ...this.computeMemoizationInputs(value.left, null).rvalues, + ...this.computeMemoizationInputs(value.right, null).rvalues, + ], + }; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitValueForMemoization(instr.id, instr.value, instr.lvalue); + } + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: this.computeMemoizationInputs(value.value, null).rvalues, + }; + } + case 'JsxExpression': { + const operands = []; + if (value.tag.kind === 'Identifier') { + operands.push(value.tag); + } + for (const prop of value.props) { + if (prop.kind === 'JsxAttribute') { + operands.push(prop.place); + } + else { + operands.push(prop.argument); + } + } + if (value.children !== null) { + for (const child of value.children) { + operands.push(child); + } + } + const level = options.memoizeJsxElements + ? MemoizationLevel.Memoized + : MemoizationLevel.Unmemoized; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: operands, + }; + } + case 'JsxFragment': { + const level = options.memoizeJsxElements + ? MemoizationLevel.Memoized + : MemoizationLevel.Unmemoized; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: value.children, + }; + } + case 'NextPropertyOf': + case 'StartMemoize': + case 'FinishMemoize': + case 'Debugger': + case 'ComputedDelete': + case 'PropertyDelete': + case 'LoadGlobal': + case 'MetaProperty': + case 'TemplateLiteral': + case 'Primitive': + case 'JSXText': + case 'BinaryExpression': + case 'UnaryExpression': { + const level = options.forceMemoizePrimitives + ? MemoizationLevel.Memoized + : MemoizationLevel.Never; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: [], + }; + } + case 'Await': + case 'TypeCastExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.value], + }; + } + case 'IteratorNext': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.iterator, value.collection], + }; + } + case 'GetIterator': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.collection], + }; + } + case 'LoadLocal': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.place], + }; + } + case 'LoadContext': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.place], + }; + } + case 'DeclareContext': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Memoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [], + }; + } + case 'DeclareLocal': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Unmemoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [], + }; + } + case 'PrefixUpdate': + case 'PostfixUpdate': { + const lvalues = [ + { place: value.lvalue, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreLocal': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreContext': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Memoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreGlobal': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'Destructure': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + lvalues.push(...computePatternLValues(value.lvalue.pattern)); + return { + lvalues: lvalues, + rvalues: [value.value], + }; + } + case 'ComputedLoad': + case 'PropertyLoad': { + const level = options.forceMemoizePrimitives + ? MemoizationLevel.Memoized + : MemoizationLevel.Conditional; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: [value.object], + }; + } + case 'ComputedStore': { + const lvalues = [ + { place: value.object, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'OptionalExpression': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues: lvalues, + rvalues: [ + ...this.computeMemoizationInputs(value.value, null).rvalues, + ], + }; + } + case 'TaggedTemplateExpression': { + const signature = getFunctionCallSignature(env, value.tag.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'CallExpression': { + const signature = getFunctionCallSignature(env, value.callee.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'MethodCall': { + const signature = getFunctionCallSignature(env, value.property.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'RegExpLiteral': + case 'ObjectMethod': + case 'FunctionExpression': + case 'ArrayExpression': + case 'NewExpression': + case 'ObjectExpression': + case 'PropertyStore': { + const operands = [...eachReactiveValueOperand(value)]; + const lvalues = operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized })); + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + return { + lvalues, + rvalues: operands, + }; + } + case 'UnsupportedNode': { + CompilerError.invariant(false, { + reason: `Unexpected unsupported node`, + description: null, + loc: value.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(value, `Unexpected value kind \`${value.kind}\``); + } + } + } + visitValueForMemoization(id, value, lvalue) { + var _a, _b, _c; + const state = this.state; + const aliasing = this.computeMemoizationInputs(value, lvalue); + for (const operand of aliasing.rvalues) { + const operandId = (_a = state.definitions.get(operand.identifier.declarationId)) !== null && _a !== void 0 ? _a : operand.identifier.declarationId; + state.visitOperand(id, operand, operandId); + } + for (const { place: lvalue, level } of aliasing.lvalues) { + const lvalueId = (_b = state.definitions.get(lvalue.identifier.declarationId)) !== null && _b !== void 0 ? _b : lvalue.identifier.declarationId; + let node = state.identifiers.get(lvalueId); + if (node === undefined) { + node = { + level: MemoizationLevel.Never, + memoized: false, + dependencies: new Set(), + scopes: new Set(), + seen: false, + }; + state.identifiers.set(lvalueId, node); + } + node.level = joinAliases(node.level, level); + for (const operand of aliasing.rvalues) { + const operandId = (_c = state.definitions.get(operand.identifier.declarationId)) !== null && _c !== void 0 ? _c : operand.identifier.declarationId; + if (operandId === lvalueId) { + continue; + } + node.dependencies.add(operandId); + } + state.visitOperand(id, lvalue, lvalueId); + } + if (value.kind === 'LoadLocal' && lvalue !== null) { + state.definitions.set(lvalue.identifier.declarationId, value.place.identifier.declarationId); + } + else if (value.kind === 'CallExpression' || value.kind === 'MethodCall') { + let callee = value.kind === 'CallExpression' ? value.callee : value.property; + if (getHookKind(state.env, callee.identifier) != null) { + const signature = getFunctionCallSignature(this.env, callee.identifier.type); + if (signature && signature.noAlias === true) { + return; + } + for (const operand of value.args) { + const place = operand.kind === 'Spread' ? operand.place : operand; + state.escapingValues.add(place.identifier.declarationId); + } + } + } + } + visitInstruction(instruction, _scopes) { + this.visitValueForMemoization(instruction.id, instruction.value, instruction.lvalue); + } + visitTerminal(stmt, scopes) { + this.traverseTerminal(stmt, scopes); + if (stmt.terminal.kind === 'return') { + this.state.escapingValues.add(stmt.terminal.value.identifier.declarationId); + const identifierNode = this.state.identifiers.get(stmt.terminal.value.identifier.declarationId); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: null, + loc: stmt.terminal.loc, + suggestions: null, + }); + for (const scope of scopes) { + identifierNode.scopes.add(scope.id); + } + } + } + visitScope(scope, scopes) { + for (const reassignment of scope.scope.reassignments) { + const identifierNode = this.state.identifiers.get(reassignment.declarationId); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: null, + loc: reassignment.loc, + suggestions: null, + }); + for (const scope of scopes) { + identifierNode.scopes.add(scope.id); + } + identifierNode.scopes.add(scope.scope.id); + } + this.traverseScope(scope, [...scopes, scope.scope]); + } +} +class PruneScopesTransform extends ReactiveFunctionTransform { + constructor() { + super(...arguments); + this.prunedScopes = new Set(); + this.reassignments = new Map(); + } + transformScope(scopeBlock, state) { + this.visitScope(scopeBlock, state); + if ((scopeBlock.scope.declarations.size === 0 && + scopeBlock.scope.reassignments.size === 0) || + scopeBlock.scope.earlyReturnValue !== null) { + return { kind: 'keep' }; + } + const hasMemoizedOutput = Array.from(scopeBlock.scope.declarations.values()).some(decl => state.has(decl.identifier.declarationId)) || + Array.from(scopeBlock.scope.reassignments).some(identifier => state.has(identifier.declarationId)); + if (hasMemoizedOutput) { + return { kind: 'keep' }; + } + else { + this.prunedScopes.add(scopeBlock.scope.id); + return { + kind: 'replace-many', + value: scopeBlock.instructions, + }; + } + } + transformInstruction(instruction, state) { + var _a; + this.traverseInstruction(instruction, state); + const value = instruction.value; + if (value.kind === 'StoreLocal' && value.lvalue.kind === 'Reassign') { + const ids = getOrInsertDefault(this.reassignments, value.lvalue.place.identifier.declarationId, new Set()); + ids.add(value.value.identifier); + } + else if (value.kind === 'FinishMemoize') { + let decls; + if (value.decl.identifier.scope == null) { + decls = (_a = this.reassignments.get(value.decl.identifier.declarationId)) !== null && _a !== void 0 ? _a : [ + value.decl.identifier, + ]; + } + else { + decls = [value.decl.identifier]; + } + if ([...decls].every(decl => decl.scope == null || this.prunedScopes.has(decl.scope.id))) { + value.pruned = true; + } + } + return { kind: 'keep' }; + } +} + +let Visitor$7 = class Visitor extends ReactiveFunctionVisitor { + visitLValue(id, lvalue, state) { + this.visitPlace(id, lvalue, state); + } + visitPlace(_id, place, state) { + if (place.reactive) { + state.add(place.identifier.id); + } + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + for (const [id, decl] of scopeBlock.scope.declarations) { + if (!isPrimitiveType(decl.identifier) && + !isStableRefType(decl.identifier, state)) { + state.add(id); + } + } + } +}; +function isStableRefType(identifier, reactiveIdentifiers) { + return isUseRefType(identifier) && !reactiveIdentifiers.has(identifier.id); +} +function collectReactiveIdentifiers(fn) { + const visitor = new Visitor$7(); + const state = new Set(); + visitReactiveFunction(fn, visitor, state); + return state; +} + +function pruneNonReactiveDependencies(fn) { + const reactiveIdentifiers = collectReactiveIdentifiers(fn); + visitReactiveFunction(fn, new Visitor$6(), reactiveIdentifiers); +} +let Visitor$6 = class Visitor extends ReactiveFunctionVisitor { + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + const { lvalue, value } = instruction; + switch (value.kind) { + case 'LoadLocal': { + if (lvalue !== null && state.has(value.place.identifier.id)) { + state.add(lvalue.identifier.id); + } + break; + } + case 'StoreLocal': { + if (state.has(value.value.identifier.id)) { + state.add(value.lvalue.place.identifier.id); + if (lvalue !== null) { + state.add(lvalue.identifier.id); + } + } + break; + } + case 'Destructure': { + if (state.has(value.value.identifier.id)) { + for (const lvalue of eachPatternOperand(value.lvalue.pattern)) { + if (isStableType(lvalue.identifier)) { + continue; + } + state.add(lvalue.identifier.id); + } + if (lvalue !== null) { + state.add(lvalue.identifier.id); + } + } + break; + } + case 'PropertyLoad': { + if (lvalue !== null && + state.has(value.object.identifier.id) && + !isStableType(lvalue.identifier)) { + state.add(lvalue.identifier.id); + } + break; + } + case 'ComputedLoad': { + if (lvalue !== null && + (state.has(value.object.identifier.id) || + state.has(value.property.identifier.id))) { + state.add(lvalue.identifier.id); + } + break; + } + } + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + for (const dep of scopeBlock.scope.dependencies) { + const isReactive = state.has(dep.identifier.id); + if (!isReactive) { + scopeBlock.scope.dependencies.delete(dep); + } + } + if (scopeBlock.scope.dependencies.size !== 0) { + for (const [, declaration] of scopeBlock.scope.declarations) { + state.add(declaration.identifier.id); + } + for (const reassignment of scopeBlock.scope.reassignments) { + state.add(reassignment.id); + } + } + } +}; + +function pruneUnusedLValues(fn) { + const lvalues = new Map(); + visitReactiveFunction(fn, new Visitor$5(), lvalues); + for (const [, instr] of lvalues) { + instr.lvalue = null; + } +} +let Visitor$5 = class Visitor extends ReactiveFunctionVisitor { + visitPlace(id, place, state) { + state.delete(place.identifier.declarationId); + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + if (instruction.lvalue !== null && + instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.declarationId, instruction); + } + } +}; + +function pruneUnusedLabels(fn) { + const labels = new Set(); + visitReactiveFunction(fn, new Transform$2(), labels); +} +let Transform$2 = class Transform extends ReactiveFunctionTransform { + transformTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + const { terminal } = stmt; + if ((terminal.kind === 'break' || terminal.kind === 'continue') && + terminal.targetKind === 'labeled') { + state.add(terminal.target); + } + const isReachableLabel = stmt.label !== null && state.has(stmt.label.id); + if (stmt.terminal.kind === 'label' && !isReachableLabel) { + const block = [...stmt.terminal.block]; + const last = block.at(-1); + if (last !== undefined && + last.kind === 'terminal' && + last.terminal.kind === 'break' && + last.terminal.target === null) { + block.pop(); + } + return { kind: 'replace-many', value: block }; + } + else { + if (!isReachableLabel && stmt.label != null) { + stmt.label.implicit = true; + } + return { kind: 'keep' }; + } + } +}; + +function pruneUnusedScopes(fn) { + visitReactiveFunction(fn, new Transform$1(), { + hasReturnStatement: false, + }); +} +let Transform$1 = class Transform extends ReactiveFunctionTransform { + visitTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + if (stmt.terminal.kind === 'return') { + state.hasReturnStatement = true; + } + } + transformScope(scopeBlock, _state) { + const scopeState = { hasReturnStatement: false }; + this.visitScope(scopeBlock, scopeState); + if (!scopeState.hasReturnStatement && + scopeBlock.scope.reassignments.size === 0 && + (scopeBlock.scope.declarations.size === 0 || + !hasOwnDeclaration(scopeBlock))) { + return { + kind: 'replace', + value: { + kind: 'pruned-scope', + scope: scopeBlock.scope, + instructions: scopeBlock.instructions, + }, + }; + } + else { + return { kind: 'keep' }; + } + } +}; +function hasOwnDeclaration(block) { + for (const declaration of block.scope.declarations.values()) { + if (declaration.scope.id === block.scope.id) { + return true; + } + } + return false; +} + +function collectReferencedGlobals(fn) { + const identifiers = new Set(); + visitReactiveFunction(fn, new Visitor$4(), identifiers); + return identifiers; +} +let Visitor$4 = class Visitor extends ReactiveFunctionVisitor { + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + else if (value.kind === 'LoadGlobal') { + state.add(value.binding.name); + } + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +}; + +var _Scopes_instances, _Scopes_seen, _Scopes_stack, _Scopes_globals, _Scopes_programContext, _Scopes_lookup; +function renameVariables(fn) { + const globals = collectReferencedGlobals(fn); + const scopes = new Scopes(globals, fn.env.programContext); + renameVariablesImpl(fn, new Visitor$3(), scopes); + return new Set([...scopes.names, ...globals]); +} +function renameVariablesImpl(fn, visitor, scopes) { + scopes.enter(() => { + for (const param of fn.params) { + if (param.kind === 'Identifier') { + scopes.visit(param.identifier); + } + else { + scopes.visit(param.place.identifier); + } + } + visitReactiveFunction(fn, visitor, scopes); + }); +} +let Visitor$3 = class Visitor extends ReactiveFunctionVisitor { + visitParam(place, state) { + state.visit(place.identifier); + } + visitLValue(_id, lvalue, state) { + state.visit(lvalue.identifier); + } + visitPlace(id, place, state) { + state.visit(place.identifier); + } + visitBlock(block, state) { + state.enter(() => { + this.traverseBlock(block, state); + }); + } + visitPrunedScope(scopeBlock, state) { + this.traverseBlock(scopeBlock.instructions, state); + } + visitScope(scope, state) { + for (const [_, declaration] of scope.scope.declarations) { + state.visit(declaration.identifier); + } + this.traverseScope(scope, state); + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + } + visitReactiveFunctionValue(_id, _dependencies, _fn, _state) { + renameVariablesImpl(_fn, this, _state); + } +}; +class Scopes { + constructor(globals, programContext) { + _Scopes_instances.add(this); + _Scopes_seen.set(this, new Map()); + _Scopes_stack.set(this, [new Map()]); + _Scopes_globals.set(this, void 0); + _Scopes_programContext.set(this, void 0); + this.names = new Set(); + __classPrivateFieldSet(this, _Scopes_globals, globals, "f"); + __classPrivateFieldSet(this, _Scopes_programContext, programContext, "f"); + } + visit(identifier) { + const originalName = identifier.name; + if (originalName === null) { + return; + } + const mappedName = __classPrivateFieldGet(this, _Scopes_seen, "f").get(identifier.declarationId); + if (mappedName !== undefined) { + identifier.name = mappedName; + return; + } + let name = originalName.value; + let id = 0; + if (isPromotedTemporary(originalName.value)) { + name = `t${id++}`; + } + else if (isPromotedJsxTemporary(originalName.value)) { + name = `T${id++}`; + } + while (__classPrivateFieldGet(this, _Scopes_instances, "m", _Scopes_lookup).call(this, name) !== null || __classPrivateFieldGet(this, _Scopes_globals, "f").has(name)) { + if (isPromotedTemporary(originalName.value)) { + name = `t${id++}`; + } + else if (isPromotedJsxTemporary(originalName.value)) { + name = `T${id++}`; + } + else { + name = `${originalName.value}$${id++}`; + } + } + __classPrivateFieldGet(this, _Scopes_programContext, "f").addNewReference(name); + const identifierName = makeIdentifierName(name); + identifier.name = identifierName; + __classPrivateFieldGet(this, _Scopes_seen, "f").set(identifier.declarationId, identifierName); + __classPrivateFieldGet(this, _Scopes_stack, "f").at(-1).set(identifierName.value, identifier.declarationId); + this.names.add(identifierName.value); + } + enter(fn) { + const next = new Map(); + __classPrivateFieldGet(this, _Scopes_stack, "f").push(next); + fn(); + const last = __classPrivateFieldGet(this, _Scopes_stack, "f").pop(); + CompilerError.invariant(last === next, { + reason: 'Mismatch push/pop calls', + description: null, + loc: null, + suggestions: null, + }); + } +} +_Scopes_seen = new WeakMap(), _Scopes_stack = new WeakMap(), _Scopes_globals = new WeakMap(), _Scopes_programContext = new WeakMap(), _Scopes_instances = new WeakSet(), _Scopes_lookup = function _Scopes_lookup(name) { + for (let i = __classPrivateFieldGet(this, _Scopes_stack, "f").length - 1; i >= 0; i--) { + const scope = __classPrivateFieldGet(this, _Scopes_stack, "f")[i]; + const entry = scope.get(name); + if (entry !== undefined) { + return entry; + } + } + return null; +}; + +function stabilizeBlockIds(fn) { + const referenced = new Set(); + visitReactiveFunction(fn, new CollectReferencedLabels(), referenced); + const mappings = new Map(); + for (const blockId of referenced) { + mappings.set(blockId, makeBlockId(mappings.size)); + } + visitReactiveFunction(fn, new RewriteBlockIds(), mappings); +} +class CollectReferencedLabels extends ReactiveFunctionVisitor { + visitScope(scope, state) { + const { earlyReturnValue } = scope.scope; + if (earlyReturnValue != null) { + state.add(earlyReturnValue.label); + } + this.traverseScope(scope, state); + } + visitTerminal(stmt, state) { + if (stmt.label != null) { + if (!stmt.label.implicit) { + state.add(stmt.label.id); + } + } + this.traverseTerminal(stmt, state); + } +} +class RewriteBlockIds extends ReactiveFunctionVisitor { + visitScope(scope, state) { + const { earlyReturnValue } = scope.scope; + if (earlyReturnValue != null) { + const rewrittenId = getOrInsertDefault(state, earlyReturnValue.label, state.size); + earlyReturnValue.label = makeBlockId(rewrittenId); + } + this.traverseScope(scope, state); + } + visitTerminal(stmt, state) { + if (stmt.label != null) { + const rewrittenId = getOrInsertDefault(state, stmt.label.id, state.size); + stmt.label.id = makeBlockId(rewrittenId); + } + const terminal = stmt.terminal; + if (terminal.kind === 'break' || terminal.kind === 'continue') { + const rewrittenId = getOrInsertDefault(state, terminal.target, state.size); + terminal.target = makeBlockId(rewrittenId); + } + this.traverseTerminal(stmt, state); + } +} + +function inferAliases(func) { + const aliases = new DisjointSet(); + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + inferInstr(instr, aliases); + } + } + return aliases; +} +function inferInstr(instr, aliases) { + const { lvalue, value: instrValue } = instr; + let alias = null; + switch (instrValue.kind) { + case 'LoadLocal': + case 'LoadContext': { + if (isPrimitiveType(instrValue.place.identifier)) { + return; + } + alias = instrValue.place; + break; + } + case 'StoreLocal': + case 'StoreContext': { + alias = instrValue.value; + break; + } + case 'Destructure': { + alias = instrValue.value; + break; + } + case 'ComputedLoad': + case 'PropertyLoad': { + alias = instrValue.object; + break; + } + case 'TypeCastExpression': { + alias = instrValue.value; + break; + } + default: + return; + } + aliases.union([lvalue.identifier, alias.identifier]); +} + +function inferAliasForPhis(func, aliases) { + var _a, _b; + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + const isPhiMutatedAfterCreation = phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id); + if (isPhiMutatedAfterCreation) { + for (const [, operand] of phi.operands) { + aliases.union([phi.place.identifier, operand.identifier]); + } + } + } + } +} + +function inferAliasForStores(func, aliases) { + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + const isStore = lvalue.effect === Effect.Store || + ![...eachInstructionValueOperand(value)].every(operand => operand.effect !== Effect.Store); + if (!isStore) { + continue; + } + for (const operand of eachInstructionLValue(instr)) { + maybeAlias(aliases, lvalue, operand, instr.id); + } + for (const operand of eachInstructionValueOperand(value)) { + if (operand.effect === Effect.Capture || + operand.effect === Effect.Store) { + maybeAlias(aliases, lvalue, operand, instr.id); + } + } + } + } +} +function maybeAlias(aliases, lvalue, rvalue, id) { + if (lvalue.identifier.mutableRange.end > id + 1 || + rvalue.identifier.mutableRange.end > id) { + aliases.union([lvalue.identifier, rvalue.identifier]); + } +} + +function infer$1(place, instrId) { + if (!isRefOrRefValue(place.identifier)) { + place.identifier.mutableRange.end = makeInstructionId(instrId + 1); + } +} +function inferPlace(place, instrId, inferMutableRangeForStores) { + switch (place.effect) { + case Effect.Unknown: { + throw new Error(`Found an unknown place ${printPlace(place)}}!`); + } + case Effect.Capture: + case Effect.Read: + case Effect.Freeze: + return; + case Effect.Store: + if (inferMutableRangeForStores) { + infer$1(place, instrId); + } + return; + case Effect.ConditionallyMutateIterator: { + const identifier = place.identifier; + if (!isArrayType(identifier) && + !isSetType(identifier) && + !isMapType(identifier)) { + infer$1(place, instrId); + } + return; + } + case Effect.ConditionallyMutate: + case Effect.Mutate: { + infer$1(place, instrId); + return; + } + default: + assertExhaustive$1(place.effect, `Unexpected ${printPlace(place)} effect`); + } +} +function inferMutableLifetimes(func, inferMutableRangeForStores) { + var _a, _b; + const contextVariableDeclarationInstructions = new Map(); + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + const isPhiMutatedAfterCreation = phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id); + if (inferMutableRangeForStores && + isPhiMutatedAfterCreation && + phi.place.identifier.mutableRange.start === 0) { + for (const [, operand] of phi.operands) { + if (phi.place.identifier.mutableRange.start === 0) { + phi.place.identifier.mutableRange.start = + operand.identifier.mutableRange.start; + } + else { + phi.place.identifier.mutableRange.start = makeInstructionId(Math.min(phi.place.identifier.mutableRange.start, operand.identifier.mutableRange.start)); + } + } + } + } + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + const lvalueId = operand.identifier; + lvalueId.mutableRange.start = instr.id; + lvalueId.mutableRange.end = makeInstructionId(instr.id + 1); + } + for (const operand of eachInstructionOperand(instr)) { + inferPlace(operand, instr.id, inferMutableRangeForStores); + } + if (instr.value.kind === 'DeclareContext' || + (instr.value.kind === 'StoreContext' && + instr.value.lvalue.kind !== InstructionKind.Reassign && + !contextVariableDeclarationInstructions.has(instr.value.lvalue.place.identifier))) { + contextVariableDeclarationInstructions.set(instr.value.lvalue.place.identifier, instr.id); + } + else if (instr.value.kind === 'StoreContext') { + const declaration = contextVariableDeclarationInstructions.get(instr.value.lvalue.place.identifier); + if (declaration != null && + !isRefOrRefValue(instr.value.lvalue.place.identifier)) { + const range = instr.value.lvalue.place.identifier.mutableRange; + if (range.start === 0) { + range.start = declaration; + } + else { + range.start = makeInstructionId(Math.min(range.start, declaration)); + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + inferPlace(operand, block.terminal.id, inferMutableRangeForStores); + } + } +} + +function inferMutableRangesForAlias(_fn, aliases) { + const aliasSets = aliases.buildSets(); + for (const aliasSet of aliasSets) { + const mutatingIdentifiers = [...aliasSet].filter(id => id.mutableRange.end - id.mutableRange.start > 1 && !isRefOrRefValue(id)); + if (mutatingIdentifiers.length > 0) { + let lastMutatingInstructionId = 0; + for (const id of mutatingIdentifiers) { + if (id.mutableRange.end > lastMutatingInstructionId) { + lastMutatingInstructionId = id.mutableRange.end; + } + } + for (const alias of aliasSet) { + if (alias.mutableRange.end < lastMutatingInstructionId && + !isRefOrRefValue(alias)) { + alias.mutableRange.end = lastMutatingInstructionId; + } + } + } + } +} + +function inferTryCatchAliases(fn, aliases) { + const handlerParams = new Map(); + for (const [_, block] of fn.body.blocks) { + if (block.terminal.kind === 'try' && + block.terminal.handlerBinding !== null) { + handlerParams.set(block.terminal.handler, block.terminal.handlerBinding.identifier); + } + else if (block.terminal.kind === 'maybe-throw') { + const handlerParam = handlerParams.get(block.terminal.handler); + if (handlerParam === undefined) { + continue; + } + for (const instr of block.instructions) { + aliases.union([handlerParam, instr.lvalue.identifier]); + } + } + } +} + +function inferMutableRanges(ir) { + inferMutableLifetimes(ir, false); + const aliases = inferAliases(ir); + inferTryCatchAliases(ir, aliases); + let prevAliases = aliases.canonicalize(); + while (true) { + inferMutableRangesForAlias(ir, aliases); + inferAliasForStores(ir, aliases); + inferAliasForPhis(ir, aliases); + const nextAliases = aliases.canonicalize(); + if (areEqualMaps(prevAliases, nextAliases)) { + break; + } + prevAliases = nextAliases; + } + inferMutableLifetimes(ir, true); + prevAliases = aliases.canonicalize(); + while (true) { + inferMutableRangesForAlias(ir, aliases); + inferAliasForPhis(ir, aliases); + const nextAliases = aliases.canonicalize(); + if (areEqualMaps(prevAliases, nextAliases)) { + break; + } + prevAliases = nextAliases; + } +} +function areEqualMaps(a, b) { + if (a.size !== b.size) { + return false; + } + for (const [key, value] of a) { + if (!b.has(key)) { + return false; + } + if (b.get(key) !== value) { + return false; + } + } + return true; +} + +function analyseFunctions(func) { + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'ObjectMethod': + case 'FunctionExpression': { + lower(instr.value.loweredFunc.func); + infer(instr.value.loweredFunc); + for (const operand of instr.value.loweredFunc.func.context) { + operand.identifier.mutableRange.start = makeInstructionId(0); + operand.identifier.mutableRange.end = makeInstructionId(0); + operand.identifier.scope = null; + } + break; + } + } + } + } +} +function lower(func) { + var _a, _b; + analyseFunctions(func); + inferReferenceEffects(func, { isFunctionExpression: true }); + deadCodeElimination(func); + inferMutableRanges(func); + rewriteInstructionKindsBasedOnReassignment(func); + inferReactiveScopeVariables(func); + (_b = (_a = func.env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'hir', + name: 'AnalyseFunction (inner)', + value: func, + }); +} +function infer(loweredFunc) { + for (const operand of loweredFunc.func.context) { + const identifier = operand.identifier; + CompilerError.invariant(operand.effect === Effect.Unknown, { + reason: '[AnalyseFunctions] Expected Function context effects to not have been set', + loc: operand.loc, + }); + if (isRefOrRefValue(identifier)) { + operand.effect = Effect.Capture; + } + else if (isMutatedOrReassigned(identifier)) { + operand.effect = Effect.Capture; + } + else { + operand.effect = Effect.Read; + } + } +} +function isMutatedOrReassigned(id) { + return id.mutableRange.end > id.mutableRange.start; +} + +function collectMaybeMemoDependencies(value, maybeDeps, optional) { + var _a; + switch (value.kind) { + case 'LoadGlobal': { + return { + root: { + kind: 'Global', + identifierName: value.binding.name, + }, + path: [], + }; + } + case 'PropertyLoad': { + const object = maybeDeps.get(value.object.identifier.id); + if (object != null) { + return { + root: object.root, + path: [...object.path, { property: value.property, optional }], + }; + } + break; + } + case 'LoadLocal': + case 'LoadContext': { + const source = maybeDeps.get(value.place.identifier.id); + if (source != null) { + return source; + } + else if (value.place.identifier.name != null && + value.place.identifier.name.kind === 'named') { + return { + root: { + kind: 'NamedLocal', + value: Object.assign({}, value.place), + }, + path: [], + }; + } + break; + } + case 'StoreLocal': { + const lvalue = value.lvalue.place.identifier; + const rvalue = value.value.identifier.id; + const aliased = maybeDeps.get(rvalue); + if (aliased != null && ((_a = lvalue.name) === null || _a === void 0 ? void 0 : _a.kind) !== 'named') { + maybeDeps.set(lvalue.id, aliased); + return aliased; + } + break; + } + } + return null; +} +function collectTemporaries(instr, env, sidemap) { + const { value, lvalue } = instr; + switch (value.kind) { + case 'FunctionExpression': { + sidemap.functions.set(instr.lvalue.identifier.id, instr); + break; + } + case 'LoadGlobal': { + const global = env.getGlobalDeclaration(value.binding, value.loc); + const hookKind = global !== null ? getHookKindForType(env, global) : null; + const lvalId = instr.lvalue.identifier.id; + if (hookKind === 'useMemo' || hookKind === 'useCallback') { + sidemap.manualMemos.set(lvalId, { + kind: hookKind, + loadInstr: instr, + }); + } + else if (value.binding.name === 'React') { + sidemap.react.add(lvalId); + } + break; + } + case 'PropertyLoad': { + if (sidemap.react.has(value.object.identifier.id)) { + const property = value.property; + if (property === 'useMemo' || property === 'useCallback') { + sidemap.manualMemos.set(instr.lvalue.identifier.id, { + kind: property, + loadInstr: instr, + }); + } + } + break; + } + case 'ArrayExpression': { + if (value.elements.every(e => e.kind === 'Identifier')) { + sidemap.maybeDepsLists.set(instr.lvalue.identifier.id, value.elements); + } + break; + } + } + const maybeDep = collectMaybeMemoDependencies(value, sidemap.maybeDeps, sidemap.optionals.has(lvalue.identifier.id)); + if (maybeDep != null) { + sidemap.maybeDeps.set(lvalue.identifier.id, maybeDep); + } +} +function makeManualMemoizationMarkers(fnExpr, env, depsList, memoDecl, manualMemoId) { + return [ + { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, fnExpr.loc), + value: { + kind: 'StartMemoize', + manualMemoId, + deps: depsList, + loc: fnExpr.loc, + }, + loc: fnExpr.loc, + }, + { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, fnExpr.loc), + value: { + kind: 'FinishMemoize', + manualMemoId, + decl: Object.assign({}, memoDecl), + loc: fnExpr.loc, + }, + loc: fnExpr.loc, + }, + ]; +} +function getManualMemoizationReplacement(fn, loc, kind) { + if (kind === 'useMemo') { + return { + kind: 'CallExpression', + callee: fn, + args: [], + loc, + }; + } + else { + return { + kind: 'LoadLocal', + place: { + kind: 'Identifier', + identifier: fn.identifier, + effect: Effect.Unknown, + reactive: false, + loc, + }, + loc, + }; + } +} +function extractManualMemoizationArgs(instr, kind, sidemap) { + const [fnPlace, depsListPlace] = instr.value.args; + if (fnPlace == null) { + CompilerError.throwInvalidReact({ + reason: `Expected a callback function to be passed to ${kind}`, + loc: instr.value.loc, + suggestions: null, + }); + } + if (fnPlace.kind === 'Spread' || (depsListPlace === null || depsListPlace === void 0 ? void 0 : depsListPlace.kind) === 'Spread') { + CompilerError.throwInvalidReact({ + reason: `Unexpected spread argument to ${kind}`, + loc: instr.value.loc, + suggestions: null, + }); + } + let depsList = null; + if (depsListPlace != null) { + const maybeDepsList = sidemap.maybeDepsLists.get(depsListPlace.identifier.id); + if (maybeDepsList == null) { + CompilerError.throwInvalidReact({ + reason: `Expected the dependency list for ${kind} to be an array literal`, + suggestions: null, + loc: depsListPlace.loc, + }); + } + depsList = maybeDepsList.map(dep => { + const maybeDep = sidemap.maybeDeps.get(dep.identifier.id); + if (maybeDep == null) { + CompilerError.throwInvalidReact({ + reason: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`, + suggestions: null, + loc: dep.loc, + }); + } + return maybeDep; + }); + } + return { + fnPlace, + depsList, + }; +} +function dropManualMemoization(func) { + const isValidationEnabled = func.env.config.validatePreserveExistingMemoizationGuarantees || + func.env.config.validateNoSetStateInRender || + func.env.config.enablePreserveExistingMemoizationGuarantees; + const optionals = findOptionalPlaces(func); + const sidemap = { + functions: new Map(), + manualMemos: new Map(), + react: new Set(), + maybeDeps: new Map(), + maybeDepsLists: new Map(), + optionals, + }; + let nextManualMemoId = 0; + const queuedInserts = new Map(); + for (const [_, block] of func.body.blocks) { + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + if (instr.value.kind === 'CallExpression' || + instr.value.kind === 'MethodCall') { + const id = instr.value.kind === 'CallExpression' + ? instr.value.callee.identifier.id + : instr.value.property.identifier.id; + const manualMemo = sidemap.manualMemos.get(id); + if (manualMemo != null) { + const { fnPlace, depsList } = extractManualMemoizationArgs(instr, manualMemo.kind, sidemap); + instr.value = getManualMemoizationReplacement(fnPlace, instr.value.loc, manualMemo.kind); + if (isValidationEnabled) { + if (!sidemap.functions.has(fnPlace.identifier.id)) { + CompilerError.throwInvalidReact({ + reason: `Expected the first argument to be an inline function expression`, + suggestions: [], + loc: fnPlace.loc, + }); + } + const memoDecl = manualMemo.kind === 'useMemo' + ? instr.lvalue + : { + kind: 'Identifier', + identifier: fnPlace.identifier, + effect: Effect.Unknown, + reactive: false, + loc: fnPlace.loc, + }; + const [startMarker, finishMarker] = makeManualMemoizationMarkers(fnPlace, func.env, depsList, memoDecl, nextManualMemoId++); + queuedInserts.set(manualMemo.loadInstr.id, startMarker); + queuedInserts.set(instr.id, finishMarker); + } + } + } + else { + collectTemporaries(instr, func.env, sidemap); + } + } + } + if (queuedInserts.size > 0) { + let hasChanges = false; + for (const [_, block] of func.body.blocks) { + let nextInstructions = null; + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + const insertInstr = queuedInserts.get(instr.id); + if (insertInstr != null) { + nextInstructions = nextInstructions !== null && nextInstructions !== void 0 ? nextInstructions : block.instructions.slice(0, i); + nextInstructions.push(instr); + nextInstructions.push(insertInstr); + } + else if (nextInstructions != null) { + nextInstructions.push(instr); + } + } + if (nextInstructions !== null) { + block.instructions = nextInstructions; + hasChanges = true; + } + } + if (hasChanges) { + markInstructionIds(func.body); + } + } +} +function findOptionalPlaces(fn) { + const optionals = new Set(); + for (const [, block] of fn.body.blocks) { + if (block.terminal.kind === 'optional' && block.terminal.optional) { + const optionalTerminal = block.terminal; + let testBlock = fn.body.blocks.get(block.terminal.test); + loop: while (true) { + const terminal = testBlock.terminal; + switch (terminal.kind) { + case 'branch': { + if (terminal.fallthrough === optionalTerminal.fallthrough) { + const consequent = fn.body.blocks.get(terminal.consequent); + const last = consequent.instructions.at(-1); + if (last !== undefined && last.value.kind === 'StoreLocal') { + optionals.add(last.value.value.identifier.id); + } + break loop; + } + else { + testBlock = fn.body.blocks.get(terminal.fallthrough); + } + break; + } + case 'optional': + case 'logical': + case 'sequence': + case 'ternary': { + testBlock = fn.body.blocks.get(terminal.fallthrough); + break; + } + default: { + CompilerError.invariant(false, { + reason: `Unexpected terminal in optional`, + loc: terminal.loc, + }); + } + } + } + } + } + return optionals; +} + +class StableSidemap { + constructor(env) { + this.map = new Map(); + this.env = env; + } + handleInstruction(instr) { + const { value, lvalue } = instr; + switch (value.kind) { + case 'CallExpression': + case 'MethodCall': { + if (evaluatesToStableTypeOrContainer(this.env, instr)) { + if (isStableType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + else { + this.map.set(lvalue.identifier.id, { + isStable: false, + }); + } + } + else if (this.env.config.enableTreatRefLikeIdentifiersAsRefs && + isUseRefType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + break; + } + case 'Destructure': + case 'PropertyLoad': { + const source = value.kind === 'Destructure' + ? value.value.identifier.id + : value.object.identifier.id; + const entry = this.map.get(source); + if (entry) { + for (const lvalue of eachInstructionLValue(instr)) { + if (isStableTypeContainer(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: false, + }); + } + else if (isStableType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + } + } + break; + } + case 'StoreLocal': { + const entry = this.map.get(value.value.identifier.id); + if (entry) { + this.map.set(lvalue.identifier.id, entry); + this.map.set(value.lvalue.place.identifier.id, entry); + } + break; + } + case 'LoadLocal': { + const entry = this.map.get(value.place.identifier.id); + if (entry) { + this.map.set(lvalue.identifier.id, entry); + } + break; + } + } + } + isStable(id) { + const entry = this.map.get(id); + return entry != null ? entry.isStable : false; + } +} +function inferReactivePlaces(fn) { + const reactiveIdentifiers = new ReactivityMap(findDisjointMutableValues(fn)); + const stableIdentifierSources = new StableSidemap(fn.env); + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + reactiveIdentifiers.markReactive(place); + } + const postDominators = computePostDominatorTree(fn, { + includeThrowsAsExitNode: false, + }); + const postDominatorFrontierCache = new Map(); + function isReactiveControlledBlock(id) { + let controlBlocks = postDominatorFrontierCache.get(id); + if (controlBlocks === undefined) { + controlBlocks = postDominatorFrontier(fn, postDominators, id); + postDominatorFrontierCache.set(id, controlBlocks); + } + for (const blockId of controlBlocks) { + const controlBlock = fn.body.blocks.get(blockId); + switch (controlBlock.terminal.kind) { + case 'if': + case 'branch': { + if (reactiveIdentifiers.isReactive(controlBlock.terminal.test)) { + return true; + } + break; + } + case 'switch': { + if (reactiveIdentifiers.isReactive(controlBlock.terminal.test)) { + return true; + } + for (const case_ of controlBlock.terminal.cases) { + if (case_.test !== null && + reactiveIdentifiers.isReactive(case_.test)) { + return true; + } + } + break; + } + } + } + return false; + } + do { + for (const [, block] of fn.body.blocks) { + let hasReactiveControl = isReactiveControlledBlock(block.id); + for (const phi of block.phis) { + if (reactiveIdentifiers.isReactive(phi.place)) { + continue; + } + let isPhiReactive = false; + for (const [, operand] of phi.operands) { + if (reactiveIdentifiers.isReactive(operand)) { + isPhiReactive = true; + break; + } + } + if (isPhiReactive) { + reactiveIdentifiers.markReactive(phi.place); + } + else { + for (const [pred] of phi.operands) { + if (isReactiveControlledBlock(pred)) { + reactiveIdentifiers.markReactive(phi.place); + break; + } + } + } + } + for (const instruction of block.instructions) { + stableIdentifierSources.handleInstruction(instruction); + const { value } = instruction; + let hasReactiveInput = false; + for (const operand of eachInstructionValueOperand(value)) { + const reactive = reactiveIdentifiers.isReactive(operand); + hasReactiveInput || (hasReactiveInput = reactive); + } + if (value.kind === 'CallExpression' && + (getHookKind(fn.env, value.callee.identifier) != null || + isUseOperator(value.callee.identifier))) { + hasReactiveInput = true; + } + else if (value.kind === 'MethodCall' && + (getHookKind(fn.env, value.property.identifier) != null || + isUseOperator(value.property.identifier))) { + hasReactiveInput = true; + } + if (hasReactiveInput) { + for (const lvalue of eachInstructionLValue(instruction)) { + if (stableIdentifierSources.isStable(lvalue.identifier.id)) { + continue; + } + reactiveIdentifiers.markReactive(lvalue); + } + } + if (hasReactiveInput || hasReactiveControl) { + for (const operand of eachInstructionValueOperand(value)) { + switch (operand.effect) { + case Effect.Capture: + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + if (isMutable(instruction, operand)) { + reactiveIdentifiers.markReactive(operand); + } + break; + } + case Effect.Freeze: + case Effect.Read: { + break; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: operand.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(operand.effect, `Unexpected effect kind \`${operand.effect}\``); + } + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + reactiveIdentifiers.isReactive(operand); + } + } + } while (reactiveIdentifiers.snapshot()); +} +function postDominatorFrontier(fn, postDominators, targetId) { + const visited = new Set(); + const frontier = new Set(); + const targetPostDominators = postDominatorsOf(fn, postDominators, targetId); + for (const blockId of [...targetPostDominators, targetId]) { + if (visited.has(blockId)) { + continue; + } + visited.add(blockId); + const block = fn.body.blocks.get(blockId); + for (const pred of block.preds) { + if (!targetPostDominators.has(pred)) { + frontier.add(pred); + } + } + } + return frontier; +} +function postDominatorsOf(fn, postDominators, targetId) { + var _a; + const result = new Set(); + const visited = new Set(); + const queue = [targetId]; + while (queue.length) { + const currentId = queue.shift(); + if (visited.has(currentId)) { + continue; + } + visited.add(currentId); + const current = fn.body.blocks.get(currentId); + for (const pred of current.preds) { + const predPostDominator = (_a = postDominators.get(pred)) !== null && _a !== void 0 ? _a : pred; + if (predPostDominator === targetId || result.has(predPostDominator)) { + result.add(pred); + } + queue.push(pred); + } + } + return result; +} +class ReactivityMap { + constructor(aliasedIdentifiers) { + this.hasChanges = false; + this.reactive = new Set(); + this.aliasedIdentifiers = aliasedIdentifiers; + } + isReactive(place) { + var _a; + const identifier = (_a = this.aliasedIdentifiers.find(place.identifier)) !== null && _a !== void 0 ? _a : place.identifier; + const reactive = this.reactive.has(identifier.id); + if (reactive) { + place.reactive = true; + } + return reactive; + } + markReactive(place) { + var _a; + place.reactive = true; + const identifier = (_a = this.aliasedIdentifiers.find(place.identifier)) !== null && _a !== void 0 ? _a : place.identifier; + if (!this.reactive.has(identifier.id)) { + this.hasChanges = true; + this.reactive.add(identifier.id); + } + } + snapshot() { + const hasChanges = this.hasChanges; + this.hasChanges = false; + return hasChanges; + } +} + +function inlineImmediatelyInvokedFunctionExpressions(fn) { + const functions = new Map(); + const inlinedFunctions = new Set(); + const queue = Array.from(fn.body.blocks.values()); + queue: for (const block of queue) { + for (let ii = 0; ii < block.instructions.length; ii++) { + const instr = block.instructions[ii]; + switch (instr.value.kind) { + case 'FunctionExpression': { + if (instr.lvalue.identifier.name === null) { + functions.set(instr.lvalue.identifier.id, instr.value); + } + break; + } + case 'CallExpression': { + if (instr.value.args.length !== 0) { + continue; + } + const body = functions.get(instr.value.callee.identifier.id); + if (body === undefined) { + continue; + } + if (body.loweredFunc.func.params.length > 0 || + body.loweredFunc.func.async || + body.loweredFunc.func.generator) { + continue; + } + inlinedFunctions.add(instr.value.callee.identifier.id); + const continuationBlockId = fn.env.nextBlockId; + const continuationBlock = { + id: continuationBlockId, + instructions: block.instructions.slice(ii + 1), + kind: block.kind, + phis: new Set(), + preds: new Set(), + terminal: block.terminal, + }; + fn.body.blocks.set(continuationBlockId, continuationBlock); + block.instructions.length = ii; + const newTerminal = { + block: body.loweredFunc.func.body.entry, + id: makeInstructionId(0), + kind: 'label', + fallthrough: continuationBlockId, + loc: block.terminal.loc, + }; + block.terminal = newTerminal; + const result = instr.lvalue; + declareTemporary(fn.env, block, result); + promoteTemporary(result.identifier); + for (const [id, block] of body.loweredFunc.func.body.blocks) { + block.preds.clear(); + rewriteBlock(fn.env, block, continuationBlockId, result); + fn.body.blocks.set(id, block); + } + queue.push(continuationBlock); + continue queue; + } + default: { + for (const place of eachInstructionValueOperand(instr.value)) { + functions.delete(place.identifier.id); + } + } + } + } + } + if (inlinedFunctions.size !== 0) { + for (const [, block] of fn.body.blocks) { + retainWhere(block.instructions, instr => !inlinedFunctions.has(instr.lvalue.identifier.id)); + } + reversePostorderBlocks(fn.body); + markInstructionIds(fn.body); + markPredecessors(fn.body); + } +} +function rewriteBlock(env, block, returnTarget, returnValue) { + const { terminal } = block; + if (terminal.kind !== 'return') { + return; + } + block.instructions.push({ + id: makeInstructionId(0), + loc: terminal.loc, + lvalue: createTemporaryPlace(env, terminal.loc), + value: { + kind: 'StoreLocal', + lvalue: { kind: InstructionKind.Reassign, place: Object.assign({}, returnValue) }, + value: terminal.value, + type: null, + loc: terminal.loc, + }, + }); + block.terminal = { + kind: 'goto', + block: returnTarget, + id: makeInstructionId(0), + variant: GotoVariant.Break, + loc: block.terminal.loc, + }; +} +function declareTemporary(env, block, result) { + block.instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, result.loc), + value: { + kind: 'DeclareLocal', + lvalue: { + place: result, + kind: InstructionKind.Let, + }, + type: null, + loc: result.loc, + }, + }); +} + +function collectHoistablePropertyLoads(fn, temporaries, hoistableFromOptionals) { + const registry = new PropertyPathRegistry(); + const knownImmutableIdentifiers = new Set(); + if (fn.fnType === 'Component' || fn.fnType === 'Hook') { + for (const p of fn.params) { + if (p.kind === 'Identifier') { + knownImmutableIdentifiers.add(p.identifier.id); + } + } + } + return collectHoistablePropertyLoadsImpl(fn, { + temporaries, + knownImmutableIdentifiers, + hoistableFromOptionals, + registry, + nestedFnImmutableContext: null, + assumedInvokedFns: fn.env.config.enableTreatFunctionDepsAsConditional + ? new Set() + : getAssumedInvokedFunctions(fn), + }); +} +function collectHoistablePropertyLoadsInInnerFn(fnInstr, temporaries, hoistableFromOptionals) { + const fn = fnInstr.value.loweredFunc.func; + const initialContext = { + temporaries, + knownImmutableIdentifiers: new Set(), + hoistableFromOptionals, + registry: new PropertyPathRegistry(), + nestedFnImmutableContext: null, + assumedInvokedFns: fn.env.config.enableTreatFunctionDepsAsConditional + ? new Set() + : getAssumedInvokedFunctions(fn), + }; + const nestedFnImmutableContext = new Set(fn.context + .filter(place => isImmutableAtInstr(place.identifier, fnInstr.id, initialContext)) + .map(place => place.identifier.id)); + initialContext.nestedFnImmutableContext = nestedFnImmutableContext; + return collectHoistablePropertyLoadsImpl(fn, initialContext); +} +function collectHoistablePropertyLoadsImpl(fn, context) { + const nodes = collectNonNullsInBlocks(fn, context); + propagateNonNull(fn, nodes, context.registry); + return nodes; +} +function keyByScopeId(fn, source) { + const keyedByScopeId = new Map(); + for (const [_, block] of fn.body.blocks) { + if (block.terminal.kind === 'scope') { + keyedByScopeId.set(block.terminal.scope.id, source.get(block.terminal.block)); + } + } + return keyedByScopeId; +} +class PropertyPathRegistry { + constructor() { + this.roots = new Map(); + } + getOrCreateIdentifier(identifier) { + let rootNode = this.roots.get(identifier.id); + if (rootNode === undefined) { + rootNode = { + root: identifier.id, + properties: new Map(), + optionalProperties: new Map(), + fullPath: { + identifier, + path: [], + }, + hasOptional: false, + parent: null, + }; + this.roots.set(identifier.id, rootNode); + } + return rootNode; + } + static getOrCreatePropertyEntry(parent, entry) { + const map = entry.optional ? parent.optionalProperties : parent.properties; + let child = map.get(entry.property); + if (child == null) { + child = { + properties: new Map(), + optionalProperties: new Map(), + parent: parent, + fullPath: { + identifier: parent.fullPath.identifier, + path: parent.fullPath.path.concat(entry), + }, + hasOptional: parent.hasOptional || entry.optional, + }; + map.set(entry.property, child); + } + return child; + } + getOrCreateProperty(n) { + let currNode = this.getOrCreateIdentifier(n.identifier); + if (n.path.length === 0) { + return currNode; + } + for (let i = 0; i < n.path.length - 1; i++) { + currNode = PropertyPathRegistry.getOrCreatePropertyEntry(currNode, n.path[i]); + } + return PropertyPathRegistry.getOrCreatePropertyEntry(currNode, n.path.at(-1)); + } +} +function getMaybeNonNullInInstruction(instr, context) { + var _a, _b, _c; + let path = null; + if (instr.kind === 'PropertyLoad') { + path = (_a = context.temporaries.get(instr.object.identifier.id)) !== null && _a !== void 0 ? _a : { + identifier: instr.object.identifier, + path: [], + }; + } + else if (instr.kind === 'Destructure') { + path = (_b = context.temporaries.get(instr.value.identifier.id)) !== null && _b !== void 0 ? _b : null; + } + else if (instr.kind === 'ComputedLoad') { + path = (_c = context.temporaries.get(instr.object.identifier.id)) !== null && _c !== void 0 ? _c : null; + } + return path != null ? context.registry.getOrCreateProperty(path) : null; +} +function isImmutableAtInstr(identifier, instr, context) { + if (context.nestedFnImmutableContext != null) { + return context.nestedFnImmutableContext.has(identifier.id); + } + else { + const mutableAtInstr = identifier.mutableRange.end > identifier.mutableRange.start + 1 && + identifier.scope != null && + inRange({ + id: instr, + }, identifier.scope.range); + return (!mutableAtInstr || context.knownImmutableIdentifiers.has(identifier.id)); + } +} +function collectNonNullsInBlocks(fn, context) { + var _a; + const knownNonNullIdentifiers = new Set(); + if (fn.fnType === 'Component' && + fn.params.length > 0 && + fn.params[0].kind === 'Identifier') { + const identifier = fn.params[0].identifier; + knownNonNullIdentifiers.add(context.registry.getOrCreateIdentifier(identifier)); + } + const nodes = new Map(); + for (const [_, block] of fn.body.blocks) { + const assumedNonNullObjects = new Set(knownNonNullIdentifiers); + const maybeOptionalChain = context.hoistableFromOptionals.get(block.id); + if (maybeOptionalChain != null) { + assumedNonNullObjects.add(context.registry.getOrCreateProperty(maybeOptionalChain)); + } + for (const instr of block.instructions) { + const maybeNonNull = getMaybeNonNullInInstruction(instr.value, context); + if (maybeNonNull != null && + isImmutableAtInstr(maybeNonNull.fullPath.identifier, instr.id, context)) { + assumedNonNullObjects.add(maybeNonNull); + } + if (instr.value.kind === 'FunctionExpression') { + const innerFn = instr.value.loweredFunc; + if (context.assumedInvokedFns.has(innerFn)) { + const innerHoistableMap = collectHoistablePropertyLoadsImpl(innerFn.func, Object.assign(Object.assign({}, context), { nestedFnImmutableContext: (_a = context.nestedFnImmutableContext) !== null && _a !== void 0 ? _a : new Set(innerFn.func.context + .filter(place => isImmutableAtInstr(place.identifier, instr.id, context)) + .map(place => place.identifier.id)) })); + const innerHoistables = assertNonNull(innerHoistableMap.get(innerFn.func.body.entry)); + for (const entry of innerHoistables.assumedNonNullObjects) { + assumedNonNullObjects.add(entry); + } + } + } + } + nodes.set(block.id, { + block, + assumedNonNullObjects, + }); + } + return nodes; +} +function propagateNonNull(fn, nodes, registry) { + const blockSuccessors = new Map(); + const terminalPreds = new Set(); + for (const [blockId, block] of fn.body.blocks) { + for (const pred of block.preds) { + getOrInsertDefault(blockSuccessors, pred, new Set()).add(blockId); + } + if (block.terminal.kind === 'throw' || block.terminal.kind === 'return') { + terminalPreds.add(blockId); + } + } + function recursivelyPropagateNonNull(nodeId, direction, traversalState) { + var _a; + if (traversalState.has(nodeId)) { + return false; + } + traversalState.set(nodeId, 'active'); + const node = nodes.get(nodeId); + if (node == null) { + CompilerError.invariant(false, { + reason: `Bad node ${nodeId}, kind: ${direction}`, + loc: GeneratedSource, + }); + } + const neighbors = Array.from(direction === 'backward' + ? ((_a = blockSuccessors.get(nodeId)) !== null && _a !== void 0 ? _a : []) + : node.block.preds); + let changed = false; + for (const pred of neighbors) { + if (!traversalState.has(pred)) { + const neighborChanged = recursivelyPropagateNonNull(pred, direction, traversalState); + changed || (changed = neighborChanged); + } + } + const neighborAccesses = Set_intersect(Array.from(neighbors) + .filter(n => traversalState.get(n) === 'done') + .map(n => assertNonNull(nodes.get(n)).assumedNonNullObjects)); + const prevObjects = assertNonNull(nodes.get(nodeId)).assumedNonNullObjects; + const mergedObjects = Set_union(prevObjects, neighborAccesses); + reduceMaybeOptionalChains(mergedObjects, registry); + assertNonNull(nodes.get(nodeId)).assumedNonNullObjects = mergedObjects; + traversalState.set(nodeId, 'done'); + changed || (changed = !Set_equal(prevObjects, mergedObjects)); + return changed; + } + const traversalState = new Map(); + const reversedBlocks = [...fn.body.blocks]; + reversedBlocks.reverse(); + let changed; + let i = 0; + do { + CompilerError.invariant(i++ < 100, { + reason: '[CollectHoistablePropertyLoads] fixed point iteration did not terminate after 100 loops', + loc: GeneratedSource, + }); + changed = false; + for (const [blockId] of fn.body.blocks) { + const forwardChanged = recursivelyPropagateNonNull(blockId, 'forward', traversalState); + changed || (changed = forwardChanged); + } + traversalState.clear(); + for (const [blockId] of reversedBlocks) { + const backwardChanged = recursivelyPropagateNonNull(blockId, 'backward', traversalState); + changed || (changed = backwardChanged); + } + traversalState.clear(); + } while (changed); +} +function assertNonNull(value, source) { + CompilerError.invariant(value != null, { + reason: 'Unexpected null', + description: source != null ? `(from ${source})` : null, + loc: GeneratedSource, + }); + return value; +} +function reduceMaybeOptionalChains(nodes, registry) { + let optionalChainNodes = Set_filter(nodes, n => n.hasOptional); + if (optionalChainNodes.size === 0) { + return; + } + let changed; + do { + changed = false; + for (const original of optionalChainNodes) { + let { identifier, path: origPath } = original.fullPath; + let currNode = registry.getOrCreateIdentifier(identifier); + for (let i = 0; i < origPath.length; i++) { + const entry = origPath[i]; + const nextEntry = entry.optional && nodes.has(currNode) + ? { property: entry.property, optional: false } + : entry; + currNode = PropertyPathRegistry.getOrCreatePropertyEntry(currNode, nextEntry); + } + if (currNode !== original) { + changed = true; + optionalChainNodes.delete(original); + optionalChainNodes.add(currNode); + nodes.delete(original); + nodes.add(currNode); + } + } + } while (changed); +} +function getAssumedInvokedFunctions(fn, temporaries = new Map()) { + var _a; + const hoistableFunctions = new Set(); + for (const block of fn.body.blocks.values()) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'FunctionExpression') { + temporaries.set(lvalue.identifier.id, { + fn: value.loweredFunc, + mayInvoke: new Set(), + }); + } + else if (value.kind === 'StoreLocal') { + const lvalue = value.lvalue.place.identifier; + const maybeLoweredFunc = temporaries.get(value.value.identifier.id); + if (maybeLoweredFunc != null) { + temporaries.set(lvalue.id, maybeLoweredFunc); + } + } + else if (value.kind === 'LoadLocal') { + const maybeLoweredFunc = temporaries.get(value.place.identifier.id); + if (maybeLoweredFunc != null) { + temporaries.set(lvalue.identifier.id, maybeLoweredFunc); + } + } + } + } + for (const block of fn.body.blocks.values()) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'CallExpression') { + const callee = value.callee; + const maybeHook = getHookKind(fn.env, callee.identifier); + const maybeLoweredFunc = temporaries.get(callee.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + else if (maybeHook != null) { + for (const arg of value.args) { + if (arg.kind === 'Identifier') { + const maybeLoweredFunc = temporaries.get(arg.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + } + } + else if (value.kind === 'JsxExpression') { + for (const attr of value.props) { + if (attr.kind === 'JsxSpreadAttribute') { + continue; + } + const maybeLoweredFunc = temporaries.get(attr.place.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + for (const child of (_a = value.children) !== null && _a !== void 0 ? _a : []) { + const maybeLoweredFunc = temporaries.get(child.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + else if (value.kind === 'FunctionExpression') { + const loweredFunc = value.loweredFunc.func; + const lambdasCalled = getAssumedInvokedFunctions(loweredFunc, temporaries); + const maybeLoweredFunc = temporaries.get(lvalue.identifier.id); + if (maybeLoweredFunc != null) { + for (const called of lambdasCalled) { + maybeLoweredFunc.mayInvoke.add(called); + } + } + } + } + if (block.terminal.kind === 'return') { + const maybeLoweredFunc = temporaries.get(block.terminal.value.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + for (const [_, { fn, mayInvoke }] of temporaries) { + if (hoistableFunctions.has(fn)) { + for (const called of mayInvoke) { + hoistableFunctions.add(called); + } + } + } + return hoistableFunctions; +} + +function collectOptionalChainSidemap(fn) { + const context = { + currFn: fn, + blocks: fn.body.blocks, + seenOptionals: new Set(), + processedInstrsInOptional: new Set(), + temporariesReadInOptional: new Map(), + hoistableObjects: new Map(), + }; + traverseFunction(fn, context); + return { + temporariesReadInOptional: context.temporariesReadInOptional, + processedInstrsInOptional: context.processedInstrsInOptional, + hoistableObjects: context.hoistableObjects, + }; +} +function traverseFunction(fn, context) { + for (const [_, block] of fn.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + traverseFunction(instr.value.loweredFunc.func, Object.assign(Object.assign({}, context), { currFn: instr.value.loweredFunc.func, blocks: instr.value.loweredFunc.func.body.blocks })); + } + } + if (block.terminal.kind === 'optional' && + !context.seenOptionals.has(block.id)) { + traverseOptionalBlock(block, context, null); + } + } +} +function matchOptionalTestBlock(terminal, blocks) { + const consequentBlock = assertNonNull(blocks.get(terminal.consequent)); + if (consequentBlock.instructions.length === 2 && + consequentBlock.instructions[0].value.kind === 'PropertyLoad' && + consequentBlock.instructions[1].value.kind === 'StoreLocal') { + const propertyLoad = consequentBlock + .instructions[0]; + const storeLocal = consequentBlock.instructions[1].value; + const storeLocalInstr = consequentBlock.instructions[1]; + CompilerError.invariant(propertyLoad.value.object.identifier.id === terminal.test.identifier.id, { + reason: '[OptionalChainDeps] Inconsistent optional chaining property load', + description: `Test=${printIdentifier(terminal.test.identifier)} PropertyLoad base=${printIdentifier(propertyLoad.value.object.identifier)}`, + loc: propertyLoad.loc, + }); + CompilerError.invariant(storeLocal.value.identifier.id === propertyLoad.lvalue.identifier.id, { + reason: '[OptionalChainDeps] Unexpected storeLocal', + loc: propertyLoad.loc, + }); + if (consequentBlock.terminal.kind !== 'goto' || + consequentBlock.terminal.variant !== GotoVariant.Break) { + return null; + } + const alternate = assertNonNull(blocks.get(terminal.alternate)); + CompilerError.invariant(alternate.instructions.length === 2 && + alternate.instructions[0].value.kind === 'Primitive' && + alternate.instructions[1].value.kind === 'StoreLocal', { + reason: 'Unexpected alternate structure', + loc: terminal.loc, + }); + return { + consequentId: storeLocal.lvalue.place.identifier.id, + property: propertyLoad.value.property, + propertyId: propertyLoad.lvalue.identifier.id, + storeLocalInstr, + consequentGoto: consequentBlock.terminal.block, + }; + } + return null; +} +function traverseOptionalBlock(optional, context, outerAlternate) { + context.seenOptionals.add(optional.id); + const maybeTest = context.blocks.get(optional.terminal.test); + let test; + let baseObject; + if (maybeTest.terminal.kind === 'branch') { + CompilerError.invariant(optional.terminal.optional, { + reason: '[OptionalChainDeps] Expect base case to be always optional', + loc: optional.terminal.loc, + }); + if (maybeTest.instructions.length === 0 || + maybeTest.instructions[0].value.kind !== 'LoadLocal') { + return null; + } + const path = []; + for (let i = 1; i < maybeTest.instructions.length; i++) { + const instrVal = maybeTest.instructions[i].value; + const prevInstr = maybeTest.instructions[i - 1]; + if (instrVal.kind === 'PropertyLoad' && + instrVal.object.identifier.id === prevInstr.lvalue.identifier.id) { + path.push({ property: instrVal.property, optional: false }); + } + else { + return null; + } + } + CompilerError.invariant(maybeTest.terminal.test.identifier.id === + maybeTest.instructions.at(-1).lvalue.identifier.id, { + reason: '[OptionalChainDeps] Unexpected test expression', + loc: maybeTest.terminal.loc, + }); + baseObject = { + identifier: maybeTest.instructions[0].value.place.identifier, + path, + }; + test = maybeTest.terminal; + } + else if (maybeTest.terminal.kind === 'optional') { + const testBlock = context.blocks.get(maybeTest.terminal.fallthrough); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional fallthrough block`, + loc: maybeTest.terminal.loc, + }); + } + const innerOptional = traverseOptionalBlock(maybeTest, context, testBlock.terminal.alternate); + if (innerOptional == null) { + return null; + } + if (testBlock.terminal.test.identifier.id !== innerOptional) { + return null; + } + if (!optional.terminal.optional) { + context.hoistableObjects.set(optional.id, assertNonNull(context.temporariesReadInOptional.get(innerOptional))); + } + baseObject = assertNonNull(context.temporariesReadInOptional.get(innerOptional)); + test = testBlock.terminal; + } + else { + return null; + } + if (test.alternate === outerAlternate) { + CompilerError.invariant(optional.instructions.length === 0, { + reason: '[OptionalChainDeps] Unexpected instructions an inner optional block. ' + + 'This indicates that the compiler may be incorrectly concatenating two unrelated optional chains', + loc: optional.terminal.loc, + }); + } + const matchConsequentResult = matchOptionalTestBlock(test, context.blocks); + if (!matchConsequentResult) { + return null; + } + CompilerError.invariant(matchConsequentResult.consequentGoto === optional.terminal.fallthrough, { + reason: '[OptionalChainDeps] Unexpected optional goto-fallthrough', + description: `${matchConsequentResult.consequentGoto} != ${optional.terminal.fallthrough}`, + loc: optional.terminal.loc, + }); + const load = { + identifier: baseObject.identifier, + path: [ + ...baseObject.path, + { + property: matchConsequentResult.property, + optional: optional.terminal.optional, + }, + ], + }; + context.processedInstrsInOptional.add(matchConsequentResult.storeLocalInstr); + context.processedInstrsInOptional.add(test); + context.temporariesReadInOptional.set(matchConsequentResult.consequentId, load); + context.temporariesReadInOptional.set(matchConsequentResult.propertyId, load); + return matchConsequentResult.consequentId; +} + +var _a, _ReactiveScopeDependencyTreeHIR_hoistableObjects, _ReactiveScopeDependencyTreeHIR_deps, _ReactiveScopeDependencyTreeHIR_getOrCreateRoot, _ReactiveScopeDependencyTreeHIR_debugImpl; +class ReactiveScopeDependencyTreeHIR { + constructor(hoistableObjects) { + var _b; + _ReactiveScopeDependencyTreeHIR_hoistableObjects.set(this, new Map()); + _ReactiveScopeDependencyTreeHIR_deps.set(this, new Map()); + for (const { path, identifier } of hoistableObjects) { + let currNode = __classPrivateFieldGet(_a, _a, "m", _ReactiveScopeDependencyTreeHIR_getOrCreateRoot).call(_a, identifier, __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_hoistableObjects, "f"), path.length > 0 && path[0].optional ? 'Optional' : 'NonNull'); + for (let i = 0; i < path.length; i++) { + const prevAccessType = (_b = currNode.properties.get(path[i].property)) === null || _b === void 0 ? void 0 : _b.accessType; + const accessType = i + 1 < path.length && path[i + 1].optional ? 'Optional' : 'NonNull'; + CompilerError.invariant(prevAccessType == null || prevAccessType === accessType, { + reason: 'Conflicting access types', + loc: GeneratedSource, + }); + let nextNode = currNode.properties.get(path[i].property); + if (nextNode == null) { + nextNode = { + properties: new Map(), + accessType, + }; + currNode.properties.set(path[i].property, nextNode); + } + currNode = nextNode; + } + } + } + addDependency(dep) { + const { identifier, path } = dep; + let depCursor = __classPrivateFieldGet(_a, _a, "m", _ReactiveScopeDependencyTreeHIR_getOrCreateRoot).call(_a, identifier, __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f"), PropertyAccessType.UnconditionalAccess); + let hoistableCursor = __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_hoistableObjects, "f").get(identifier); + for (const entry of path) { + let nextHoistableCursor; + let nextDepCursor; + if (entry.optional) { + if (hoistableCursor != null) { + nextHoistableCursor = hoistableCursor === null || hoistableCursor === void 0 ? void 0 : hoistableCursor.properties.get(entry.property); + } + let accessType; + if (hoistableCursor != null && + hoistableCursor.accessType === 'NonNull') { + accessType = PropertyAccessType.UnconditionalAccess; + } + else { + accessType = PropertyAccessType.OptionalAccess; + } + nextDepCursor = makeOrMergeProperty(depCursor, entry.property, accessType); + } + else if (hoistableCursor != null && + hoistableCursor.accessType === 'NonNull') { + nextHoistableCursor = hoistableCursor.properties.get(entry.property); + nextDepCursor = makeOrMergeProperty(depCursor, entry.property, PropertyAccessType.UnconditionalAccess); + } + else { + break; + } + depCursor = nextDepCursor; + hoistableCursor = nextHoistableCursor; + } + depCursor.accessType = merge(depCursor.accessType, PropertyAccessType.OptionalDependency); + } + deriveMinimalDependencies() { + const results = new Set(); + for (const [rootId, rootNode] of __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f").entries()) { + collectMinimalDependenciesInSubtree(rootNode, rootId, [], results); + } + return results; + } + printDeps(includeAccesses) { + let res = []; + for (const [rootId, rootNode] of __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f").entries()) { + const rootResults = printSubtree(rootNode, includeAccesses).map(result => `${printIdentifier(rootId)}.${result}`); + res.push(rootResults); + } + return res.flat().join('\n'); + } + static debug(roots) { + const buf = [`tree() [`]; + for (const [rootId, rootNode] of roots) { + buf.push(`${printIdentifier(rootId)} (${rootNode.accessType}):`); + __classPrivateFieldGet(this, _a, "m", _ReactiveScopeDependencyTreeHIR_debugImpl).call(this, buf, rootNode, 1); + } + buf.push(']'); + return buf.length > 2 ? buf.join('\n') : buf.join(''); + } +} +_a = ReactiveScopeDependencyTreeHIR, _ReactiveScopeDependencyTreeHIR_hoistableObjects = new WeakMap(), _ReactiveScopeDependencyTreeHIR_deps = new WeakMap(), _ReactiveScopeDependencyTreeHIR_getOrCreateRoot = function _ReactiveScopeDependencyTreeHIR_getOrCreateRoot(identifier, roots, defaultAccessType) { + let rootNode = roots.get(identifier); + if (rootNode === undefined) { + rootNode = { + properties: new Map(), + accessType: defaultAccessType, + }; + roots.set(identifier, rootNode); + } + return rootNode; +}, _ReactiveScopeDependencyTreeHIR_debugImpl = function _ReactiveScopeDependencyTreeHIR_debugImpl(buf, node, depth = 0) { + for (const [property, childNode] of node.properties) { + buf.push(`${' '.repeat(depth)}.${property} (${childNode.accessType}):`); + __classPrivateFieldGet(this, _a, "m", _ReactiveScopeDependencyTreeHIR_debugImpl).call(this, buf, childNode, depth + 1); + } +}; +var PropertyAccessType; +(function (PropertyAccessType) { + PropertyAccessType["OptionalAccess"] = "OptionalAccess"; + PropertyAccessType["UnconditionalAccess"] = "UnconditionalAccess"; + PropertyAccessType["OptionalDependency"] = "OptionalDependency"; + PropertyAccessType["UnconditionalDependency"] = "UnconditionalDependency"; +})(PropertyAccessType || (PropertyAccessType = {})); +function isOptional(access) { + return (access === PropertyAccessType.OptionalAccess || + access === PropertyAccessType.OptionalDependency); +} +function isDependency(access) { + return (access === PropertyAccessType.OptionalDependency || + access === PropertyAccessType.UnconditionalDependency); +} +function merge(access1, access2) { + const resultIsUnconditional = !(isOptional(access1) && isOptional(access2)); + const resultIsDependency = isDependency(access1) || isDependency(access2); + if (resultIsUnconditional) { + if (resultIsDependency) { + return PropertyAccessType.UnconditionalDependency; + } + else { + return PropertyAccessType.UnconditionalAccess; + } + } + else { + if (resultIsDependency) { + return PropertyAccessType.OptionalDependency; + } + else { + return PropertyAccessType.OptionalAccess; + } + } +} +function collectMinimalDependenciesInSubtree(node, rootIdentifier, path, results) { + if (isDependency(node.accessType)) { + results.add({ identifier: rootIdentifier, path }); + } + else { + for (const [childName, childNode] of node.properties) { + collectMinimalDependenciesInSubtree(childNode, rootIdentifier, [ + ...path, + { + property: childName, + optional: isOptional(childNode.accessType), + }, + ], results); + } + } +} +function printSubtree(node, includeAccesses) { + const results = []; + for (const [propertyName, propertyNode] of node.properties) { + if (includeAccesses || isDependency(propertyNode.accessType)) { + results.push(`${propertyName} (${propertyNode.accessType})`); + } + const propertyResults = printSubtree(propertyNode, includeAccesses); + results.push(...propertyResults.map(result => `${propertyName}.${result}`)); + } + return results; +} +function makeOrMergeProperty(node, property, accessType) { + let child = node.properties.get(property); + if (child == null) { + child = { + properties: new Map(), + accessType, + }; + node.properties.set(property, child); + } + else { + child.accessType = merge(child.accessType, accessType); + } + return child; +} + +var _DependencyCollectionContext_instances, _DependencyCollectionContext_declarations, _DependencyCollectionContext_reassignments, _DependencyCollectionContext_scopes, _DependencyCollectionContext_dependencies, _DependencyCollectionContext_temporaries, _DependencyCollectionContext_temporariesUsedOutsideScope, _DependencyCollectionContext_processedInstrsInOptional, _DependencyCollectionContext_innerFnContext, _DependencyCollectionContext_checkValidDependency, _DependencyCollectionContext_isScopeActive; +function propagateScopeDependenciesHIR(fn) { + const usedOutsideDeclaringScope = findTemporariesUsedOutsideDeclaringScope(fn); + const temporaries = collectTemporariesSidemap(fn, usedOutsideDeclaringScope); + const { temporariesReadInOptional, processedInstrsInOptional, hoistableObjects, } = collectOptionalChainSidemap(fn); + const hoistablePropertyLoads = keyByScopeId(fn, collectHoistablePropertyLoads(fn, temporaries, hoistableObjects)); + const scopeDeps = collectDependencies(fn, usedOutsideDeclaringScope, new Map([...temporaries, ...temporariesReadInOptional]), processedInstrsInOptional); + for (const [scope, deps] of scopeDeps) { + if (deps.length === 0) { + continue; + } + const hoistables = hoistablePropertyLoads.get(scope.id); + CompilerError.invariant(hoistables != null, { + reason: '[PropagateScopeDependencies] Scope not found in tracked blocks', + loc: GeneratedSource, + }); + const tree = new ReactiveScopeDependencyTreeHIR([...hoistables.assumedNonNullObjects].map(o => o.fullPath)); + for (const dep of deps) { + tree.addDependency(Object.assign({}, dep)); + } + const candidates = tree.deriveMinimalDependencies(); + for (const candidateDep of candidates) { + if (!Iterable_some(scope.dependencies, existingDep => existingDep.identifier.declarationId === + candidateDep.identifier.declarationId && + areEqualPaths(existingDep.path, candidateDep.path))) + scope.dependencies.add(candidateDep); + } + } +} +function findTemporariesUsedOutsideDeclaringScope(fn) { + const declarations = new Map(); + const prunedScopes = new Set(); + const scopeTraversal = new ScopeBlockTraversal(); + const usedOutsideDeclaringScope = new Set(); + function handlePlace(place) { + const declaringScope = declarations.get(place.identifier.declarationId); + if (declaringScope != null && + !scopeTraversal.isScopeActive(declaringScope) && + !prunedScopes.has(declaringScope)) { + usedOutsideDeclaringScope.add(place.identifier.declarationId); + } + } + function handleInstruction(instr) { + const scope = scopeTraversal.currentScope; + if (scope == null || prunedScopes.has(scope)) { + return; + } + switch (instr.value.kind) { + case 'LoadLocal': + case 'LoadContext': + case 'PropertyLoad': { + declarations.set(instr.lvalue.identifier.declarationId, scope); + break; + } + } + } + for (const [blockId, block] of fn.body.blocks) { + scopeTraversal.recordScopes(block); + const scopeStartInfo = scopeTraversal.blockInfos.get(blockId); + if ((scopeStartInfo === null || scopeStartInfo === void 0 ? void 0 : scopeStartInfo.kind) === 'begin' && scopeStartInfo.pruned) { + prunedScopes.add(scopeStartInfo.scope.id); + } + for (const instr of block.instructions) { + for (const place of eachInstructionOperand(instr)) { + handlePlace(place); + } + handleInstruction(instr); + } + for (const place of eachTerminalOperand(block.terminal)) { + handlePlace(place); + } + } + return usedOutsideDeclaringScope; +} +function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) { + const temporaries = new Map(); + collectTemporariesSidemapImpl(fn, usedOutsideDeclaringScope, temporaries, null); + return temporaries; +} +function isLoadContextMutable(instrValue, id) { + if (instrValue.kind === 'LoadContext') { + return (instrValue.place.identifier.scope != null && + id >= instrValue.place.identifier.scope.range.end); + } + return false; +} +function collectTemporariesSidemapImpl(fn, usedOutsideDeclaringScope, temporaries, innerFnContext) { + for (const [_, block] of fn.body.blocks) { + for (const { value, lvalue, id: origInstrId } of block.instructions) { + const instrId = innerFnContext != null ? innerFnContext.instrId : origInstrId; + const usedOutside = usedOutsideDeclaringScope.has(lvalue.identifier.declarationId); + if (value.kind === 'PropertyLoad' && !usedOutside) { + if (innerFnContext == null || + temporaries.has(value.object.identifier.id)) { + const property = getProperty(value.object, value.property, false, temporaries); + temporaries.set(lvalue.identifier.id, property); + } + } + else if ((value.kind === 'LoadLocal' || isLoadContextMutable(value, instrId)) && + lvalue.identifier.name == null && + value.place.identifier.name !== null && + !usedOutside) { + if (innerFnContext == null || + fn.context.some(context => context.identifier.id === value.place.identifier.id)) { + temporaries.set(lvalue.identifier.id, { + identifier: value.place.identifier, + path: [], + }); + } + } + else if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + collectTemporariesSidemapImpl(value.loweredFunc.func, usedOutsideDeclaringScope, temporaries, innerFnContext !== null && innerFnContext !== void 0 ? innerFnContext : { instrId }); + } + } + } +} +function getProperty(object, propertyName, optional, temporaries) { + const resolvedDependency = temporaries.get(object.identifier.id); + let property; + if (resolvedDependency == null) { + property = { + identifier: object.identifier, + path: [{ property: propertyName, optional }], + }; + } + else { + property = { + identifier: resolvedDependency.identifier, + path: [...resolvedDependency.path, { property: propertyName, optional }], + }; + } + return property; +} +class DependencyCollectionContext { + constructor(temporariesUsedOutsideScope, temporaries, processedInstrsInOptional) { + _DependencyCollectionContext_instances.add(this); + _DependencyCollectionContext_declarations.set(this, new Map()); + _DependencyCollectionContext_reassignments.set(this, new Map()); + _DependencyCollectionContext_scopes.set(this, empty()); + _DependencyCollectionContext_dependencies.set(this, empty()); + this.deps = new Map(); + _DependencyCollectionContext_temporaries.set(this, void 0); + _DependencyCollectionContext_temporariesUsedOutsideScope.set(this, void 0); + _DependencyCollectionContext_processedInstrsInOptional.set(this, void 0); + _DependencyCollectionContext_innerFnContext.set(this, null); + __classPrivateFieldSet(this, _DependencyCollectionContext_temporariesUsedOutsideScope, temporariesUsedOutsideScope, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_temporaries, temporaries, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_processedInstrsInOptional, processedInstrsInOptional, "f"); + } + enterScope(scope) { + __classPrivateFieldSet(this, _DependencyCollectionContext_dependencies, __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").push([]), "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_scopes, __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").push(scope), "f"); + } + exitScope(scope, pruned) { + var _a; + const scopedDependencies = __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value; + CompilerError.invariant(scopedDependencies != null, { + reason: '[PropagateScopeDeps]: Unexpected scope mismatch', + loc: scope.loc, + }); + __classPrivateFieldSet(this, _DependencyCollectionContext_scopes, __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").pop(), "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_dependencies, __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").pop(), "f"); + for (const dep of scopedDependencies) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, dep)) { + (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value) === null || _a === void 0 ? void 0 : _a.push(dep); + } + } + if (!pruned) { + this.deps.set(scope, scopedDependencies); + } + } + isUsedOutsideDeclaringScope(place) { + return __classPrivateFieldGet(this, _DependencyCollectionContext_temporariesUsedOutsideScope, "f").has(place.identifier.declarationId); + } + declare(identifier, decl) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f") != null) + return; + if (!__classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").has(identifier.declarationId)) { + __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").set(identifier.declarationId, decl); + } + __classPrivateFieldGet(this, _DependencyCollectionContext_reassignments, "f").set(identifier, decl); + } + hasDeclared(identifier) { + return __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").has(identifier.declarationId); + } + get currentScope() { + return __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f"); + } + visitOperand(place) { + var _a; + this.visitDependency((_a = __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f").get(place.identifier.id)) !== null && _a !== void 0 ? _a : { + identifier: place.identifier, + path: [], + }); + } + visitProperty(object, property, optional) { + const nextDependency = getProperty(object, property, optional, __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f")); + this.visitDependency(nextDependency); + } + visitDependency(maybeDependency) { + var _a; + const originalDeclaration = __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").get(maybeDependency.identifier.declarationId); + if (originalDeclaration !== undefined && + originalDeclaration.scope.value !== null) { + originalDeclaration.scope.each(scope => { + if (!__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_isScopeActive).call(this, scope) && + !Iterable_some(scope.declarations.values(), decl => decl.identifier.declarationId === + maybeDependency.identifier.declarationId)) { + scope.declarations.set(maybeDependency.identifier.id, { + identifier: maybeDependency.identifier, + scope: originalDeclaration.scope.value, + }); + } + }); + } + if (isUseRefType(maybeDependency.identifier) && + ((_a = maybeDependency.path.at(0)) === null || _a === void 0 ? void 0 : _a.property) === 'current') { + maybeDependency = { + identifier: maybeDependency.identifier, + path: [], + }; + } + if (__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, maybeDependency)) { + __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value.push(maybeDependency); + } + } + visitReassignment(place) { + const currentScope = this.currentScope.value; + if (currentScope != null && + !Iterable_some(currentScope.reassignments, identifier => identifier.declarationId === place.identifier.declarationId) && + __classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, { identifier: place.identifier, path: [] })) { + currentScope.reassignments.add(place.identifier); + } + } + enterInnerFn(innerFn, cb) { + var _a; + const prevContext = __classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_innerFnContext, (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f")) !== null && _a !== void 0 ? _a : { outerInstrId: innerFn.id }, "f"); + const result = cb(); + __classPrivateFieldSet(this, _DependencyCollectionContext_innerFnContext, prevContext, "f"); + return result; + } + isDeferredDependency(instr) { + return (__classPrivateFieldGet(this, _DependencyCollectionContext_processedInstrsInOptional, "f").has(instr.value) || + (instr.kind === HIRValue.Instruction && + __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f").has(instr.value.lvalue.identifier.id))); + } +} +_DependencyCollectionContext_declarations = new WeakMap(), _DependencyCollectionContext_reassignments = new WeakMap(), _DependencyCollectionContext_scopes = new WeakMap(), _DependencyCollectionContext_dependencies = new WeakMap(), _DependencyCollectionContext_temporaries = new WeakMap(), _DependencyCollectionContext_temporariesUsedOutsideScope = new WeakMap(), _DependencyCollectionContext_processedInstrsInOptional = new WeakMap(), _DependencyCollectionContext_innerFnContext = new WeakMap(), _DependencyCollectionContext_instances = new WeakSet(), _DependencyCollectionContext_checkValidDependency = function _DependencyCollectionContext_checkValidDependency(maybeDependency) { + var _a; + if (isRefValueType(maybeDependency.identifier)) { + return false; + } + if (isObjectMethodType(maybeDependency.identifier)) { + return false; + } + const identifier = maybeDependency.identifier; + const currentDeclaration = (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_reassignments, "f").get(identifier)) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").get(identifier.declarationId); + const currentScope = this.currentScope.value; + return (currentScope != null && + currentDeclaration !== undefined && + currentDeclaration.id < currentScope.range.start); +}, _DependencyCollectionContext_isScopeActive = function _DependencyCollectionContext_isScopeActive(scope) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f") === null) { + return false; + } + return __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").find(state => state === scope); +}; +var HIRValue; +(function (HIRValue) { + HIRValue[HIRValue["Instruction"] = 1] = "Instruction"; + HIRValue[HIRValue["Terminal"] = 2] = "Terminal"; +})(HIRValue || (HIRValue = {})); +function handleInstruction(instr, context) { + const { id, value, lvalue } = instr; + context.declare(lvalue.identifier, { + id, + scope: context.currentScope, + }); + if (context.isDeferredDependency({ kind: HIRValue.Instruction, value: instr })) { + return; + } + if (value.kind === 'PropertyLoad') { + context.visitProperty(value.object, value.property, false); + } + else if (value.kind === 'StoreLocal') { + context.visitOperand(value.value); + if (value.lvalue.kind === InstructionKind.Reassign) { + context.visitReassignment(value.lvalue.place); + } + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + else if (value.kind === 'DeclareLocal' || value.kind === 'DeclareContext') { + if (convertHoistedLValueKind(value.lvalue.kind) === null) { + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + } + else if (value.kind === 'Destructure') { + context.visitOperand(value.value); + for (const place of eachPatternOperand(value.lvalue.pattern)) { + if (value.lvalue.kind === InstructionKind.Reassign) { + context.visitReassignment(place); + } + context.declare(place.identifier, { + id, + scope: context.currentScope, + }); + } + } + else if (value.kind === 'StoreContext') { + if (!context.hasDeclared(value.lvalue.place.identifier) || + value.lvalue.kind !== InstructionKind.Reassign) { + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + for (const operand of eachInstructionValueOperand(value)) { + context.visitOperand(operand); + } + } + else { + for (const operand of eachInstructionValueOperand(value)) { + context.visitOperand(operand); + } + } +} +function collectDependencies(fn, usedOutsideDeclaringScope, temporaries, processedInstrsInOptional) { + const context = new DependencyCollectionContext(usedOutsideDeclaringScope, temporaries, processedInstrsInOptional); + for (const param of fn.params) { + if (param.kind === 'Identifier') { + context.declare(param.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + else { + context.declare(param.place.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + } + const scopeTraversal = new ScopeBlockTraversal(); + const handleFunction = (fn) => { + for (const [blockId, block] of fn.body.blocks) { + scopeTraversal.recordScopes(block); + const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId); + if ((scopeBlockInfo === null || scopeBlockInfo === void 0 ? void 0 : scopeBlockInfo.kind) === 'begin') { + context.enterScope(scopeBlockInfo.scope); + } + else if ((scopeBlockInfo === null || scopeBlockInfo === void 0 ? void 0 : scopeBlockInfo.kind) === 'end') { + context.exitScope(scopeBlockInfo.scope, scopeBlockInfo.pruned); + } + for (const phi of block.phis) { + for (const operand of phi.operands) { + const maybeOptionalChain = temporaries.get(operand[1].identifier.id); + if (maybeOptionalChain) { + context.visitDependency(maybeOptionalChain); + } + } + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + context.declare(instr.lvalue.identifier, { + id: instr.id, + scope: context.currentScope, + }); + const innerFn = instr.value.loweredFunc.func; + context.enterInnerFn(instr, () => { + handleFunction(innerFn); + }); + } + else { + handleInstruction(instr, context); + } + } + if (!context.isDeferredDependency({ + kind: HIRValue.Terminal, + value: block.terminal, + })) { + for (const place of eachTerminalOperand(block.terminal)) { + context.visitOperand(place); + } + } + } + }; + handleFunction(fn); + return context.deps; +} + +function inferEffectDependencies(fn) { + var _a, _b; + let hasRewrite = false; + const fnExpressions = new Map(); + const autodepFnConfigs = new Map(); + for (const effectTarget of fn.env.config.inferEffectDependencies) { + const moduleTargets = getOrInsertWith(autodepFnConfigs, effectTarget.function.source, () => new Map()); + moduleTargets.set(effectTarget.function.importSpecifierName, effectTarget.numRequiredArgs); + } + const autodepFnLoads = new Map(); + const autodepModuleLoads = new Map(); + const scopeInfos = new Map(); + const loadGlobals = new Set(); + const reactiveIds = inferReactiveIdentifiers(fn); + for (const [, block] of fn.body.blocks) { + if (block.terminal.kind === 'scope') { + const scopeBlock = fn.body.blocks.get(block.terminal.block); + if (scopeBlock.instructions.length === 1 && + scopeBlock.terminal.kind === 'goto' && + scopeBlock.terminal.block === block.terminal.fallthrough) { + scopeInfos.set(block.terminal.scope.id, block.terminal.scope.dependencies); + } + } + const rewriteInstrs = new Map(); + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'FunctionExpression') { + fnExpressions.set(lvalue.identifier.id, instr); + } + else if (value.kind === 'PropertyLoad') { + if (typeof value.property === 'string' && + autodepModuleLoads.has(value.object.identifier.id)) { + const moduleTargets = autodepModuleLoads.get(value.object.identifier.id); + const propertyName = value.property; + const numRequiredArgs = moduleTargets.get(propertyName); + if (numRequiredArgs != null) { + autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs); + } + } + } + else if (value.kind === 'LoadGlobal') { + loadGlobals.add(lvalue.identifier.id); + if (value.binding.kind === 'ImportNamespace') { + const moduleTargets = autodepFnConfigs.get(value.binding.module); + if (moduleTargets != null) { + autodepModuleLoads.set(lvalue.identifier.id, moduleTargets); + } + } + if (value.binding.kind === 'ImportSpecifier' || + value.binding.kind === 'ImportDefault') { + const moduleTargets = autodepFnConfigs.get(value.binding.module); + if (moduleTargets != null) { + const importSpecifierName = value.binding.kind === 'ImportSpecifier' + ? value.binding.imported + : DEFAULT_EXPORT; + const numRequiredArgs = moduleTargets.get(importSpecifierName); + if (numRequiredArgs != null) { + autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs); + } + } + } + } + else if (value.kind === 'CallExpression' || + value.kind === 'MethodCall') { + const callee = value.kind === 'CallExpression' ? value.callee : value.property; + if (value.args.length === autodepFnLoads.get(callee.identifier.id) && + value.args[0].kind === 'Identifier') { + const effectDeps = []; + const newInstructions = []; + const deps = { + kind: 'ArrayExpression', + elements: effectDeps, + loc: GeneratedSource, + }; + const depsPlace = createTemporaryPlace(fn.env, GeneratedSource); + depsPlace.effect = Effect.Read; + const fnExpr = fnExpressions.get(value.args[0].identifier.id); + if (fnExpr != null) { + const scopeInfo = fnExpr.lvalue.identifier.scope != null + ? scopeInfos.get(fnExpr.lvalue.identifier.scope.id) + : null; + let minimalDeps; + if (scopeInfo != null) { + minimalDeps = new Set(scopeInfo); + } + else { + minimalDeps = inferMinimalDependencies(fnExpr); + } + const usedDeps = []; + for (const dep of minimalDeps) { + if (((isUseRefType(dep.identifier) || + isSetStateType(dep.identifier)) && + !reactiveIds.has(dep.identifier.id)) || + isFireFunctionType(dep.identifier)) { + continue; + } + const { place, instructions } = writeDependencyToInstructions(dep, reactiveIds.has(dep.identifier.id), fn.env, fnExpr.loc); + newInstructions.push(...instructions); + effectDeps.push(place); + usedDeps.push(dep); + } + const decorations = []; + for (const loc of collectDepUsages(usedDeps, fnExpr.value)) { + if (typeof loc === 'symbol') { + continue; + } + decorations.push(loc); + } + if (typeof value.loc !== 'symbol') { + (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.logEvent(fn.env.filename, { + kind: 'AutoDepsDecorations', + fnLoc: value.loc, + decorations, + }); + } + newInstructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, depsPlace), { effect: Effect.Mutate }), + value: deps, + }); + value.args.push(Object.assign(Object.assign({}, depsPlace), { effect: Effect.Freeze })); + rewriteInstrs.set(instr.id, newInstructions); + fn.env.inferredEffectLocations.add(callee.loc); + } + else if (loadGlobals.has(value.args[0].identifier.id)) { + newInstructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, depsPlace), { effect: Effect.Mutate }), + value: deps, + }); + value.args.push(Object.assign(Object.assign({}, depsPlace), { effect: Effect.Freeze })); + rewriteInstrs.set(instr.id, newInstructions); + fn.env.inferredEffectLocations.add(callee.loc); + } + } + else if (value.args.length >= 2 && + value.args.length - 1 === autodepFnLoads.get(callee.identifier.id) && + value.args[0] != null && + value.args[0].kind === 'Identifier') { + const penultimateArg = value.args[value.args.length - 2]; + const depArrayArg = value.args[value.args.length - 1]; + if (depArrayArg.kind !== 'Spread' && + penultimateArg.kind !== 'Spread' && + typeof depArrayArg.loc !== 'symbol' && + typeof penultimateArg.loc !== 'symbol' && + typeof value.loc !== 'symbol') { + (_b = fn.env.logger) === null || _b === void 0 ? void 0 : _b.logEvent(fn.env.filename, { + kind: 'AutoDepsEligible', + fnLoc: value.loc, + depArrayLoc: Object.assign(Object.assign({}, depArrayArg.loc), { start: penultimateArg.loc.end, end: depArrayArg.loc.end }), + }); + } + } + } + } + if (rewriteInstrs.size > 0) { + hasRewrite = true; + const newInstrs = []; + for (const instr of block.instructions) { + const newInstr = rewriteInstrs.get(instr.id); + if (newInstr != null) { + newInstrs.push(...newInstr, instr); + } + else { + newInstrs.push(instr); + } + } + block.instructions = newInstrs; + } + } + if (hasRewrite) { + markInstructionIds(fn.body); + fixScopeAndIdentifierRanges(fn.body); + fn.env.hasInferredEffect = true; + } +} +function writeDependencyToInstructions(dep, reactive, env, loc) { + const instructions = []; + let currValue = createTemporaryPlace(env, GeneratedSource); + currValue.reactive = reactive; + instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, currValue), { effect: Effect.Mutate }), + value: { + kind: 'LoadLocal', + place: { + kind: 'Identifier', + identifier: dep.identifier, + effect: Effect.Capture, + reactive, + loc: loc, + }, + loc: loc, + }, + }); + for (const path of dep.path) { + if (path.optional) { + break; + } + if (path.property === 'current') { + break; + } + const nextValue = createTemporaryPlace(env, GeneratedSource); + nextValue.reactive = reactive; + instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, nextValue), { effect: Effect.Mutate }), + value: { + kind: 'PropertyLoad', + object: Object.assign(Object.assign({}, currValue), { effect: Effect.Capture }), + property: path.property, + loc: loc, + }, + }); + currValue = nextValue; + } + currValue.effect = Effect.Freeze; + return { place: currValue, instructions }; +} +function inferReactiveIdentifiers(fn) { + const reactiveIds = new Set(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const place of eachInstructionOperand(instr)) { + if (place.reactive) { + reactiveIds.add(place.identifier.id); + } + } + } + for (const place of eachTerminalOperand(block.terminal)) { + if (place.reactive) { + reactiveIds.add(place.identifier.id); + } + } + } + return reactiveIds; +} +function collectDepUsages(deps, fnExpr) { + const identifiers = new Map(); + const loadedDeps = new Set(); + const sourceLocations = []; + for (const dep of deps) { + identifiers.set(dep.identifier.id, dep); + } + for (const [, block] of fnExpr.loweredFunc.func.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'LoadLocal' && + identifiers.has(instr.value.place.identifier.id)) { + loadedDeps.add(instr.lvalue.identifier.id); + } + for (const place of eachInstructionOperand(instr)) { + if (loadedDeps.has(place.identifier.id)) { + sourceLocations.push(place.identifier.loc); + } + } + } + } + return sourceLocations; +} +function inferMinimalDependencies(fnInstr) { + const fn = fnInstr.value.loweredFunc.func; + const temporaries = collectTemporariesSidemap(fn, new Set()); + const { hoistableObjects, processedInstrsInOptional, temporariesReadInOptional, } = collectOptionalChainSidemap(fn); + const hoistablePropertyLoads = collectHoistablePropertyLoadsInInnerFn(fnInstr, temporaries, hoistableObjects); + const hoistableToFnEntry = hoistablePropertyLoads.get(fn.body.entry); + CompilerError.invariant(hoistableToFnEntry != null, { + reason: '[InferEffectDependencies] Internal invariant broken: missing entry block', + loc: fnInstr.loc, + }); + const dependencies = inferDependencies(fnInstr, new Map([...temporaries, ...temporariesReadInOptional]), processedInstrsInOptional); + const tree = new ReactiveScopeDependencyTreeHIR([...hoistableToFnEntry.assumedNonNullObjects].map(o => o.fullPath)); + for (const dep of dependencies) { + tree.addDependency(Object.assign({}, dep)); + } + return tree.deriveMinimalDependencies(); +} +function inferDependencies(fnInstr, temporaries, processedInstrsInOptional) { + const fn = fnInstr.value.loweredFunc.func; + const context = new DependencyCollectionContext(new Set(), temporaries, processedInstrsInOptional); + for (const dep of fn.context) { + context.declare(dep.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + const placeholderScope = { + id: makeScopeId(0), + range: { + start: fnInstr.id, + end: makeInstructionId(fnInstr.id + 1), + }, + dependencies: new Set(), + reassignments: new Set(), + declarations: new Map(), + earlyReturnValue: null, + merged: new Set(), + loc: GeneratedSource, + }; + context.enterScope(placeholderScope); + inferDependenciesInFn(fn, context, temporaries); + context.exitScope(placeholderScope, false); + const resultUnfiltered = context.deps.get(placeholderScope); + CompilerError.invariant(resultUnfiltered != null, { + reason: '[InferEffectDependencies] Internal invariant broken: missing scope dependencies', + loc: fn.loc, + }); + const fnContext = new Set(fn.context.map(dep => dep.identifier.id)); + const result = new Set(); + for (const dep of resultUnfiltered) { + if (fnContext.has(dep.identifier.id)) { + result.add(dep); + } + } + return result; +} +function inferDependenciesInFn(fn, context, temporaries) { + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const operand of phi.operands) { + const maybeOptionalChain = temporaries.get(operand[1].identifier.id); + if (maybeOptionalChain) { + context.visitDependency(maybeOptionalChain); + } + } + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + context.declare(instr.lvalue.identifier, { + id: instr.id, + scope: context.currentScope, + }); + const innerFn = instr.value.loweredFunc.func; + context.enterInnerFn(instr, () => { + inferDependenciesInFn(innerFn, context, temporaries); + }); + } + else { + handleInstruction(instr, context); + } + } + } +} + +function instructionReordering(fn) { + var _a; + const shared = new Map(); + const references = findReferencedRangeOfTemporaries(fn); + for (const [, block] of fn.body.blocks) { + reorderBlock(fn.env, block, shared, references); + } + CompilerError.invariant(shared.size === 0, { + reason: `InstructionReordering: expected all reorderable nodes to have been emitted`, + loc: (_a = [...shared.values()] + .map(node => { var _a; return (_a = node.instruction) === null || _a === void 0 ? void 0 : _a.loc; }) + .filter(loc => loc != null)[0]) !== null && _a !== void 0 ? _a : GeneratedSource, + }); + markInstructionIds(fn.body); +} +var ReferenceKind; +(function (ReferenceKind) { + ReferenceKind[ReferenceKind["Read"] = 0] = "Read"; + ReferenceKind[ReferenceKind["Write"] = 1] = "Write"; +})(ReferenceKind || (ReferenceKind = {})); +function findReferencedRangeOfTemporaries(fn) { + const singleUseIdentifiers = new Map(); + const lastAssignments = new Map(); + function reference(instr, place, kind) { + var _a; + if (place.identifier.name !== null && + place.identifier.name.kind === 'named') { + if (kind === ReferenceKind.Write) { + const name = place.identifier.name.value; + const previous = lastAssignments.get(name); + if (previous === undefined) { + lastAssignments.set(name, instr); + } + else { + lastAssignments.set(name, makeInstructionId(Math.max(previous, instr))); + } + } + return; + } + else if (kind === ReferenceKind.Read) { + const previousCount = (_a = singleUseIdentifiers.get(place.identifier.id)) !== null && _a !== void 0 ? _a : 0; + singleUseIdentifiers.set(place.identifier.id, previousCount + 1); + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const operand of eachInstructionValueLValue(instr.value)) { + reference(instr.id, operand, ReferenceKind.Read); + } + for (const lvalue of eachInstructionLValue(instr)) { + reference(instr.id, lvalue, ReferenceKind.Write); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + reference(block.terminal.id, operand, ReferenceKind.Read); + } + } + return { + singleUseIdentifiers: new Set([...singleUseIdentifiers] + .filter(([, count]) => count === 1) + .map(([id]) => id)), + lastAssignments, + }; +} +function reorderBlock(env, block, shared, references) { + var _a, _b; + const locals = new Map(); + const named = new Map(); + let previous = null; + for (const instr of block.instructions) { + const { lvalue, value } = instr; + const reorderability = getReorderability(instr, references); + const node = getOrInsertWith(locals, lvalue.identifier.id, () => ({ + instruction: instr, + dependencies: new Set(), + reorderability, + depth: null, + })); + if (reorderability === Reorderability.Nonreorderable) { + if (previous !== null) { + node.dependencies.add(previous); + } + previous = lvalue.identifier.id; + } + for (const operand of eachInstructionValueOperand(value)) { + const { name, id } = operand.identifier; + if (name !== null && name.kind === 'named') { + const previous = named.get(name.value); + if (previous !== undefined) { + node.dependencies.add(previous); + } + named.set(name.value, lvalue.identifier.id); + } + else if (locals.has(id) || shared.has(id)) { + node.dependencies.add(id); + } + } + for (const lvalueOperand of eachInstructionValueLValue(value)) { + const lvalueNode = getOrInsertWith(locals, lvalueOperand.identifier.id, () => ({ + instruction: null, + dependencies: new Set(), + depth: null, + })); + lvalueNode.dependencies.add(lvalue.identifier.id); + const name = lvalueOperand.identifier.name; + if (name !== null && name.kind === 'named') { + const previous = named.get(name.value); + if (previous !== undefined) { + node.dependencies.add(previous); + } + named.set(name.value, lvalue.identifier.id); + } + } + } + const nextInstructions = []; + if (isExpressionBlockKind(block.kind)) { + if (previous !== null) { + emit(env, locals, shared, nextInstructions, previous); + } + if (block.instructions.length !== 0) { + emit(env, locals, shared, nextInstructions, block.instructions.at(-1).lvalue.identifier.id); + } + for (const operand of eachTerminalOperand(block.terminal)) { + emit(env, locals, shared, nextInstructions, operand.identifier.id); + } + for (const [id, node] of locals) { + if (node.instruction == null) { + continue; + } + CompilerError.invariant(node.reorderability === Reorderability.Reorderable, { + reason: `Expected all remaining instructions to be reorderable`, + loc: (_b = (_a = node.instruction) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : block.terminal.loc, + description: node.instruction != null + ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable` + : `Lvalue $${id} was not emitted yet but is not reorderable`, + }); + shared.set(id, node); + } + } + else { + for (const operand of eachTerminalOperand(block.terminal)) { + emit(env, locals, shared, nextInstructions, operand.identifier.id); + } + for (const id of Array.from(locals.keys()).reverse()) { + const node = locals.get(id); + if (node === undefined) { + continue; + } + if (node.reorderability === Reorderability.Reorderable) { + shared.set(id, node); + } + else { + emit(env, locals, shared, nextInstructions, id); + } + } + } + block.instructions = nextInstructions; +} +function getDepth(env, nodes, id) { + const node = nodes.get(id); + if (node == null) { + return 0; + } + if (node.depth != null) { + return node.depth; + } + node.depth = 0; + let depth = node.reorderability === Reorderability.Reorderable ? 1 : 10; + for (const dep of node.dependencies) { + depth += getDepth(env, nodes, dep); + } + node.depth = depth; + return depth; +} +function emit(env, locals, shared, instructions, id) { + var _a; + const node = (_a = locals.get(id)) !== null && _a !== void 0 ? _a : shared.get(id); + if (node == null) { + return; + } + locals.delete(id); + shared.delete(id); + const deps = [...node.dependencies]; + deps.sort((a, b) => { + const aDepth = getDepth(env, locals, a); + const bDepth = getDepth(env, locals, b); + return bDepth - aDepth; + }); + for (const dep of deps) { + emit(env, locals, shared, instructions, dep); + } + if (node.instruction !== null) { + instructions.push(node.instruction); + } +} +var Reorderability; +(function (Reorderability) { + Reorderability[Reorderability["Reorderable"] = 0] = "Reorderable"; + Reorderability[Reorderability["Nonreorderable"] = 1] = "Nonreorderable"; +})(Reorderability || (Reorderability = {})); +function getReorderability(instr, references) { + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': + case 'JSXText': + case 'LoadGlobal': + case 'Primitive': + case 'TemplateLiteral': + case 'BinaryExpression': + case 'UnaryExpression': { + return Reorderability.Reorderable; + } + case 'LoadLocal': { + const name = instr.value.place.identifier.name; + if (name !== null && name.kind === 'named') { + const lastAssignment = references.lastAssignments.get(name.value); + if (lastAssignment !== undefined && + lastAssignment < instr.id && + references.singleUseIdentifiers.has(instr.lvalue.identifier.id)) { + return Reorderability.Reorderable; + } + } + return Reorderability.Nonreorderable; + } + default: { + return Reorderability.Nonreorderable; + } + } +} + +function alignMethodCallScopes(fn) { + const scopeMapping = new Map(); + const mergedScopes = new DisjointSet(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { lvalue, value } = instr; + if (value.kind === 'MethodCall') { + const lvalueScope = lvalue.identifier.scope; + const propertyScope = value.property.identifier.scope; + if (lvalueScope !== null) { + if (propertyScope !== null) { + mergedScopes.union([lvalueScope, propertyScope]); + } + else { + scopeMapping.set(value.property.identifier.id, lvalueScope); + } + } + else if (propertyScope !== null) { + scopeMapping.set(value.property.identifier.id, null); + } + } + else if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + alignMethodCallScopes(value.loweredFunc.func); + } + } + } + mergedScopes.forEach((scope, root) => { + if (scope === root) { + return; + } + root.range.start = makeInstructionId(Math.min(scope.range.start, root.range.start)); + root.range.end = makeInstructionId(Math.max(scope.range.end, root.range.end)); + }); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const mappedScope = scopeMapping.get(instr.lvalue.identifier.id); + if (mappedScope !== undefined) { + instr.lvalue.identifier.scope = mappedScope; + } + else if (instr.lvalue.identifier.scope !== null) { + const mergedScope = mergedScopes.find(instr.lvalue.identifier.scope); + if (mergedScope != null) { + instr.lvalue.identifier.scope = mergedScope; + } + } + } + } +} + +function alignReactiveScopesToBlockScopesHIR(fn) { + var _a, _b, _c, _d, _e; + const activeBlockFallthroughRanges = []; + const activeScopes = new Set(); + const seen = new Set(); + const valueBlockNodes = new Map(); + const placeScopes = new Map(); + function recordPlace(id, place, node) { + if (place.identifier.scope !== null) { + placeScopes.set(place, place.identifier.scope); + } + const scope = getPlaceScope(id, place); + if (scope == null) { + return; + } + activeScopes.add(scope); + node === null || node === void 0 ? void 0 : node.children.push({ kind: 'scope', scope, id }); + if (seen.has(scope)) { + return; + } + seen.add(scope); + if (node != null && node.valueRange !== null) { + scope.range.start = makeInstructionId(Math.min(node.valueRange.start, scope.range.start)); + scope.range.end = makeInstructionId(Math.max(node.valueRange.end, scope.range.end)); + } + } + for (const [, block] of fn.body.blocks) { + const startingId = (_b = (_a = block.instructions[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id; + retainWhere_Set(activeScopes, scope => scope.range.end > startingId); + const top = activeBlockFallthroughRanges.at(-1); + if ((top === null || top === void 0 ? void 0 : top.fallthrough) === block.id) { + activeBlockFallthroughRanges.pop(); + for (const scope of activeScopes) { + scope.range.start = makeInstructionId(Math.min(scope.range.start, top.range.start)); + } + } + const { instructions, terminal } = block; + const node = (_c = valueBlockNodes.get(block.id)) !== null && _c !== void 0 ? _c : null; + for (const instr of instructions) { + for (const lvalue of eachInstructionLValue(instr)) { + recordPlace(instr.id, lvalue, node); + } + for (const operand of eachInstructionValueOperand(instr.value)) { + recordPlace(instr.id, operand, node); + } + } + for (const operand of eachTerminalOperand(terminal)) { + recordPlace(terminal.id, operand, node); + } + const fallthrough = terminalFallthrough(terminal); + if (fallthrough !== null && terminal.kind !== 'branch') { + const fallthroughBlock = fn.body.blocks.get(fallthrough); + const nextId = (_e = (_d = fallthroughBlock.instructions[0]) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : fallthroughBlock.terminal.id; + for (const scope of activeScopes) { + if (scope.range.end > terminal.id) { + scope.range.end = makeInstructionId(Math.max(scope.range.end, nextId)); + } + } + activeBlockFallthroughRanges.push({ + fallthrough, + range: { + start: terminal.id, + end: nextId, + }, + }); + CompilerError.invariant(!valueBlockNodes.has(fallthrough), { + reason: 'Expect hir blocks to have unique fallthroughs', + loc: terminal.loc, + }); + if (node != null) { + valueBlockNodes.set(fallthrough, node); + } + } + mapTerminalSuccessors(terminal, successor => { + var _a, _b; + if (valueBlockNodes.has(successor)) { + return successor; + } + const successorBlock = fn.body.blocks.get(successor); + if (successorBlock.kind === 'block' || successorBlock.kind === 'catch') ; + else if (node == null || + terminal.kind === 'ternary' || + terminal.kind === 'logical' || + terminal.kind === 'optional') { + let valueRange; + if (node == null) { + CompilerError.invariant(fallthrough !== null, { + reason: `Expected a fallthrough for value block`, + loc: terminal.loc, + }); + const fallthroughBlock = fn.body.blocks.get(fallthrough); + const nextId = (_b = (_a = fallthroughBlock.instructions[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : fallthroughBlock.terminal.id; + valueRange = { + start: terminal.id, + end: nextId, + }; + } + else { + valueRange = node.valueRange; + } + const childNode = { + kind: 'node', + id: terminal.id, + children: [], + valueRange, + }; + node === null || node === void 0 ? void 0 : node.children.push(childNode); + valueBlockNodes.set(successor, childNode); + } + else { + valueBlockNodes.set(successor, node); + } + return successor; + }); + } +} + +function flattenReactiveLoopsHIR(fn) { + const activeLoops = Array(); + for (const [, block] of fn.body.blocks) { + retainWhere(activeLoops, id => id !== block.id); + const { terminal } = block; + switch (terminal.kind) { + case 'do-while': + case 'for': + case 'for-in': + case 'for-of': + case 'while': { + activeLoops.push(terminal.fallthrough); + break; + } + case 'scope': { + if (activeLoops.length !== 0) { + block.terminal = { + kind: 'pruned-scope', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + scope: terminal.scope, + }; + } + break; + } + case 'branch': + case 'goto': + case 'if': + case 'label': + case 'logical': + case 'maybe-throw': + case 'optional': + case 'pruned-scope': + case 'return': + case 'sequence': + case 'switch': + case 'ternary': + case 'throw': + case 'try': + case 'unreachable': + case 'unsupported': { + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } +} + +function flattenScopesWithHooksOrUseHIR(fn) { + const activeScopes = []; + const prune = []; + for (const [, block] of fn.body.blocks) { + retainWhere(activeScopes, current => current.fallthrough !== block.id); + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'MethodCall': + case 'CallExpression': { + const callee = value.kind === 'MethodCall' ? value.property : value.callee; + if (getHookKind(fn.env, callee.identifier) != null || + isUseOperator(callee.identifier)) { + prune.push(...activeScopes.map(entry => entry.block)); + activeScopes.length = 0; + } + } + } + } + if (block.terminal.kind === 'scope') { + activeScopes.push({ + block: block.id, + fallthrough: block.terminal.fallthrough, + }); + } + } + for (const id of prune) { + const block = fn.body.blocks.get(id); + const terminal = block.terminal; + CompilerError.invariant(terminal.kind === 'scope', { + reason: `Expected block to have a scope terminal`, + description: `Expected block bb${block.id} to end in a scope terminal`, + loc: terminal.loc, + }); + const body = fn.body.blocks.get(terminal.block); + if (body.instructions.length === 1 && + body.terminal.kind === 'goto' && + body.terminal.block === terminal.fallthrough) { + block.terminal = { + kind: 'label', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + }; + continue; + } + block.terminal = { + kind: 'pruned-scope', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + scope: terminal.scope, + }; + } +} + +function pruneAlwaysInvalidatingScopes(fn) { + visitReactiveFunction(fn, new Transform(), false); +} +class Transform extends ReactiveFunctionTransform { + constructor() { + super(...arguments); + this.alwaysInvalidatingValues = new Set(); + this.unmemoizedValues = new Set(); + } + transformInstruction(instruction, withinScope) { + this.visitInstruction(instruction, withinScope); + const { lvalue, value } = instruction; + switch (value.kind) { + case 'ArrayExpression': + case 'ObjectExpression': + case 'JsxExpression': + case 'JsxFragment': + case 'NewExpression': { + if (lvalue !== null) { + this.alwaysInvalidatingValues.add(lvalue.identifier); + if (!withinScope) { + this.unmemoizedValues.add(lvalue.identifier); + } + } + break; + } + case 'StoreLocal': { + if (this.alwaysInvalidatingValues.has(value.value.identifier)) { + this.alwaysInvalidatingValues.add(value.lvalue.place.identifier); + } + if (this.unmemoizedValues.has(value.value.identifier)) { + this.unmemoizedValues.add(value.lvalue.place.identifier); + } + break; + } + case 'LoadLocal': { + if (lvalue !== null && + this.alwaysInvalidatingValues.has(value.place.identifier)) { + this.alwaysInvalidatingValues.add(lvalue.identifier); + } + if (lvalue !== null && + this.unmemoizedValues.has(value.place.identifier)) { + this.unmemoizedValues.add(lvalue.identifier); + } + break; + } + } + return { kind: 'keep' }; + } + transformScope(scopeBlock, _withinScope) { + this.visitScope(scopeBlock, true); + for (const dep of scopeBlock.scope.dependencies) { + if (this.unmemoizedValues.has(dep.identifier)) { + for (const [_, decl] of scopeBlock.scope.declarations) { + if (this.alwaysInvalidatingValues.has(decl.identifier)) { + this.unmemoizedValues.add(decl.identifier); + } + } + for (const identifier of scopeBlock.scope.reassignments) { + if (this.alwaysInvalidatingValues.has(identifier)) { + this.unmemoizedValues.add(identifier); + } + } + return { + kind: 'replace', + value: { + kind: 'pruned-scope', + scope: scopeBlock.scope, + instructions: scopeBlock.instructions, + }, + }; + } + } + return { kind: 'keep' }; + } +} + +let Visitor$2 = class Visitor extends ReactiveFunctionVisitor { + constructor(env, aliases, paths) { + super(); + this.map = new Map(); + this.aliases = aliases; + this.paths = paths; + this.env = env; + } + join(values) { + function join2(l, r) { + if (l === 'Update' || r === 'Update') { + return 'Update'; + } + else if (l === 'Create' || r === 'Create') { + return 'Create'; + } + else if (l === 'Unknown' || r === 'Unknown') { + return 'Unknown'; + } + assertExhaustive$1(r, `Unhandled variable kind ${r}`); + } + return values.reduce(join2, 'Unknown'); + } + isCreateOnlyHook(id) { + return isUseStateType(id) || isUseRefType(id); + } + visitPlace(_, place, state) { + var _a; + this.map.set(place.identifier.id, this.join([state, (_a = this.map.get(place.identifier.id)) !== null && _a !== void 0 ? _a : 'Unknown'])); + } + visitBlock(block, state) { + super.visitBlock([...block].reverse(), state); + } + visitInstruction(instruction) { + const state = this.join([...eachInstructionLValue(instruction)].map(operand => { var _a; return (_a = this.map.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : 'Unknown'; })); + const visitCallOrMethodNonArgs = () => { + switch (instruction.value.kind) { + case 'CallExpression': { + this.visitPlace(instruction.id, instruction.value.callee, state); + break; + } + case 'MethodCall': { + this.visitPlace(instruction.id, instruction.value.property, state); + this.visitPlace(instruction.id, instruction.value.receiver, state); + break; + } + } + }; + const isHook = () => { + let callee = null; + switch (instruction.value.kind) { + case 'CallExpression': { + callee = instruction.value.callee.identifier; + break; + } + case 'MethodCall': { + callee = instruction.value.property.identifier; + break; + } + } + return callee != null && getHookKind(this.env, callee) != null; + }; + switch (instruction.value.kind) { + case 'CallExpression': + case 'MethodCall': { + if (instruction.lvalue && + this.isCreateOnlyHook(instruction.lvalue.identifier)) { + [...eachCallArgument(instruction.value.args)].forEach(operand => this.visitPlace(instruction.id, operand, 'Create')); + visitCallOrMethodNonArgs(); + } + else { + this.traverseInstruction(instruction, isHook() ? 'Update' : state); + } + break; + } + default: { + this.traverseInstruction(instruction, state); + } + } + } + visitScope(scope) { + const state = this.join([ + ...scope.scope.declarations.keys(), + ...[...scope.scope.reassignments.values()].map(ident => ident.id), + ].map(id => { var _a; return (_a = this.map.get(id)) !== null && _a !== void 0 ? _a : 'Unknown'; })); + super.visitScope(scope, state); + [...scope.scope.dependencies].forEach(ident => { + var _a; + let target = (_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0 ? _a : ident.identifier.id; + ident.path.forEach(token => { + var _a; + target && (target = (_a = this.paths.get(target)) === null || _a === void 0 ? void 0 : _a.get(token.property)); + }); + if (target && this.map.get(target) === 'Create') { + scope.scope.dependencies.delete(ident); + } + }); + } + visitTerminal(stmt, state) { + CompilerError.invariant(state !== 'Create', { + reason: "Visiting a terminal statement with state 'Create'", + loc: stmt.terminal.loc, + }); + super.visitTerminal(stmt, state); + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +}; +function pruneInitializationDependencies(fn) { + const [aliases, paths] = getAliases(fn); + visitReactiveFunction(fn, new Visitor$2(fn.env, aliases, paths), 'Update'); +} +function update(map, key, path, value) { + var _a; + const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map(); + inner.set(path, value); + map.set(key, inner); +} +class AliasVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopeIdentifiers = new DisjointSet(); + this.scopePaths = new Map(); + } + visitInstruction(instr) { + if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext') { + this.scopeIdentifiers.union([ + instr.value.lvalue.place.identifier.id, + instr.value.value.identifier.id, + ]); + } + else if (instr.value.kind === 'LoadLocal' || + instr.value.kind === 'LoadContext') { + instr.lvalue && + this.scopeIdentifiers.union([ + instr.lvalue.identifier.id, + instr.value.place.identifier.id, + ]); + } + else if (instr.value.kind === 'PropertyLoad') { + instr.lvalue && + update(this.scopePaths, instr.value.object.identifier.id, instr.value.property, instr.lvalue.identifier.id); + } + else if (instr.value.kind === 'PropertyStore') { + update(this.scopePaths, instr.value.object.identifier.id, instr.value.property, instr.value.value.identifier.id); + } + } +} +function getAliases(fn) { + var _a, _b; + const visitor = new AliasVisitor(); + visitReactiveFunction(fn, visitor, null); + let disjoint = visitor.scopeIdentifiers; + let scopePaths = new Map(); + for (const [key, value] of visitor.scopePaths) { + for (const [path, id] of value) { + update(scopePaths, (_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key, path, (_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id); + } + } + return [disjoint, scopePaths]; +} + +function isPrimitiveBinaryOp(op) { + switch (op) { + case '+': + case '-': + case '/': + case '%': + case '*': + case '**': + case '&': + case '|': + case '>>': + case '<<': + case '^': + case '>': + case '<': + case '>=': + case '<=': + case '|>': + return true; + default: + return false; + } +} +function inferTypes(func) { + const unifier = new Unifier(func.env); + for (const e of generate(func)) { + unifier.unify(e.left, e.right); + } + apply(func, unifier); +} +function apply(func, unifier) { + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + phi.place.identifier.type = unifier.get(phi.place.identifier.type); + } + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + operand.identifier.type = unifier.get(operand.identifier.type); + } + for (const place of eachInstructionOperand(instr)) { + place.identifier.type = unifier.get(place.identifier.type); + } + const { lvalue, value } = instr; + lvalue.identifier.type = unifier.get(lvalue.identifier.type); + if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + apply(value.loweredFunc.func, unifier); + } + } + } + func.returnType = unifier.get(func.returnType); +} +function equation(left, right) { + return { + left, + right, + }; +} +function* generate(func) { + if (func.fnType === 'Component') { + const [props, ref] = func.params; + if (props && props.kind === 'Identifier') { + yield equation(props.identifier.type, { + kind: 'Object', + shapeId: BuiltInPropsId, + }); + } + if (ref && ref.kind === 'Identifier') { + yield equation(ref.identifier.type, { + kind: 'Object', + shapeId: BuiltInUseRefId, + }); + } + } + const names = new Map(); + const returnTypes = []; + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + yield equation(phi.place.identifier.type, { + kind: 'Phi', + operands: [...phi.operands.values()].map(id => id.identifier.type), + }); + } + for (const instr of block.instructions) { + yield* generateInstructionTypes(func.env, names, instr); + } + const terminal = block.terminal; + if (terminal.kind === 'return') { + returnTypes.push(terminal.value.identifier.type); + } + } + if (returnTypes.length > 1) { + yield equation(func.returnType, { + kind: 'Phi', + operands: returnTypes, + }); + } + else if (returnTypes.length === 1) { + yield equation(func.returnType, returnTypes[0]); + } +} +function setName(names, id, name) { + var _a; + if (((_a = name.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named') { + names.set(id, name.name.value); + } +} +function getName(names, id) { + var _a; + return (_a = names.get(id)) !== null && _a !== void 0 ? _a : ''; +} +function* generateInstructionTypes(env, names, instr) { + const { lvalue, value } = instr; + const left = lvalue.identifier.type; + switch (value.kind) { + case 'TemplateLiteral': + case 'JSXText': + case 'Primitive': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'UnaryExpression': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'LoadLocal': { + setName(names, lvalue.identifier.id, value.place.identifier); + yield equation(left, value.place.identifier.type); + break; + } + case 'DeclareContext': + case 'StoreContext': + case 'LoadContext': { + break; + } + case 'StoreLocal': { + if (env.config.enableUseTypeAnnotations) { + yield equation(value.lvalue.place.identifier.type, value.value.identifier.type); + const valueType = value.type === null ? makeType() : lowerType(value.type); + yield equation(valueType, value.lvalue.place.identifier.type); + yield equation(left, valueType); + } + else { + yield equation(left, value.value.identifier.type); + yield equation(value.lvalue.place.identifier.type, value.value.identifier.type); + } + break; + } + case 'StoreGlobal': { + yield equation(left, value.value.identifier.type); + break; + } + case 'BinaryExpression': { + if (isPrimitiveBinaryOp(value.operator)) { + yield equation(value.left.identifier.type, { kind: 'Primitive' }); + yield equation(value.right.identifier.type, { kind: 'Primitive' }); + } + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + yield equation(value.value.identifier.type, { kind: 'Primitive' }); + yield equation(value.lvalue.identifier.type, { kind: 'Primitive' }); + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'LoadGlobal': { + const globalType = env.getGlobalDeclaration(value.binding, value.loc); + if (globalType) { + yield equation(left, globalType); + } + break; + } + case 'CallExpression': { + const returnType = makeType(); + yield equation(value.callee.identifier.type, { + kind: 'Function', + shapeId: null, + return: returnType, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'TaggedTemplateExpression': { + const returnType = makeType(); + yield equation(value.tag.identifier.type, { + kind: 'Function', + shapeId: null, + return: returnType, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'ObjectExpression': { + for (const property of value.properties) { + if (property.kind === 'ObjectProperty' && + property.key.kind === 'computed') { + yield equation(property.key.name.identifier.type, { + kind: 'Primitive', + }); + } + } + yield equation(left, { kind: 'Object', shapeId: BuiltInObjectId }); + break; + } + case 'ArrayExpression': { + yield equation(left, { kind: 'Object', shapeId: BuiltInArrayId }); + break; + } + case 'PropertyLoad': { + yield equation(left, { + kind: 'Property', + objectType: value.object.identifier.type, + objectName: getName(names, value.object.identifier.id), + propertyName: { + kind: 'literal', + value: value.property, + }, + }); + break; + } + case 'ComputedLoad': { + yield equation(left, { + kind: 'Property', + objectType: value.object.identifier.type, + objectName: getName(names, value.object.identifier.id), + propertyName: { + kind: 'computed', + value: value.property.identifier.type, + }, + }); + break; + } + case 'MethodCall': { + const returnType = makeType(); + yield equation(value.property.identifier.type, { + kind: 'Function', + return: returnType, + shapeId: null, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'Destructure': { + const pattern = value.lvalue.pattern; + if (pattern.kind === 'ArrayPattern') { + for (let i = 0; i < pattern.items.length; i++) { + const item = pattern.items[i]; + if (item.kind === 'Identifier') { + const propertyName = String(i); + yield equation(item.identifier.type, { + kind: 'Property', + objectType: value.value.identifier.type, + objectName: getName(names, value.value.identifier.id), + propertyName: { + kind: 'literal', + value: makePropertyLiteral(propertyName), + }, + }); + } + else { + break; + } + } + } + else { + for (const property of pattern.properties) { + if (property.kind === 'ObjectProperty') { + if (property.key.kind === 'identifier' || + property.key.kind === 'string') { + yield equation(property.place.identifier.type, { + kind: 'Property', + objectType: value.value.identifier.type, + objectName: getName(names, value.value.identifier.id), + propertyName: { + kind: 'literal', + value: makePropertyLiteral(property.key.name), + }, + }); + } + } + } + } + break; + } + case 'TypeCastExpression': { + if (env.config.enableUseTypeAnnotations) { + yield equation(value.type, value.value.identifier.type); + yield equation(left, value.type); + } + else { + yield equation(left, value.value.identifier.type); + } + break; + } + case 'PropertyDelete': + case 'ComputedDelete': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'FunctionExpression': { + yield* generate(value.loweredFunc.func); + yield equation(left, { + kind: 'Function', + shapeId: BuiltInFunctionId, + return: value.loweredFunc.func.returnType, + isConstructor: false, + }); + break; + } + case 'NextPropertyOf': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'ObjectMethod': { + yield* generate(value.loweredFunc.func); + yield equation(left, { kind: 'ObjectMethod' }); + break; + } + case 'JsxExpression': + case 'JsxFragment': { + yield equation(left, { kind: 'Object', shapeId: BuiltInJsxId }); + break; + } + case 'NewExpression': { + const returnType = makeType(); + yield equation(value.callee.identifier.type, { + kind: 'Function', + return: returnType, + shapeId: null, + isConstructor: true, + }); + yield equation(left, returnType); + break; + } + case 'PropertyStore': + case 'DeclareLocal': + case 'RegExpLiteral': + case 'MetaProperty': + case 'ComputedStore': + case 'Await': + case 'GetIterator': + case 'IteratorNext': + case 'UnsupportedNode': + case 'Debugger': + case 'FinishMemoize': + case 'StartMemoize': { + break; + } + default: + assertExhaustive$1(value, `Unhandled instruction value kind: ${value.kind}`); + } +} +class Unifier { + constructor(env) { + this.substitutions = new Map(); + this.env = env; + } + unify(tA, tB) { + if (tB.kind === 'Property') { + if (this.env.config.enableTreatRefLikeIdentifiersAsRefs && + isRefLikeName(tB)) { + this.unify(tB.objectType, { + kind: 'Object', + shapeId: BuiltInUseRefId, + }); + this.unify(tA, { + kind: 'Object', + shapeId: BuiltInRefValueId, + }); + return; + } + const objectType = this.get(tB.objectType); + const propertyType = tB.propertyName.kind === 'literal' + ? this.env.getPropertyType(objectType, tB.propertyName.value) + : this.env.getFallthroughPropertyType(objectType, tB.propertyName.value); + if (propertyType !== null) { + this.unify(tA, propertyType); + } + return; + } + if (typeEquals(tA, tB)) { + return; + } + if (tA.kind === 'Type') { + this.bindVariableTo(tA, tB); + return; + } + if (tB.kind === 'Type') { + this.bindVariableTo(tB, tA); + return; + } + if (tB.kind === 'Function' && + tA.kind === 'Function' && + tA.isConstructor === tB.isConstructor) { + this.unify(tA.return, tB.return); + return; + } + } + bindVariableTo(v, type) { + if (type.kind === 'Poly') { + return; + } + if (this.substitutions.has(v.id)) { + this.unify(this.substitutions.get(v.id), type); + return; + } + if (type.kind === 'Type' && this.substitutions.has(type.id)) { + this.unify(v, this.substitutions.get(type.id)); + return; + } + if (type.kind === 'Phi') { + CompilerError.invariant(type.operands.length > 0, { + reason: 'there should be at least one operand', + description: null, + loc: null, + suggestions: null, + }); + let candidateType = null; + for (const operand of type.operands) { + const resolved = this.get(operand); + if (candidateType === null) { + candidateType = resolved; + } + else if (!typeEquals(resolved, candidateType)) { + const unionType = tryUnionTypes(resolved, candidateType); + if (unionType === null) { + candidateType = null; + break; + } + else { + candidateType = unionType; + } + } + } + if (candidateType !== null) { + this.unify(v, candidateType); + return; + } + } + if (this.occursCheck(v, type)) { + const resolvedType = this.tryResolveType(v, type); + if (resolvedType !== null) { + this.substitutions.set(v.id, resolvedType); + return; + } + throw new Error('cycle detected'); + } + this.substitutions.set(v.id, type); + } + tryResolveType(v, type) { + switch (type.kind) { + case 'Phi': { + const operands = []; + for (const operand of type.operands) { + if (operand.kind === 'Type' && operand.id === v.id) { + continue; + } + const resolved = this.tryResolveType(v, operand); + if (resolved === null) { + return null; + } + operands.push(resolved); + } + return { kind: 'Phi', operands }; + } + case 'Type': { + const substitution = this.get(type); + if (substitution !== type) { + const resolved = this.tryResolveType(v, substitution); + if (resolved !== null) { + this.substitutions.set(type.id, resolved); + } + return resolved; + } + return type; + } + case 'Property': { + const objectType = this.tryResolveType(v, this.get(type.objectType)); + if (objectType === null) { + return null; + } + return { + kind: 'Property', + objectName: type.objectName, + objectType, + propertyName: type.propertyName, + }; + } + case 'Function': { + const returnType = this.tryResolveType(v, this.get(type.return)); + if (returnType === null) { + return null; + } + return { + kind: 'Function', + return: returnType, + shapeId: type.shapeId, + isConstructor: type.isConstructor, + }; + } + case 'ObjectMethod': + case 'Object': + case 'Primitive': + case 'Poly': { + return type; + } + default: { + assertExhaustive$1(type, `Unexpected type kind '${type.kind}'`); + } + } + } + occursCheck(v, type) { + if (typeEquals(v, type)) + return true; + if (type.kind === 'Type' && this.substitutions.has(type.id)) { + return this.occursCheck(v, this.substitutions.get(type.id)); + } + if (type.kind === 'Phi') { + return type.operands.some(o => this.occursCheck(v, o)); + } + if (type.kind === 'Function') { + return this.occursCheck(v, type.return); + } + return false; + } + get(type) { + if (type.kind === 'Type') { + if (this.substitutions.has(type.id)) { + return this.get(this.substitutions.get(type.id)); + } + } + if (type.kind === 'Phi') { + return { kind: 'Phi', operands: type.operands.map(o => this.get(o)) }; + } + return type; + } +} +const RefLikeNameRE = /^(?:[a-zA-Z$_][a-zA-Z$_0-9]*)Ref$|^ref$/; +function isRefLikeName(t) { + return (t.propertyName.kind === 'literal' && + RefLikeNameRE.test(t.objectName) && + t.propertyName.value === 'current'); +} +function tryUnionTypes(ty1, ty2) { + let readonlyType; + let otherType; + if (ty1.kind === 'Object' && ty1.shapeId === BuiltInMixedReadonlyId) { + readonlyType = ty1; + otherType = ty2; + } + else if (ty2.kind === 'Object' && ty2.shapeId === BuiltInMixedReadonlyId) { + readonlyType = ty2; + otherType = ty1; + } + else { + return null; + } + if (otherType.kind === 'Primitive') { + return readonlyType; + } + else if (otherType.kind === 'Object' && + otherType.shapeId === BuiltInArrayId) { + return otherType; + } + return null; +} + +function validateContextVariableLValues(fn) { + const identifierKinds = new Map(); + validateContextVariableLValuesImpl(fn, identifierKinds); +} +function validateContextVariableLValuesImpl(fn, identifierKinds) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'DeclareContext': + case 'StoreContext': { + visit(identifierKinds, value.lvalue.place, 'context'); + break; + } + case 'LoadContext': { + visit(identifierKinds, value.place, 'context'); + break; + } + case 'StoreLocal': + case 'DeclareLocal': { + visit(identifierKinds, value.lvalue.place, 'local'); + break; + } + case 'LoadLocal': { + visit(identifierKinds, value.place, 'local'); + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + visit(identifierKinds, value.lvalue, 'local'); + break; + } + case 'Destructure': { + for (const lvalue of eachPatternOperand(value.lvalue.pattern)) { + visit(identifierKinds, lvalue, 'destructure'); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + validateContextVariableLValuesImpl(value.loweredFunc.func, identifierKinds); + break; + } + default: { + for (const _ of eachInstructionValueLValue(value)) { + CompilerError.throwTodo({ + reason: 'ValidateContextVariableLValues: unhandled instruction variant', + loc: value.loc, + description: `Handle '${value.kind} lvalues`, + suggestions: null, + }); + } + } + } + } + } +} +function visit(identifiers, place, kind) { + const prev = identifiers.get(place.identifier.id); + if (prev !== undefined) { + const wasContext = prev.kind === 'context'; + const isContext = kind === 'context'; + if (wasContext !== isContext) { + if (prev.kind === 'destructure' || kind === 'destructure') { + CompilerError.throwTodo({ + reason: `Support destructuring of context variables`, + loc: kind === 'destructure' ? place.loc : prev.place.loc, + description: null, + suggestions: null, + }); + } + CompilerError.invariant(false, { + reason: `Expected all references to a variable to be consistently local or context references`, + loc: place.loc, + description: `Identifier ${printPlace(place)} is referenced as a ${kind} variable, but was previously referenced as a ${prev} variable`, + suggestions: null, + }); + } + } + identifiers.set(place.identifier.id, { place, kind }); +} + +function computeUnconditionalBlocks(fn) { + const unconditionalBlocks = new Set(); + const dominators = computePostDominatorTree(fn, { + includeThrowsAsExitNode: false, + }); + const exit = dominators.exit; + let current = fn.body.entry; + while (current !== null && current !== exit) { + CompilerError.invariant(!unconditionalBlocks.has(current), { + reason: 'Internal error: non-terminating loop in ComputeUnconditionalBlocks', + loc: null, + suggestions: null, + }); + unconditionalBlocks.add(current); + current = dominators.get(current); + } + return unconditionalBlocks; +} + +var Kind; +(function (Kind) { + Kind["Error"] = "Error"; + Kind["KnownHook"] = "KnownHook"; + Kind["PotentialHook"] = "PotentialHook"; + Kind["Global"] = "Global"; + Kind["Local"] = "Local"; +})(Kind || (Kind = {})); +function joinKinds(a, b) { + if (a === Kind.Error || b === Kind.Error) { + return Kind.Error; + } + else if (a === Kind.KnownHook || b === Kind.KnownHook) { + return Kind.KnownHook; + } + else if (a === Kind.PotentialHook || b === Kind.PotentialHook) { + return Kind.PotentialHook; + } + else if (a === Kind.Global || b === Kind.Global) { + return Kind.Global; + } + else { + return Kind.Local; + } +} +function validateHooksUsage(fn) { + const unconditionalBlocks = computeUnconditionalBlocks(fn); + const errors = new CompilerError(); + const errorsByPlace = new Map(); + function recordError(loc, errorDetail) { + if (typeof loc === 'symbol') { + errors.pushErrorDetail(errorDetail); + } + else { + errorsByPlace.set(loc, errorDetail); + } + } + function recordConditionalHookError(place) { + setKind(place, Kind.Error); + const reason = 'Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)'; + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined || previousError.reason !== reason) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason, + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + function recordInvalidHookUsageError(place) { + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason: 'Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values', + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + function recordDynamicHookUsageError(place) { + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason: 'Hooks must be the same function on every render, but this value may change over time to a different function. See https://react.dev/reference/rules/react-calls-components-and-hooks#dont-dynamically-use-hooks', + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + const valueKinds = new Map(); + function getKindForPlace(place) { + const knownKind = valueKinds.get(place.identifier.id); + if (place.identifier.name !== null && + isHookName$2(place.identifier.name.value)) { + return joinKinds(knownKind !== null && knownKind !== void 0 ? knownKind : Kind.Local, Kind.PotentialHook); + } + else { + return knownKind !== null && knownKind !== void 0 ? knownKind : Kind.Local; + } + } + function visitPlace(place) { + const kind = valueKinds.get(place.identifier.id); + if (kind === Kind.KnownHook) { + recordInvalidHookUsageError(place); + } + } + function setKind(place, kind) { + valueKinds.set(place.identifier.id, kind); + } + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + const kind = getKindForPlace(place); + setKind(place, kind); + } + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + let kind = phi.place.identifier.name !== null && + isHookName$2(phi.place.identifier.name.value) + ? Kind.PotentialHook + : Kind.Local; + for (const [, operand] of phi.operands) { + const operandKind = valueKinds.get(operand.identifier.id); + if (operandKind !== undefined) { + kind = joinKinds(kind, operandKind); + } + } + valueKinds.set(phi.place.identifier.id, kind); + } + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadGlobal': { + if (getHookKind(fn.env, instr.lvalue.identifier) != null) { + setKind(instr.lvalue, Kind.KnownHook); + } + else { + setKind(instr.lvalue, Kind.Global); + } + break; + } + case 'LoadContext': + case 'LoadLocal': { + visitPlace(instr.value.place); + const kind = getKindForPlace(instr.value.place); + setKind(instr.lvalue, kind); + break; + } + case 'StoreLocal': + case 'StoreContext': { + visitPlace(instr.value.value); + const kind = joinKinds(getKindForPlace(instr.value.value), getKindForPlace(instr.value.lvalue.place)); + setKind(instr.value.lvalue.place, kind); + setKind(instr.lvalue, kind); + break; + } + case 'ComputedLoad': { + visitPlace(instr.value.object); + const kind = getKindForPlace(instr.value.object); + setKind(instr.lvalue, joinKinds(getKindForPlace(instr.lvalue), kind)); + break; + } + case 'PropertyLoad': { + const objectKind = getKindForPlace(instr.value.object); + const isHookProperty = typeof instr.value.property === 'string' && + isHookName$2(instr.value.property); + let kind; + switch (objectKind) { + case Kind.Error: { + kind = Kind.Error; + break; + } + case Kind.KnownHook: { + kind = isHookProperty ? Kind.KnownHook : Kind.Local; + break; + } + case Kind.PotentialHook: { + kind = Kind.PotentialHook; + break; + } + case Kind.Global: { + kind = isHookProperty ? Kind.KnownHook : Kind.Global; + break; + } + case Kind.Local: { + kind = isHookProperty ? Kind.PotentialHook : Kind.Local; + break; + } + default: { + assertExhaustive$1(objectKind, `Unexpected kind \`${objectKind}\``); + } + } + setKind(instr.lvalue, kind); + break; + } + case 'CallExpression': { + const calleeKind = getKindForPlace(instr.value.callee); + const isHookCallee = calleeKind === Kind.KnownHook || calleeKind === Kind.PotentialHook; + if (isHookCallee && !unconditionalBlocks.has(block.id)) { + recordConditionalHookError(instr.value.callee); + } + else if (calleeKind === Kind.PotentialHook) { + recordDynamicHookUsageError(instr.value.callee); + } + for (const operand of eachInstructionOperand(instr)) { + if (operand === instr.value.callee) { + continue; + } + visitPlace(operand); + } + break; + } + case 'MethodCall': { + const calleeKind = getKindForPlace(instr.value.property); + const isHookCallee = calleeKind === Kind.KnownHook || calleeKind === Kind.PotentialHook; + if (isHookCallee && !unconditionalBlocks.has(block.id)) { + recordConditionalHookError(instr.value.property); + } + else if (calleeKind === Kind.PotentialHook) { + recordDynamicHookUsageError(instr.value.property); + } + for (const operand of eachInstructionOperand(instr)) { + if (operand === instr.value.property) { + continue; + } + visitPlace(operand); + } + break; + } + case 'Destructure': { + visitPlace(instr.value.value); + const objectKind = getKindForPlace(instr.value.value); + for (const lvalue of eachInstructionLValue(instr)) { + const isHookProperty = lvalue.identifier.name !== null && + isHookName$2(lvalue.identifier.name.value); + let kind; + switch (objectKind) { + case Kind.Error: { + kind = Kind.Error; + break; + } + case Kind.KnownHook: { + kind = Kind.KnownHook; + break; + } + case Kind.PotentialHook: { + kind = Kind.PotentialHook; + break; + } + case Kind.Global: { + kind = isHookProperty ? Kind.KnownHook : Kind.Global; + break; + } + case Kind.Local: { + kind = isHookProperty ? Kind.PotentialHook : Kind.Local; + break; + } + default: { + assertExhaustive$1(objectKind, `Unexpected kind \`${objectKind}\``); + } + } + setKind(lvalue, kind); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + visitFunctionExpression(errors, instr.value.loweredFunc.func); + break; + } + default: { + for (const operand of eachInstructionOperand(instr)) { + visitPlace(operand); + } + for (const lvalue of eachInstructionLValue(instr)) { + const kind = getKindForPlace(lvalue); + setKind(lvalue, kind); + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + visitPlace(operand); + } + } + for (const [, error] of errorsByPlace) { + errors.push(error); + } + return errors.asResult(); +} +function visitFunctionExpression(errors, fn) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'ObjectMethod': + case 'FunctionExpression': { + visitFunctionExpression(errors, instr.value.loweredFunc.func); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'CallExpression' + ? instr.value.callee + : instr.value.property; + const hookKind = getHookKind(fn.env, callee.identifier); + if (hookKind != null) { + errors.pushErrorDetail(new CompilerErrorDetail({ + severity: ErrorSeverity.InvalidReact, + reason: 'Hooks must be called at the top level in the body of a function component or custom hook, and may not be called within function expressions. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)', + loc: callee.loc, + description: `Cannot call ${hookKind} within a function component`, + suggestions: null, + })); + } + break; + } + } + } + } +} + +function validateMemoizedEffectDependencies(fn) { + const errors = new CompilerError(); + visitReactiveFunction(fn, new Visitor$1(), errors); + return errors.asResult(); +} +let Visitor$1 = class Visitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopes = new Set(); + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + let areDependenciesMemoized = true; + for (const dep of scopeBlock.scope.dependencies) { + if (isUnmemoized$1(dep.identifier, this.scopes)) { + areDependenciesMemoized = false; + break; + } + } + if (areDependenciesMemoized) { + this.scopes.add(scopeBlock.scope.id); + for (const id of scopeBlock.scope.merged) { + this.scopes.add(id); + } + } + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + if (instruction.value.kind === 'CallExpression' && + isEffectHook(instruction.value.callee.identifier) && + instruction.value.args.length >= 2) { + const deps = instruction.value.args[1]; + if (deps.kind === 'Identifier' && + (isMutable(instruction, deps) || + isUnmemoized$1(deps.identifier, this.scopes))) { + state.push({ + reason: 'React Compiler has skipped optimizing this component because the effect dependencies could not be memoized. Unmemoized effect dependencies can trigger an infinite loop or other unexpected behavior', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc: typeof instruction.loc !== 'symbol' ? instruction.loc : null, + suggestions: null, + }); + } + } + } +}; +function isUnmemoized$1(operand, scopes) { + return operand.scope != null && !scopes.has(operand.scope.id); +} +function isEffectHook(identifier) { + return (isUseEffectHookType(identifier) || + isUseLayoutEffectHookType(identifier) || + isUseInsertionEffectHookType(identifier)); +} + +function validateNoCapitalizedCalls(fn) { + var _a; + const envConfig = fn.env.config; + const ALLOW_LIST = new Set([ + ...DEFAULT_GLOBALS.keys(), + ...((_a = envConfig.validateNoCapitalizedCalls) !== null && _a !== void 0 ? _a : []), + ]); + const hookPattern = envConfig.hookPattern != null ? new RegExp(envConfig.hookPattern) : null; + const isAllowed = (name) => { + return (ALLOW_LIST.has(name) || (hookPattern != null && hookPattern.test(name))); + }; + const errors = new CompilerError(); + const capitalLoadGlobals = new Map(); + const capitalizedProperties = new Map(); + const reason = 'Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config'; + for (const [, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + switch (value.kind) { + case 'LoadGlobal': { + if (value.binding.name != '' && + /^[A-Z]/.test(value.binding.name) && + !(value.binding.name.toUpperCase() === value.binding.name) && + !isAllowed(value.binding.name)) { + capitalLoadGlobals.set(lvalue.identifier.id, value.binding.name); + } + break; + } + case 'CallExpression': { + const calleeIdentifier = value.callee.identifier.id; + const calleeName = capitalLoadGlobals.get(calleeIdentifier); + if (calleeName != null) { + CompilerError.throwInvalidReact({ + reason, + description: `${calleeName} may be a component.`, + loc: value.loc, + suggestions: null, + }); + } + break; + } + case 'PropertyLoad': { + if (typeof value.property === 'string' && + /^[A-Z]/.test(value.property)) { + capitalizedProperties.set(lvalue.identifier.id, value.property); + } + break; + } + case 'MethodCall': { + const propertyIdentifier = value.property.identifier.id; + const propertyName = capitalizedProperties.get(propertyIdentifier); + if (propertyName != null) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason, + description: `${propertyName} may be a component.`, + loc: value.loc, + suggestions: null, + }); + } + break; + } + } + } + } + return errors.asResult(); +} + +var _Env_changed; +function makeRefId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected identifier id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +let _refId = 0; +function nextRefId() { + return makeRefId(_refId++); +} +class Env extends Map { + constructor() { + super(...arguments); + _Env_changed.set(this, false); + } + resetChanged() { + __classPrivateFieldSet(this, _Env_changed, false, "f"); + } + hasChanged() { + return __classPrivateFieldGet(this, _Env_changed, "f"); + } + set(key, value) { + const cur = this.get(key); + const widenedValue = joinRefAccessTypes(value, cur !== null && cur !== void 0 ? cur : { kind: 'None' }); + if (!(cur == null && widenedValue.kind === 'None') && + (cur == null || !tyEqual(cur, widenedValue))) { + __classPrivateFieldSet(this, _Env_changed, true, "f"); + } + return super.set(key, widenedValue); + } +} +_Env_changed = new WeakMap(); +function validateNoRefAccessInRender(fn) { + const env = new Env(); + return validateNoRefAccessInRenderImpl(fn, env).map(_ => undefined); +} +function refTypeOfType(place) { + if (isRefValueType(place.identifier)) { + return { kind: 'RefValue' }; + } + else if (isUseRefType(place.identifier)) { + return { kind: 'Ref', refId: nextRefId() }; + } + else { + return { kind: 'None' }; + } +} +function tyEqual(a, b) { + if (a.kind !== b.kind) { + return false; + } + switch (a.kind) { + case 'None': + return true; + case 'Ref': + return true; + case 'Nullable': + return true; + case 'Guard': + CompilerError.invariant(b.kind === 'Guard', { + reason: 'Expected ref value', + loc: null, + }); + return a.refId === b.refId; + case 'RefValue': + CompilerError.invariant(b.kind === 'RefValue', { + reason: 'Expected ref value', + loc: null, + }); + return a.loc == b.loc; + case 'Structure': { + CompilerError.invariant(b.kind === 'Structure', { + reason: 'Expected structure', + loc: null, + }); + const fnTypesEqual = (a.fn === null && b.fn === null) || + (a.fn !== null && + b.fn !== null && + a.fn.readRefEffect === b.fn.readRefEffect && + tyEqual(a.fn.returnType, b.fn.returnType)); + return (fnTypesEqual && + (a.value === b.value || + (a.value !== null && b.value !== null && tyEqual(a.value, b.value)))); + } + } +} +function joinRefAccessTypes(...types) { + function joinRefAccessRefTypes(a, b) { + if (a.kind === 'RefValue') { + if (b.kind === 'RefValue' && a.refId === b.refId) { + return a; + } + return { kind: 'RefValue' }; + } + else if (b.kind === 'RefValue') { + return b; + } + else if (a.kind === 'Ref' || b.kind === 'Ref') { + if (a.kind === 'Ref' && b.kind === 'Ref' && a.refId === b.refId) { + return a; + } + return { kind: 'Ref', refId: nextRefId() }; + } + else { + CompilerError.invariant(a.kind === 'Structure' && b.kind === 'Structure', { + reason: 'Expected structure', + loc: null, + }); + const fn = a.fn === null + ? b.fn + : b.fn === null + ? a.fn + : { + readRefEffect: a.fn.readRefEffect || b.fn.readRefEffect, + returnType: joinRefAccessTypes(a.fn.returnType, b.fn.returnType), + }; + const value = a.value === null + ? b.value + : b.value === null + ? a.value + : joinRefAccessRefTypes(a.value, b.value); + return { + kind: 'Structure', + fn, + value, + }; + } + } + return types.reduce((a, b) => { + if (a.kind === 'None') { + return b; + } + else if (b.kind === 'None') { + return a; + } + else if (a.kind === 'Guard') { + if (b.kind === 'Guard' && a.refId === b.refId) { + return a; + } + else if (b.kind === 'Nullable' || b.kind === 'Guard') { + return { kind: 'None' }; + } + else { + return b; + } + } + else if (b.kind === 'Guard') { + if (a.kind === 'Nullable') { + return { kind: 'None' }; + } + else { + return b; + } + } + else if (a.kind === 'Nullable') { + return b; + } + else if (b.kind === 'Nullable') { + return a; + } + else { + return joinRefAccessRefTypes(a, b); + } + }, { kind: 'None' }); +} +function validateNoRefAccessInRenderImpl(fn, env) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + let returnValues = []; + let place; + for (const param of fn.params) { + if (param.kind === 'Identifier') { + place = param; + } + else { + place = param.place; + } + const type = refTypeOfType(place); + env.set(place.identifier.id, type); + } + for (let i = 0; (i == 0 || env.hasChanged()) && i < 10; i++) { + env.resetChanged(); + returnValues = []; + const safeBlocks = new Map(); + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + env.set(phi.place.identifier.id, joinRefAccessTypes(...Array(...phi.operands.values()).map(operand => { var _a; return (_a = env.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : { kind: 'None' }; }))); + } + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoDirectRefValueAccess(errors, operand, env); + } + break; + } + case 'ComputedLoad': + case 'PropertyLoad': { + if (instr.value.kind === 'ComputedLoad') { + validateNoDirectRefValueAccess(errors, instr.value.property, env); + } + const objType = env.get(instr.value.object.identifier.id); + let lookupType = null; + if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Structure') { + lookupType = objType.value; + } + else if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Ref') { + lookupType = { + kind: 'RefValue', + loc: instr.loc, + refId: objType.refId, + }; + } + env.set(instr.lvalue.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(instr.lvalue)); + break; + } + case 'TypeCastExpression': { + env.set(instr.lvalue.identifier.id, (_a = env.get(instr.value.value.identifier.id)) !== null && _a !== void 0 ? _a : refTypeOfType(instr.lvalue)); + break; + } + case 'LoadContext': + case 'LoadLocal': { + env.set(instr.lvalue.identifier.id, (_b = env.get(instr.value.place.identifier.id)) !== null && _b !== void 0 ? _b : refTypeOfType(instr.lvalue)); + break; + } + case 'StoreContext': + case 'StoreLocal': { + env.set(instr.value.lvalue.place.identifier.id, (_c = env.get(instr.value.value.identifier.id)) !== null && _c !== void 0 ? _c : refTypeOfType(instr.value.lvalue.place)); + env.set(instr.lvalue.identifier.id, (_d = env.get(instr.value.value.identifier.id)) !== null && _d !== void 0 ? _d : refTypeOfType(instr.lvalue)); + break; + } + case 'Destructure': { + const objType = env.get(instr.value.value.identifier.id); + let lookupType = null; + if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Structure') { + lookupType = objType.value; + } + env.set(instr.lvalue.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(instr.lvalue)); + for (const lval of eachPatternOperand(instr.value.lvalue.pattern)) { + env.set(lval.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(lval)); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + let returnType = { kind: 'None' }; + let readRefEffect = false; + const result = validateNoRefAccessInRenderImpl(instr.value.loweredFunc.func, env); + if (result.isOk()) { + returnType = result.unwrap(); + } + else if (result.isErr()) { + readRefEffect = true; + } + env.set(instr.lvalue.identifier.id, { + kind: 'Structure', + fn: { + readRefEffect, + returnType, + }, + value: null, + }); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'CallExpression' + ? instr.value.callee + : instr.value.property; + const hookKind = getHookKindForType(fn.env, callee.identifier.type); + let returnType = { kind: 'None' }; + const fnType = env.get(callee.identifier.id); + if ((fnType === null || fnType === void 0 ? void 0 : fnType.kind) === 'Structure' && fnType.fn !== null) { + returnType = fnType.fn.returnType; + if (fnType.fn.readRefEffect) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: callee.loc, + description: callee.identifier.name !== null && + callee.identifier.name.kind === 'named' + ? `Function \`${callee.identifier.name.value}\` accesses a ref` + : null, + suggestions: null, + }); + } + } + for (const operand of eachInstructionValueOperand(instr.value)) { + if (hookKind != null) { + validateNoDirectRefValueAccess(errors, operand, env); + } + else { + validateNoRefAccess(errors, env, operand, operand.loc); + } + } + env.set(instr.lvalue.identifier.id, returnType); + break; + } + case 'ObjectExpression': + case 'ArrayExpression': { + const types = []; + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoDirectRefValueAccess(errors, operand, env); + types.push((_e = env.get(operand.identifier.id)) !== null && _e !== void 0 ? _e : { kind: 'None' }); + } + const value = joinRefAccessTypes(...types); + if (value.kind === 'None' || + value.kind === 'Guard' || + value.kind === 'Nullable') { + env.set(instr.lvalue.identifier.id, { kind: 'None' }); + } + else { + env.set(instr.lvalue.identifier.id, { + kind: 'Structure', + value, + fn: null, + }); + } + break; + } + case 'PropertyDelete': + case 'PropertyStore': + case 'ComputedDelete': + case 'ComputedStore': { + const safe = safeBlocks.get(block.id); + const target = env.get(instr.value.object.identifier.id); + if (instr.value.kind === 'PropertyStore' && + safe != null && + (target === null || target === void 0 ? void 0 : target.kind) === 'Ref' && + target.refId === safe) { + safeBlocks.delete(block.id); + } + else { + validateNoRefAccess(errors, env, instr.value.object, instr.loc); + } + for (const operand of eachInstructionValueOperand(instr.value)) { + if (operand === instr.value.object) { + continue; + } + validateNoRefValueAccess(errors, env, operand); + } + break; + } + case 'StartMemoize': + case 'FinishMemoize': + break; + case 'Primitive': { + if (instr.value.value == null) { + env.set(instr.lvalue.identifier.id, { kind: 'Nullable' }); + } + break; + } + case 'BinaryExpression': { + const left = env.get(instr.value.left.identifier.id); + const right = env.get(instr.value.right.identifier.id); + let nullish = false; + let refId = null; + if ((left === null || left === void 0 ? void 0 : left.kind) === 'RefValue' && left.refId != null) { + refId = left.refId; + } + else if ((right === null || right === void 0 ? void 0 : right.kind) === 'RefValue' && right.refId != null) { + refId = right.refId; + } + if ((left === null || left === void 0 ? void 0 : left.kind) === 'Nullable') { + nullish = true; + } + else if ((right === null || right === void 0 ? void 0 : right.kind) === 'Nullable') { + nullish = true; + } + if (refId !== null && nullish) { + env.set(instr.lvalue.identifier.id, { kind: 'Guard', refId }); + } + else { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoRefValueAccess(errors, env, operand); + } + } + break; + } + default: { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoRefValueAccess(errors, env, operand); + } + break; + } + } + for (const operand of eachInstructionOperand(instr)) { + guardCheck(errors, operand, env); + } + if (isUseRefType(instr.lvalue.identifier) && + ((_f = env.get(instr.lvalue.identifier.id)) === null || _f === void 0 ? void 0 : _f.kind) !== 'Ref') { + env.set(instr.lvalue.identifier.id, joinRefAccessTypes((_g = env.get(instr.lvalue.identifier.id)) !== null && _g !== void 0 ? _g : { kind: 'None' }, { kind: 'Ref', refId: nextRefId() })); + } + if (isRefValueType(instr.lvalue.identifier) && + ((_h = env.get(instr.lvalue.identifier.id)) === null || _h === void 0 ? void 0 : _h.kind) !== 'RefValue') { + env.set(instr.lvalue.identifier.id, joinRefAccessTypes((_j = env.get(instr.lvalue.identifier.id)) !== null && _j !== void 0 ? _j : { kind: 'None' }, { kind: 'RefValue', loc: instr.loc })); + } + } + if (block.terminal.kind === 'if') { + const test = env.get(block.terminal.test.identifier.id); + if ((test === null || test === void 0 ? void 0 : test.kind) === 'Guard') { + safeBlocks.set(block.terminal.consequent, test.refId); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + if (block.terminal.kind !== 'return') { + validateNoRefValueAccess(errors, env, operand); + if (block.terminal.kind !== 'if') { + guardCheck(errors, operand, env); + } + } + else { + validateNoDirectRefValueAccess(errors, operand, env); + guardCheck(errors, operand, env); + returnValues.push(env.get(operand.identifier.id)); + } + } + } + if (errors.hasErrors()) { + return Err(errors); + } + } + CompilerError.invariant(!env.hasChanged(), { + reason: 'Ref type environment did not converge', + loc: null, + }); + return Ok(joinRefAccessTypes(...returnValues.filter((env) => env !== undefined))); +} +function destructure(type) { + if ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && type.value !== null) { + return destructure(type.value); + } + return type; +} +function guardCheck(errors, operand, env) { + var _a; + if (((_a = env.get(operand.identifier.id)) === null || _a === void 0 ? void 0 : _a.kind) === 'Guard') { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoRefValueAccess(errors, env, operand) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'RefValue' || + ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && ((_a = type.fn) === null || _a === void 0 ? void 0 : _a.readRefEffect))) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (type.kind === 'RefValue' && type.loc) || operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoRefAccess(errors, env, operand, loc) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'Ref' || + (type === null || type === void 0 ? void 0 : type.kind) === 'RefValue' || + ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && ((_a = type.fn) === null || _a === void 0 ? void 0 : _a.readRefEffect))) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (type.kind === 'RefValue' && type.loc) || loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoDirectRefValueAccess(errors, operand, env) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'RefValue') { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (_a = type.loc) !== null && _a !== void 0 ? _a : operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} + +function validateNoSetStateInRender(fn) { + const unconditionalSetStateFunctions = new Set(); + return validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions); +} +function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) { + const unconditionalBlocks = computeUnconditionalBlocks(fn); + let activeManualMemoId = null; + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (unconditionalSetStateFunctions.has(instr.value.place.identifier.id)) { + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'StoreLocal': { + if (unconditionalSetStateFunctions.has(instr.value.value.identifier.id)) { + unconditionalSetStateFunctions.add(instr.value.lvalue.place.identifier.id); + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + if ([...eachInstructionValueOperand(instr.value)].some(operand => isSetStateType(operand.identifier) || + unconditionalSetStateFunctions.has(operand.identifier.id)) && + validateNoSetStateInRenderImpl(instr.value.loweredFunc.func, unconditionalSetStateFunctions).isErr()) { + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'StartMemoize': { + CompilerError.invariant(activeManualMemoId === null, { + reason: 'Unexpected nested StartMemoize instructions', + loc: instr.value.loc, + }); + activeManualMemoId = instr.value.manualMemoId; + break; + } + case 'FinishMemoize': { + CompilerError.invariant(activeManualMemoId === instr.value.manualMemoId, { + reason: 'Expected FinishMemoize to align with previous StartMemoize instruction', + loc: instr.value.loc, + }); + activeManualMemoId = null; + break; + } + case 'CallExpression': { + const callee = instr.value.callee; + if (isSetStateType(callee.identifier) || + unconditionalSetStateFunctions.has(callee.identifier.id)) { + if (activeManualMemoId !== null) { + errors.push({ + reason: 'Calling setState from useMemo may trigger an infinite loop. (https://react.dev/reference/react/useState)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + else if (unconditionalBlocks.has(block.id)) { + errors.push({ + reason: 'This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + } + break; + } + } + } + } + return errors.asResult(); +} + +function validatePreservedManualMemoization(fn) { + const state = { + errors: new CompilerError(), + manualMemoState: null, + }; + visitReactiveFunction(fn, new Visitor(), state); + return state.errors.asResult(); +} +var CompareDependencyResult; +(function (CompareDependencyResult) { + CompareDependencyResult[CompareDependencyResult["Ok"] = 0] = "Ok"; + CompareDependencyResult[CompareDependencyResult["RootDifference"] = 1] = "RootDifference"; + CompareDependencyResult[CompareDependencyResult["PathDifference"] = 2] = "PathDifference"; + CompareDependencyResult[CompareDependencyResult["Subpath"] = 3] = "Subpath"; + CompareDependencyResult[CompareDependencyResult["RefAccessDifference"] = 4] = "RefAccessDifference"; +})(CompareDependencyResult || (CompareDependencyResult = {})); +function compareDeps(inferred, source) { + const rootsEqual = (inferred.root.kind === 'Global' && + source.root.kind === 'Global' && + inferred.root.identifierName === source.root.identifierName) || + (inferred.root.kind === 'NamedLocal' && + source.root.kind === 'NamedLocal' && + inferred.root.value.identifier.id === source.root.value.identifier.id); + if (!rootsEqual) { + return CompareDependencyResult.RootDifference; + } + let isSubpath = true; + for (let i = 0; i < Math.min(inferred.path.length, source.path.length); i++) { + if (inferred.path[i].property !== source.path[i].property) { + isSubpath = false; + break; + } + else if (inferred.path[i].optional !== source.path[i].optional) { + return CompareDependencyResult.PathDifference; + } + } + if (isSubpath && + (source.path.length === inferred.path.length || + (inferred.path.length >= source.path.length && + !inferred.path.some(token => token.property === 'current')))) { + return CompareDependencyResult.Ok; + } + else { + if (isSubpath) { + if (source.path.some(token => token.property === 'current') || + inferred.path.some(token => token.property === 'current')) { + return CompareDependencyResult.RefAccessDifference; + } + else { + return CompareDependencyResult.Subpath; + } + } + else { + return CompareDependencyResult.PathDifference; + } + } +} +function validateInferredDep(dep, temporaries, declsWithinMemoBlock, validDepsInMemoBlock, errorState, memoLocation) { + var _a; + let normalizedDep; + const maybeNormalizedRoot = temporaries.get(dep.identifier.id); + if (maybeNormalizedRoot != null) { + normalizedDep = { + root: maybeNormalizedRoot.root, + path: [...maybeNormalizedRoot.path, ...dep.path], + }; + } + else { + CompilerError.invariant(((_a = dep.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named', { + reason: 'ValidatePreservedManualMemoization: expected scope dependency to be named', + loc: GeneratedSource, + suggestions: null, + }); + normalizedDep = { + root: { + kind: 'NamedLocal', + value: { + kind: 'Identifier', + identifier: dep.identifier, + loc: GeneratedSource, + effect: Effect.Read, + reactive: false, + }, + }, + path: [...dep.path], + }; + } + for (const decl of declsWithinMemoBlock) { + if (normalizedDep.root.kind === 'NamedLocal' && + decl === normalizedDep.root.value.identifier.declarationId) { + return; + } + } + for (const originalDep of validDepsInMemoBlock) { + const compareResult = compareDeps(normalizedDep, originalDep); + if (compareResult === CompareDependencyResult.Ok) { + return; + } + } + errorState.push({ + severity: ErrorSeverity.CannotPreserveMemoization, + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected', + description: null, + loc: memoLocation, + suggestions: null, + }); +} +class Visitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopes = new Set(); + this.prunedScopes = new Set(); + this.temporaries = new Map(); + } + recordDepsInValue(value, state) { + var _a, _b; + switch (value.kind) { + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + const result = this.recordDepsInValue(value.value, state); + return result; + } + case 'OptionalExpression': { + return this.recordDepsInValue(value.value, state); + } + case 'ConditionalExpression': { + this.recordDepsInValue(value.test, state); + this.recordDepsInValue(value.consequent, state); + this.recordDepsInValue(value.alternate, state); + return null; + } + case 'LogicalExpression': { + this.recordDepsInValue(value.left, state); + this.recordDepsInValue(value.right, state); + return null; + } + default: { + const dep = collectMaybeMemoDependencies(value, this.temporaries, false); + if (value.kind === 'StoreLocal' || value.kind === 'StoreContext') { + const storeTarget = value.lvalue.place; + (_a = state.manualMemoState) === null || _a === void 0 ? void 0 : _a.decls.add(storeTarget.identifier.declarationId); + if (((_b = storeTarget.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named' && dep == null) { + const dep = { + root: { + kind: 'NamedLocal', + value: storeTarget, + }, + path: [], + }; + this.temporaries.set(storeTarget.identifier.id, dep); + return dep; + } + } + return dep; + } + } + } + recordTemporaries(instr, state) { + var _a; + const temporaries = this.temporaries; + const { lvalue, value } = instr; + const lvalId = lvalue === null || lvalue === void 0 ? void 0 : lvalue.identifier.id; + if (lvalId != null && temporaries.has(lvalId)) { + return; + } + const isNamedLocal = ((_a = lvalue === null || lvalue === void 0 ? void 0 : lvalue.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named'; + if (lvalue !== null && isNamedLocal && state.manualMemoState != null) { + state.manualMemoState.decls.add(lvalue.identifier.declarationId); + } + const maybeDep = this.recordDepsInValue(value, state); + if (lvalId != null) { + if (maybeDep != null) { + temporaries.set(lvalId, maybeDep); + } + else if (isNamedLocal) { + temporaries.set(lvalId, { + root: { + kind: 'NamedLocal', + value: Object.assign({}, instr.lvalue), + }, + path: [], + }); + } + } + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + if (state.manualMemoState != null && + state.manualMemoState.depsFromSource != null) { + for (const dep of scopeBlock.scope.dependencies) { + validateInferredDep(dep, this.temporaries, state.manualMemoState.decls, state.manualMemoState.depsFromSource, state.errors, state.manualMemoState.loc); + } + } + this.scopes.add(scopeBlock.scope.id); + for (const id of scopeBlock.scope.merged) { + this.scopes.add(id); + } + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + this.prunedScopes.add(scopeBlock.scope.id); + } + visitInstruction(instruction, state) { + var _a, _b, _c; + this.recordTemporaries(instruction, state); + const value = instruction.value; + if (value.kind === 'StoreLocal' && + value.lvalue.kind === 'Reassign' && + state.manualMemoState != null) { + const ids = getOrInsertDefault(state.manualMemoState.reassignments, value.lvalue.place.identifier.declarationId, new Set()); + ids.add(value.value.identifier); + } + if (value.kind === 'StartMemoize') { + let depsFromSource = null; + if (value.deps != null) { + depsFromSource = value.deps; + } + CompilerError.invariant(state.manualMemoState == null, { + reason: 'Unexpected nested StartMemoize instructions', + description: `Bad manual memoization ids: ${(_a = state.manualMemoState) === null || _a === void 0 ? void 0 : _a.manualMemoId}, ${value.manualMemoId}`, + loc: value.loc, + suggestions: null, + }); + state.manualMemoState = { + loc: instruction.loc, + decls: new Set(), + depsFromSource, + manualMemoId: value.manualMemoId, + reassignments: new Map(), + }; + for (const { identifier, loc } of eachInstructionValueOperand(value)) { + if (identifier.scope != null && + !this.scopes.has(identifier.scope.id) && + !this.prunedScopes.has(identifier.scope.id)) { + state.errors.push({ + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc, + suggestions: null, + }); + } + } + } + if (value.kind === 'FinishMemoize') { + CompilerError.invariant(state.manualMemoState != null && + state.manualMemoState.manualMemoId === value.manualMemoId, { + reason: 'Unexpected mismatch between StartMemoize and FinishMemoize', + description: `Encountered StartMemoize id=${(_b = state.manualMemoState) === null || _b === void 0 ? void 0 : _b.manualMemoId} followed by FinishMemoize id=${value.manualMemoId}`, + loc: value.loc, + suggestions: null, + }); + const reassignments = state.manualMemoState.reassignments; + state.manualMemoState = null; + if (!value.pruned) { + for (const { identifier, loc } of eachInstructionValueOperand(value)) { + let decls; + if (identifier.scope == null) { + decls = (_c = reassignments.get(identifier.declarationId)) !== null && _c !== void 0 ? _c : [identifier]; + } + else { + decls = [identifier]; + } + for (const identifier of decls) { + if (isUnmemoized(identifier, this.scopes)) { + state.errors.push({ + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc, + suggestions: null, + }); + } + } + } + } + } + } +} +function isUnmemoized(operand, scopes) { + return operand.scope != null && !scopes.has(operand.scope.id); +} + +function validateUseMemo(fn) { + const errors = new CompilerError(); + const useMemos = new Set(); + const react = new Set(); + const functions = new Map(); + for (const [, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + switch (value.kind) { + case 'LoadGlobal': { + if (value.binding.name === 'useMemo') { + useMemos.add(lvalue.identifier.id); + } + else if (value.binding.name === 'React') { + react.add(lvalue.identifier.id); + } + break; + } + case 'PropertyLoad': { + if (react.has(value.object.identifier.id)) { + if (value.property === 'useMemo') { + useMemos.add(lvalue.identifier.id); + } + } + break; + } + case 'FunctionExpression': { + functions.set(lvalue.identifier.id, value); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = value.kind === 'CallExpression' + ? value.callee.identifier.id + : value.property.identifier.id; + const isUseMemo = useMemos.has(callee); + if (!isUseMemo || value.args.length === 0) { + continue; + } + const [arg] = value.args; + if (arg.kind !== 'Identifier') { + continue; + } + const body = functions.get(arg.identifier.id); + if (body === undefined) { + continue; + } + if (body.loweredFunc.func.params.length > 0) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'useMemo callbacks may not accept any arguments', + description: null, + loc: body.loc, + suggestions: null, + }); + } + if (body.loweredFunc.func.async || body.loweredFunc.func.generator) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'useMemo callbacks may not be async or generator functions', + description: null, + loc: body.loc, + suggestions: null, + }); + } + break; + } + } + } + } + return errors.asResult(); +} + +function validateLocalsNotReassignedAfterRender(fn) { + const contextVariables = new Set(); + const reassignment = getContextReassignment(fn, contextVariables, false, false); + if (reassignment !== null) { + CompilerError.throwInvalidReact({ + reason: 'Reassigning a variable after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead', + description: reassignment.identifier.name !== null && + reassignment.identifier.name.kind === 'named' + ? `Variable \`${reassignment.identifier.name.value}\` cannot be reassigned after render` + : '', + loc: reassignment.loc, + }); + } +} +function getContextReassignment(fn, contextVariables, isFunctionExpression, isAsync) { + const reassigningFunctions = new Map(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { lvalue, value } = instr; + switch (value.kind) { + case 'FunctionExpression': + case 'ObjectMethod': { + let reassignment = getContextReassignment(value.loweredFunc.func, contextVariables, true, isAsync || value.loweredFunc.func.async); + if (reassignment === null) { + for (const operand of eachInstructionValueOperand(value)) { + const reassignmentFromOperand = reassigningFunctions.get(operand.identifier.id); + if (reassignmentFromOperand !== undefined) { + reassignment = reassignmentFromOperand; + break; + } + } + } + if (reassignment !== null) { + if (isAsync || value.loweredFunc.func.async) { + CompilerError.throwInvalidReact({ + reason: 'Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead', + description: reassignment.identifier.name !== null && + reassignment.identifier.name.kind === 'named' + ? `Variable \`${reassignment.identifier.name.value}\` cannot be reassigned after render` + : '', + loc: reassignment.loc, + }); + } + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'StoreLocal': { + const reassignment = reassigningFunctions.get(value.value.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(value.lvalue.place.identifier.id, reassignment); + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'LoadLocal': { + const reassignment = reassigningFunctions.get(value.place.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'DeclareContext': { + if (!isFunctionExpression) { + contextVariables.add(value.lvalue.place.identifier.id); + } + break; + } + case 'StoreContext': { + if (isFunctionExpression) { + if (contextVariables.has(value.lvalue.place.identifier.id)) { + return value.lvalue.place; + } + } + else { + contextVariables.add(value.lvalue.place.identifier.id); + } + const reassignment = reassigningFunctions.get(value.value.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(value.lvalue.place.identifier.id, reassignment); + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + default: { + let operands = eachInstructionValueOperand(value); + if (value.kind === 'CallExpression') { + const signature = getFunctionCallSignature(fn.env, value.callee.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.callee]; + } + } + else if (value.kind === 'MethodCall') { + const signature = getFunctionCallSignature(fn.env, value.property.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.receiver, value.property]; + } + } + else if (value.kind === 'TaggedTemplateExpression') { + const signature = getFunctionCallSignature(fn.env, value.tag.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.tag]; + } + } + for (const operand of operands) { + CompilerError.invariant(operand.effect !== Effect.Unknown, { + reason: `Expected effects to be inferred prior to ValidateLocalsNotReassignedAfterRender`, + loc: operand.loc, + }); + const reassignment = reassigningFunctions.get(operand.identifier.id); + if (reassignment !== undefined) { + if (operand.effect === Effect.Freeze) { + return reassignment; + } + else { + for (const lval of eachInstructionLValue(instr)) { + reassigningFunctions.set(lval.identifier.id, reassignment); + } + } + } + } + break; + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + const reassignment = reassigningFunctions.get(operand.identifier.id); + if (reassignment !== undefined) { + return reassignment; + } + } + } + return null; +} + +function outlineFunctions(fn, fbtOperands) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + outlineFunctions(value.loweredFunc.func, fbtOperands); + } + if (value.kind === 'FunctionExpression' && + value.loweredFunc.func.context.length === 0 && + value.loweredFunc.func.id === null && + !fbtOperands.has(lvalue.identifier.id)) { + const loweredFunc = value.loweredFunc.func; + const id = fn.env.generateGloballyUniqueIdentifierName(loweredFunc.id); + loweredFunc.id = id.value; + fn.env.outlineFunction(loweredFunc, null); + instr.value = { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: id.value, + }, + loc: value.loc, + }; + } + } + } +} + +function propagatePhiTypes(fn) { + const propagated = new Set(); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (phi.place.identifier.type.kind !== 'Type' || + phi.place.identifier.name !== null) { + continue; + } + let type = null; + for (const [, operand] of phi.operands) { + if (type === null) { + type = operand.identifier.type; + } + else if (!typeEquals(type, operand.identifier.type)) { + type = null; + break; + } + } + if (type !== null) { + phi.place.identifier.type = type; + propagated.add(phi.place.identifier.id); + } + } + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'StoreLocal': { + const lvalue = value.lvalue.place; + if (propagated.has(value.value.identifier.id) && + lvalue.identifier.type.kind === 'Type' && + lvalue.identifier.name === null) { + lvalue.identifier.type = value.value.identifier.type; + propagated.add(lvalue.identifier.id); + } + } + } + } + } +} + +function lowerContextAccess(fn, loweredContextCalleeConfig) { + const contextAccess = new Map(); + const contextKeys = new Map(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'CallExpression' && + isUseContextHookType(value.callee.identifier)) { + contextAccess.set(lvalue.identifier.id, value); + continue; + } + if (value.kind !== 'Destructure') { + continue; + } + const destructureId = value.value.identifier.id; + if (!contextAccess.has(destructureId)) { + continue; + } + const keys = getContextKeys(value); + if (keys === null) { + return; + } + if (contextKeys.has(destructureId)) { + return; + } + else { + contextKeys.set(destructureId, keys); + } + } + } + let importLoweredContextCallee = null; + if (contextAccess.size > 0 && contextKeys.size > 0) { + for (const [, block] of fn.body.blocks) { + let nextInstructions = null; + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + const { lvalue, value } = instr; + if (value.kind === 'CallExpression' && + isUseContextHookType(value.callee.identifier) && + contextKeys.has(lvalue.identifier.id)) { + importLoweredContextCallee !== null && importLoweredContextCallee !== void 0 ? importLoweredContextCallee : (importLoweredContextCallee = fn.env.programContext.addImportSpecifier(loweredContextCalleeConfig)); + const loweredContextCalleeInstr = emitLoadLoweredContextCallee(fn.env, importLoweredContextCallee); + if (nextInstructions === null) { + nextInstructions = block.instructions.slice(0, i); + } + nextInstructions.push(loweredContextCalleeInstr); + const keys = contextKeys.get(lvalue.identifier.id); + const selectorFnInstr = emitSelectorFn(fn.env, keys); + nextInstructions.push(selectorFnInstr); + const lowerContextCallId = loweredContextCalleeInstr.lvalue; + value.callee = lowerContextCallId; + const selectorFn = selectorFnInstr.lvalue; + value.args.push(selectorFn); + } + if (nextInstructions) { + nextInstructions.push(instr); + } + } + if (nextInstructions) { + block.instructions = nextInstructions; + } + } + markInstructionIds(fn.body); + inferTypes(fn); + } +} +function emitLoadLoweredContextCallee(env, importedLowerContextCallee) { + const loadGlobal = { + kind: 'LoadGlobal', + binding: Object.assign({}, importedLowerContextCallee), + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, GeneratedSource), + value: loadGlobal, + }; +} +function getContextKeys(value) { + const keys = []; + const pattern = value.lvalue.pattern; + switch (pattern.kind) { + case 'ArrayPattern': { + return null; + } + case 'ObjectPattern': { + for (const place of pattern.properties) { + if (place.kind !== 'ObjectProperty' || + place.type !== 'property' || + place.key.kind !== 'identifier' || + place.place.identifier.name === null || + place.place.identifier.name.kind !== 'named') { + return null; + } + keys.push(place.key.name); + } + return keys; + } + } +} +function emitPropertyLoad(env, obj, property) { + const loadObj = { + kind: 'LoadLocal', + place: obj, + loc: GeneratedSource, + }; + const object = createTemporaryPlace(env, GeneratedSource); + const loadLocalInstr = { + lvalue: object, + value: loadObj, + id: makeInstructionId(0), + loc: GeneratedSource, + }; + const loadProp = { + kind: 'PropertyLoad', + object, + property: makePropertyLiteral(property), + loc: GeneratedSource, + }; + const element = createTemporaryPlace(env, GeneratedSource); + const loadPropInstr = { + lvalue: element, + value: loadProp, + id: makeInstructionId(0), + loc: GeneratedSource, + }; + return { + instructions: [loadLocalInstr, loadPropInstr], + element: element, + }; +} +function emitSelectorFn(env, keys) { + const obj = createTemporaryPlace(env, GeneratedSource); + promoteTemporary(obj.identifier); + const instr = []; + const elements = []; + for (const key of keys) { + const { instructions, element: prop } = emitPropertyLoad(env, obj, key); + instr.push(...instructions); + elements.push(prop); + } + const arrayInstr = emitArrayInstr(elements, env); + instr.push(arrayInstr); + const block = { + kind: 'block', + id: makeBlockId(0), + instructions: instr, + terminal: { + id: makeInstructionId(0), + kind: 'return', + loc: GeneratedSource, + value: arrayInstr.lvalue, + }, + preds: new Set(), + phis: new Set(), + }; + const fn = { + loc: GeneratedSource, + id: null, + fnType: 'Other', + env, + params: [obj], + returnTypeAnnotation: null, + returnType: makeType(), + context: [], + effects: null, + body: { + entry: block.id, + blocks: new Map([[block.id, block]]), + }, + generator: false, + async: false, + directives: [], + }; + reversePostorderBlocks(fn.body); + markInstructionIds(fn.body); + enterSSA(fn); + inferTypes(fn); + const fnInstr = { + id: makeInstructionId(0), + value: { + kind: 'FunctionExpression', + name: null, + loweredFunc: { + func: fn, + }, + type: 'ArrowFunctionExpression', + loc: GeneratedSource, + }, + lvalue: createTemporaryPlace(env, GeneratedSource), + loc: GeneratedSource, + }; + return fnInstr; +} +function emitArrayInstr(elements, env) { + const array = { + kind: 'ArrayExpression', + elements, + loc: GeneratedSource, + }; + const arrayLvalue = createTemporaryPlace(env, GeneratedSource); + const arrayInstr = { + id: makeInstructionId(0), + value: array, + lvalue: arrayLvalue, + loc: GeneratedSource, + }; + return arrayInstr; +} + +function validateNoSetStateInPassiveEffects(fn) { + const setStateFunctions = new Map(); + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (setStateFunctions.has(instr.value.place.identifier.id)) { + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.place); + } + break; + } + case 'StoreLocal': { + if (setStateFunctions.has(instr.value.value.identifier.id)) { + setStateFunctions.set(instr.value.lvalue.place.identifier.id, instr.value.value); + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.value); + } + break; + } + case 'FunctionExpression': { + if ([...eachInstructionValueOperand(instr.value)].some(operand => isSetStateType(operand.identifier) || + setStateFunctions.has(operand.identifier.id))) { + const callee = getSetStateCall(instr.value.loweredFunc.func, setStateFunctions); + if (callee !== null) { + setStateFunctions.set(instr.lvalue.identifier.id, callee); + } + } + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'MethodCall' + ? instr.value.receiver + : instr.value.callee; + if (isUseEffectHookType(callee.identifier)) { + const arg = instr.value.args[0]; + if (arg !== undefined && arg.kind === 'Identifier') { + const setState = setStateFunctions.get(arg.identifier.id); + if (setState !== undefined) { + errors.push({ + reason: 'Calling setState directly within a useEffect causes cascading renders and is not recommended. Consider alternatives to useEffect. (https://react.dev/learn/you-might-not-need-an-effect)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: setState.loc, + suggestions: null, + }); + } + } + } + break; + } + } + } + } + return errors.asResult(); +} +function getSetStateCall(fn, setStateFunctions) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (setStateFunctions.has(instr.value.place.identifier.id)) { + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.place); + } + break; + } + case 'StoreLocal': { + if (setStateFunctions.has(instr.value.value.identifier.id)) { + setStateFunctions.set(instr.value.lvalue.place.identifier.id, instr.value.value); + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.value); + } + break; + } + case 'CallExpression': { + const callee = instr.value.callee; + if (isSetStateType(callee.identifier) || + setStateFunctions.has(callee.identifier.id)) { + return callee; + } + } + } + } + } + return null; +} + +function validateNoJSXInTryStatement(fn) { + const activeTryBlocks = []; + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + retainWhere(activeTryBlocks, id => id !== block.id); + if (activeTryBlocks.length !== 0) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: `Unexpected JSX element within a try statement. To catch errors in rendering a given component, wrap that component in an error boundary. (https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)`, + loc: value.loc, + }); + break; + } + } + } + } + if (block.terminal.kind === 'try') { + activeTryBlocks.push(block.terminal.handler); + } + } + return errors.asResult(); +} + +function outlineJSX(fn) { + const outlinedFns = []; + outlineJsxImpl(fn, outlinedFns); + for (const outlinedFn of outlinedFns) { + fn.env.outlineFunction(outlinedFn, 'Component'); + } +} +function outlineJsxImpl(fn, outlinedFns) { + const globals = new Map(); + function processAndOutlineJSX(state, rewriteInstr) { + if (state.jsx.length <= 1) { + return; + } + const result = process$1(fn, [...state.jsx].sort((a, b) => a.id - b.id), globals); + if (result) { + outlinedFns.push(result.fn); + rewriteInstr.set(state.jsx.at(0).id, result.instrs); + } + } + for (const [, block] of fn.body.blocks) { + const rewriteInstr = new Map(); + let state = { + jsx: [], + children: new Set(), + }; + for (let i = block.instructions.length - 1; i >= 0; i--) { + const instr = block.instructions[i]; + const { value, lvalue } = instr; + switch (value.kind) { + case 'LoadGlobal': { + globals.set(lvalue.identifier.id, instr); + break; + } + case 'FunctionExpression': { + outlineJsxImpl(value.loweredFunc.func, outlinedFns); + break; + } + case 'JsxExpression': { + if (!state.children.has(lvalue.identifier.id)) { + processAndOutlineJSX(state, rewriteInstr); + state = { + jsx: [], + children: new Set(), + }; + } + state.jsx.push(instr); + if (value.children) { + for (const child of value.children) { + state.children.add(child.identifier.id); + } + } + break; + } + case 'ArrayExpression': + case 'Await': + case 'BinaryExpression': + case 'CallExpression': + case 'ComputedDelete': + case 'ComputedLoad': + case 'ComputedStore': + case 'Debugger': + case 'DeclareContext': + case 'DeclareLocal': + case 'Destructure': + case 'FinishMemoize': + case 'GetIterator': + case 'IteratorNext': + case 'JSXText': + case 'JsxFragment': + case 'LoadContext': + case 'LoadLocal': + case 'MetaProperty': + case 'MethodCall': + case 'NewExpression': + case 'NextPropertyOf': + case 'ObjectExpression': + case 'ObjectMethod': + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'Primitive': + case 'PropertyDelete': + case 'PropertyLoad': + case 'PropertyStore': + case 'RegExpLiteral': + case 'StartMemoize': + case 'StoreContext': + case 'StoreGlobal': + case 'StoreLocal': + case 'TaggedTemplateExpression': + case 'TemplateLiteral': + case 'TypeCastExpression': + case 'UnsupportedNode': + case 'UnaryExpression': { + break; + } + default: { + assertExhaustive$1(value, `Unexpected instruction: ${value}`); + } + } + } + processAndOutlineJSX(state, rewriteInstr); + if (rewriteInstr.size > 0) { + const newInstrs = []; + for (let i = 0; i < block.instructions.length; i++) { + const id = i + 1; + if (rewriteInstr.has(id)) { + const instrs = rewriteInstr.get(id); + newInstrs.push(...instrs); + } + else { + newInstrs.push(block.instructions[i]); + } + } + block.instructions = newInstrs; + } + deadCodeElimination(fn); + } +} +function process$1(fn, jsx, globals) { + if (fn.fnType === 'Component') { + return null; + } + const props = collectProps(fn.env, jsx); + if (!props) + return null; + const outlinedTag = fn.env.generateGloballyUniqueIdentifierName(null).value; + const newInstrs = emitOutlinedJsx(fn.env, jsx, props, outlinedTag); + if (!newInstrs) + return null; + const outlinedFn = emitOutlinedFn(fn.env, jsx, props, globals); + if (!outlinedFn) + return null; + outlinedFn.id = outlinedTag; + return { instrs: newInstrs, fn: outlinedFn }; +} +function collectProps(env, instructions) { + let id = 1; + function generateName(oldName) { + let newName = oldName; + while (seen.has(newName)) { + newName = `${oldName}${id++}`; + } + seen.add(newName); + env.programContext.addNewReference(newName); + return newName; + } + const attributes = []; + const jsxIds = new Set(instructions.map(i => i.lvalue.identifier.id)); + const seen = new Set(); + for (const instr of instructions) { + const { value } = instr; + for (const at of value.props) { + if (at.kind === 'JsxSpreadAttribute') { + return null; + } + if (at.kind === 'JsxAttribute') { + const newName = generateName(at.name); + attributes.push({ + originalName: at.name, + newName, + place: at.place, + }); + } + } + if (value.children) { + for (const child of value.children) { + if (jsxIds.has(child.identifier.id)) { + continue; + } + promoteTemporary(child.identifier); + const newName = generateName('t'); + attributes.push({ + originalName: child.identifier.name.value, + newName: newName, + place: child, + }); + } + } + } + return attributes; +} +function emitOutlinedJsx(env, instructions, outlinedProps, outlinedTag) { + const props = outlinedProps.map(p => ({ + kind: 'JsxAttribute', + name: p.newName, + place: p.place, + })); + const loadJsx = { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, GeneratedSource), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'ModuleLocal', + name: outlinedTag, + }, + loc: GeneratedSource, + }, + }; + promoteTemporaryJsxTag(loadJsx.lvalue.identifier); + const jsxExpr = { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: instructions.at(-1).lvalue, + value: { + kind: 'JsxExpression', + tag: Object.assign({}, loadJsx.lvalue), + props, + children: null, + loc: GeneratedSource, + openingLoc: GeneratedSource, + closingLoc: GeneratedSource, + }, + }; + return [loadJsx, jsxExpr]; +} +function emitOutlinedFn(env, jsx, oldProps, globals) { + const instructions = []; + const oldToNewProps = createOldToNewPropsMapping(env, oldProps); + const propsObj = createTemporaryPlace(env, GeneratedSource); + promoteTemporary(propsObj.identifier); + const destructurePropsInstr = emitDestructureProps(env, propsObj, oldToNewProps); + instructions.push(destructurePropsInstr); + const updatedJsxInstructions = emitUpdatedJsx(jsx, oldToNewProps); + const loadGlobalInstrs = emitLoadGlobals(jsx, globals); + if (!loadGlobalInstrs) { + return null; + } + instructions.push(...loadGlobalInstrs); + instructions.push(...updatedJsxInstructions); + const block = { + kind: 'block', + id: makeBlockId(0), + instructions, + terminal: { + id: makeInstructionId(0), + kind: 'return', + loc: GeneratedSource, + value: instructions.at(-1).lvalue, + }, + preds: new Set(), + phis: new Set(), + }; + const fn = { + loc: GeneratedSource, + id: null, + fnType: 'Other', + env, + params: [propsObj], + returnTypeAnnotation: null, + returnType: makeType(), + context: [], + effects: null, + body: { + entry: block.id, + blocks: new Map([[block.id, block]]), + }, + generator: false, + async: false, + directives: [], + }; + return fn; +} +function emitLoadGlobals(jsx, globals) { + const instructions = []; + for (const { value } of jsx) { + if (value.tag.kind === 'Identifier') { + const loadGlobalInstr = globals.get(value.tag.identifier.id); + if (!loadGlobalInstr) { + return null; + } + instructions.push(loadGlobalInstr); + } + } + return instructions; +} +function emitUpdatedJsx(jsx, oldToNewProps) { + const newInstrs = []; + const jsxIds = new Set(jsx.map(i => i.lvalue.identifier.id)); + for (const instr of jsx) { + const { value } = instr; + const newProps = []; + for (const prop of value.props) { + invariant(prop.kind === 'JsxAttribute', `Expected only attributes but found ${prop.kind}`); + if (prop.name === 'key') { + continue; + } + const newProp = oldToNewProps.get(prop.place.identifier.id); + invariant(newProp !== undefined, `Expected a new property for ${printIdentifier(prop.place.identifier)}`); + newProps.push({ + kind: 'JsxAttribute', + name: newProp.originalName, + place: newProp.place, + }); + } + let newChildren = null; + if (value.children) { + newChildren = []; + for (const child of value.children) { + if (jsxIds.has(child.identifier.id)) { + newChildren.push(Object.assign({}, child)); + continue; + } + const newChild = oldToNewProps.get(child.identifier.id); + invariant(newChild !== undefined, `Expected a new prop for ${printIdentifier(child.identifier)}`); + newChildren.push(Object.assign({}, newChild.place)); + } + } + newInstrs.push(Object.assign(Object.assign({}, instr), { value: Object.assign(Object.assign({}, value), { props: newProps, children: newChildren }) })); + } + return newInstrs; +} +function createOldToNewPropsMapping(env, oldProps) { + const oldToNewProps = new Map(); + for (const oldProp of oldProps) { + if (oldProp.originalName === 'key') { + continue; + } + const newProp = Object.assign(Object.assign({}, oldProp), { place: createTemporaryPlace(env, GeneratedSource) }); + newProp.place.identifier.name = makeIdentifierName(oldProp.newName); + oldToNewProps.set(oldProp.place.identifier.id, newProp); + } + return oldToNewProps; +} +function emitDestructureProps(env, propsObj, oldToNewProps) { + const properties = []; + for (const [_, prop] of oldToNewProps) { + properties.push({ + kind: 'ObjectProperty', + key: { + kind: 'string', + name: prop.newName, + }, + type: 'property', + place: prop.place, + }); + } + const destructurePropsInstr = { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, GeneratedSource), + loc: GeneratedSource, + value: { + kind: 'Destructure', + lvalue: { + pattern: { + kind: 'ObjectPattern', + properties, + }, + kind: InstructionKind.Let, + }, + loc: GeneratedSource, + value: propsObj, + }, + }; + return destructurePropsInstr; +} + +function optimizePropsMethodCalls(fn) { + for (const [, block] of fn.body.blocks) { + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + if (instr.value.kind === 'MethodCall' && + isPropsType(instr.value.receiver.identifier)) { + instr.value = { + kind: 'CallExpression', + callee: instr.value.property, + args: instr.value.args, + loc: instr.value.loc, + }; + } + } + } +} + +var _Context_env, _Context_errors, _Context_callExpressions, _Context_functionExpressions, _Context_loadLocals, _Context_fireCalleesToFireFunctions, _Context_calleesWithInsertedFire, _Context_capturedCalleeIdentifierIds, _Context_inUseEffectLambda, _Context_loadGlobalInstructionIds, _Context_arrayExpressions; +const CANNOT_COMPILE_FIRE = 'Cannot compile `fire`'; +function transformFire(fn) { + const context = new Context(fn.env); + replaceFireFunctions(fn, context); + if (!context.hasErrors()) { + ensureNoMoreFireUses(fn, context); + } + context.throwIfErrorsFound(); +} +function replaceFireFunctions(fn, context) { + let importedUseFire = null; + let hasRewrite = false; + for (const [, block] of fn.body.blocks) { + const rewriteInstrs = new Map(); + const deleteInstrs = new Set(); + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'CallExpression' && + isUseEffectHookType(value.callee.identifier) && + value.args.length > 0 && + value.args[0].kind === 'Identifier') { + const lambda = context.getFunctionExpression(value.args[0].identifier.id); + if (lambda != null) { + const capturedCallees = visitFunctionExpressionAndPropagateFireDependencies(lambda, context, true); + const newInstrs = []; + for (const [fireCalleePlace, fireCalleeInfo,] of capturedCallees.entries()) { + if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) { + context.addCalleeWithInsertedFire(fireCalleePlace); + importedUseFire !== null && importedUseFire !== void 0 ? importedUseFire : (importedUseFire = fn.env.programContext.addImportSpecifier({ + source: fn.env.programContext.reactRuntimeModule, + importSpecifierName: USE_FIRE_FUNCTION_NAME, + })); + const loadUseFireInstr = makeLoadUseFireInstruction(fn.env, importedUseFire); + const loadFireCalleeInstr = makeLoadFireCalleeInstruction(fn.env, fireCalleeInfo.capturedCalleeIdentifier); + const callUseFireInstr = makeCallUseFireInstruction(fn.env, loadUseFireInstr.lvalue, loadFireCalleeInstr.lvalue); + const storeUseFireInstr = makeStoreUseFireInstruction(fn.env, callUseFireInstr.lvalue, fireCalleeInfo.fireFunctionBinding); + newInstrs.push(loadUseFireInstr, loadFireCalleeInstr, callUseFireInstr, storeUseFireInstr); + const loadUseEffectInstrId = context.getLoadGlobalInstrId(value.callee.identifier.id); + if (loadUseEffectInstrId == null) { + context.pushError({ + loc: value.loc, + description: null, + severity: ErrorSeverity.Invariant, + reason: '[InsertFire] No LoadGlobal found for useEffect call', + suggestions: null, + }); + continue; + } + rewriteInstrs.set(loadUseEffectInstrId, newInstrs); + } + } + ensureNoRemainingCalleeCaptures(lambda.loweredFunc.func, context, capturedCallees); + if (value.args.length > 1 && + value.args[1] != null && + value.args[1].kind === 'Identifier') { + const depArray = value.args[1]; + const depArrayExpression = context.getArrayExpression(depArray.identifier.id); + if (depArrayExpression != null) { + for (const dependency of depArrayExpression.elements) { + if (dependency.kind === 'Identifier') { + const loadOfDependency = context.getLoadLocalInstr(dependency.identifier.id); + if (loadOfDependency != null) { + const replacedDepArrayItem = capturedCallees.get(loadOfDependency.place.identifier.id); + if (replacedDepArrayItem != null) { + loadOfDependency.place = + replacedDepArrayItem.fireFunctionBinding; + } + } + } + } + } + else { + context.pushError({ + loc: value.args[1].loc, + description: 'You must use an array literal for an effect dependency array when that effect uses `fire()`', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else if (value.args.length > 1 && value.args[1].kind === 'Spread') { + context.pushError({ + loc: value.args[1].place.loc, + description: 'You must use an array literal for an effect dependency array when that effect uses `fire()`', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + } + else if (value.kind === 'CallExpression' && + value.callee.identifier.type.kind === 'Function' && + value.callee.identifier.type.shapeId === BuiltInFireId && + context.inUseEffectLambda()) { + if (value.args.length === 1 && value.args[0].kind === 'Identifier') { + const callExpr = context.getCallExpression(value.args[0].identifier.id); + if (callExpr != null) { + const calleeId = callExpr.callee.identifier.id; + const loadLocal = context.getLoadLocalInstr(calleeId); + if (loadLocal == null) { + context.pushError({ + loc: value.loc, + description: null, + severity: ErrorSeverity.Invariant, + reason: '[InsertFire] No loadLocal found for fire call argument', + suggestions: null, + }); + continue; + } + const fireFunctionBinding = context.getOrGenerateFireFunctionBinding(loadLocal.place, value.loc); + loadLocal.place = Object.assign({}, fireFunctionBinding); + deleteInstrs.add(instr.id); + } + else { + context.pushError({ + loc: value.loc, + description: '`fire()` can only receive a function call such as `fire(fn(a,b)). Method calls and other expressions are not allowed', + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else { + let description = 'fire() can only take in a single call expression as an argument'; + if (value.args.length === 0) { + description += ' but received none'; + } + else if (value.args.length > 1) { + description += ' but received multiple arguments'; + } + else if (value.args[0].kind === 'Spread') { + description += ' but received a spread argument'; + } + context.pushError({ + loc: value.loc, + description, + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else if (value.kind === 'CallExpression') { + context.addCallExpression(lvalue.identifier.id, value); + } + else if (value.kind === 'FunctionExpression' && + context.inUseEffectLambda()) { + visitFunctionExpressionAndPropagateFireDependencies(value, context, false); + } + else if (value.kind === 'FunctionExpression') { + context.addFunctionExpression(lvalue.identifier.id, value); + } + else if (value.kind === 'LoadLocal') { + context.addLoadLocalInstr(lvalue.identifier.id, value); + } + else if (value.kind === 'LoadGlobal' && + value.binding.kind === 'ImportSpecifier' && + value.binding.module === 'react' && + value.binding.imported === 'fire' && + context.inUseEffectLambda()) { + deleteInstrs.add(instr.id); + } + else if (value.kind === 'LoadGlobal') { + context.addLoadGlobalInstrId(lvalue.identifier.id, instr.id); + } + else if (value.kind === 'ArrayExpression') { + context.addArrayExpression(lvalue.identifier.id, value); + } + } + block.instructions = rewriteInstructions(rewriteInstrs, block.instructions); + block.instructions = deleteInstructions(deleteInstrs, block.instructions); + if (rewriteInstrs.size > 0 || deleteInstrs.size > 0) { + hasRewrite = true; + fn.env.hasFireRewrite = true; + } + } + if (hasRewrite) { + markInstructionIds(fn.body); + } +} +function visitFunctionExpressionAndPropagateFireDependencies(fnExpr, context, enteringUseEffect) { + let withScope = enteringUseEffect + ? context.withUseEffectLambdaScope.bind(context) + : context.withFunctionScope.bind(context); + const calleesCapturedByFnExpression = withScope(() => replaceFireFunctions(fnExpr.loweredFunc.func, context)); + for (let contextIdx = 0; contextIdx < fnExpr.loweredFunc.func.context.length; contextIdx++) { + const contextItem = fnExpr.loweredFunc.func.context[contextIdx]; + const replacedCallee = calleesCapturedByFnExpression.get(contextItem.identifier.id); + if (replacedCallee != null) { + fnExpr.loweredFunc.func.context[contextIdx] = Object.assign({}, replacedCallee.fireFunctionBinding); + } + } + context.mergeCalleesFromInnerScope(calleesCapturedByFnExpression); + return calleesCapturedByFnExpression; +} +function* eachReachablePlace(fn) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + yield* eachReachablePlace(instr.value.loweredFunc.func); + } + else { + yield* eachInstructionOperand(instr); + } + } + } +} +function ensureNoRemainingCalleeCaptures(fn, context, capturedCallees) { + var _a; + for (const place of eachReachablePlace(fn)) { + const calleeInfo = capturedCallees.get(place.identifier.id); + if (calleeInfo != null) { + const calleeName = ((_a = calleeInfo.capturedCalleeIdentifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' + ? calleeInfo.capturedCalleeIdentifier.name.value + : ''; + context.pushError({ + loc: place.loc, + description: `All uses of ${calleeName} must be either used with a fire() call in \ +this effect or not used with a fire() call at all. ${calleeName} was used with fire() on line \ +${printSourceLocationLine(calleeInfo.fireLoc)} in this effect`, + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } +} +function ensureNoMoreFireUses(fn, context) { + for (const place of eachReachablePlace(fn)) { + if (place.identifier.type.kind === 'Function' && + place.identifier.type.shapeId === BuiltInFireId) { + context.pushError({ + loc: place.identifier.loc, + description: 'Cannot use `fire` outside of a useEffect function', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } +} +function makeLoadUseFireInstruction(env, importedLoadUseFire) { + const useFirePlace = createTemporaryPlace(env, GeneratedSource); + useFirePlace.effect = Effect.Read; + useFirePlace.identifier.type = DefaultNonmutatingHook; + const instrValue = { + kind: 'LoadGlobal', + binding: Object.assign({}, importedLoadUseFire), + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + value: instrValue, + lvalue: Object.assign({}, useFirePlace), + loc: GeneratedSource, + }; +} +function makeLoadFireCalleeInstruction(env, fireCalleeIdentifier) { + const loadedFireCallee = createTemporaryPlace(env, GeneratedSource); + const fireCallee = { + kind: 'Identifier', + identifier: fireCalleeIdentifier, + reactive: false, + effect: Effect.Unknown, + loc: fireCalleeIdentifier.loc, + }; + return { + id: makeInstructionId(0), + value: { + kind: 'LoadLocal', + loc: GeneratedSource, + place: Object.assign({}, fireCallee), + }, + lvalue: Object.assign({}, loadedFireCallee), + loc: GeneratedSource, + }; +} +function makeCallUseFireInstruction(env, useFirePlace, argPlace) { + const useFireCallResultPlace = createTemporaryPlace(env, GeneratedSource); + useFireCallResultPlace.effect = Effect.Read; + const useFireCall = { + kind: 'CallExpression', + callee: Object.assign({}, useFirePlace), + args: [argPlace], + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + value: useFireCall, + lvalue: Object.assign({}, useFireCallResultPlace), + loc: GeneratedSource, + }; +} +function makeStoreUseFireInstruction(env, useFireCallResultPlace, fireFunctionBindingPlace) { + promoteTemporary(fireFunctionBindingPlace.identifier); + const fireFunctionBindingLValuePlace = createTemporaryPlace(env, GeneratedSource); + return { + id: makeInstructionId(0), + value: { + kind: 'StoreLocal', + lvalue: { + kind: InstructionKind.Const, + place: Object.assign({}, fireFunctionBindingPlace), + }, + value: Object.assign({}, useFireCallResultPlace), + type: null, + loc: GeneratedSource, + }, + lvalue: fireFunctionBindingLValuePlace, + loc: GeneratedSource, + }; +} +class Context { + constructor(env) { + _Context_env.set(this, void 0); + _Context_errors.set(this, new CompilerError()); + _Context_callExpressions.set(this, new Map()); + _Context_functionExpressions.set(this, new Map()); + _Context_loadLocals.set(this, new Map()); + _Context_fireCalleesToFireFunctions.set(this, new Map()); + _Context_calleesWithInsertedFire.set(this, new Set()); + _Context_capturedCalleeIdentifierIds.set(this, new Map()); + _Context_inUseEffectLambda.set(this, false); + _Context_loadGlobalInstructionIds.set(this, new Map()); + _Context_arrayExpressions.set(this, new Map()); + __classPrivateFieldSet(this, _Context_env, env, "f"); + } + pushError(error) { + __classPrivateFieldGet(this, _Context_errors, "f").push(error); + } + withFunctionScope(fn) { + fn(); + return __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f"); + } + withUseEffectLambdaScope(fn) { + const capturedCalleeIdentifierIds = __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f"); + const inUseEffectLambda = __classPrivateFieldGet(this, _Context_inUseEffectLambda, "f"); + __classPrivateFieldSet(this, _Context_capturedCalleeIdentifierIds, new Map(), "f"); + __classPrivateFieldSet(this, _Context_inUseEffectLambda, true, "f"); + const resultCapturedCalleeIdentifierIds = this.withFunctionScope(fn); + __classPrivateFieldSet(this, _Context_capturedCalleeIdentifierIds, capturedCalleeIdentifierIds, "f"); + __classPrivateFieldSet(this, _Context_inUseEffectLambda, inUseEffectLambda, "f"); + return resultCapturedCalleeIdentifierIds; + } + addCallExpression(id, callExpr) { + __classPrivateFieldGet(this, _Context_callExpressions, "f").set(id, callExpr); + } + getCallExpression(id) { + return __classPrivateFieldGet(this, _Context_callExpressions, "f").get(id); + } + addLoadLocalInstr(id, loadLocal) { + __classPrivateFieldGet(this, _Context_loadLocals, "f").set(id, loadLocal); + } + getLoadLocalInstr(id) { + return __classPrivateFieldGet(this, _Context_loadLocals, "f").get(id); + } + getOrGenerateFireFunctionBinding(callee, fireLoc) { + const fireFunctionBinding = getOrInsertWith(__classPrivateFieldGet(this, _Context_fireCalleesToFireFunctions, "f"), callee.identifier.id, () => createTemporaryPlace(__classPrivateFieldGet(this, _Context_env, "f"), GeneratedSource)); + fireFunctionBinding.identifier.type = { + kind: 'Function', + shapeId: BuiltInFireFunctionId, + return: { kind: 'Poly' }, + isConstructor: false, + }; + __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f").set(callee.identifier.id, { + fireFunctionBinding, + capturedCalleeIdentifier: callee.identifier, + fireLoc, + }); + return fireFunctionBinding; + } + mergeCalleesFromInnerScope(innerCallees) { + for (const [id, calleeInfo] of innerCallees.entries()) { + __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f").set(id, calleeInfo); + } + } + addCalleeWithInsertedFire(id) { + __classPrivateFieldGet(this, _Context_calleesWithInsertedFire, "f").add(id); + } + hasCalleeWithInsertedFire(id) { + return __classPrivateFieldGet(this, _Context_calleesWithInsertedFire, "f").has(id); + } + inUseEffectLambda() { + return __classPrivateFieldGet(this, _Context_inUseEffectLambda, "f"); + } + addFunctionExpression(id, fn) { + __classPrivateFieldGet(this, _Context_functionExpressions, "f").set(id, fn); + } + getFunctionExpression(id) { + return __classPrivateFieldGet(this, _Context_functionExpressions, "f").get(id); + } + addLoadGlobalInstrId(id, instrId) { + __classPrivateFieldGet(this, _Context_loadGlobalInstructionIds, "f").set(id, instrId); + } + getLoadGlobalInstrId(id) { + return __classPrivateFieldGet(this, _Context_loadGlobalInstructionIds, "f").get(id); + } + addArrayExpression(id, array) { + __classPrivateFieldGet(this, _Context_arrayExpressions, "f").set(id, array); + } + getArrayExpression(id) { + return __classPrivateFieldGet(this, _Context_arrayExpressions, "f").get(id); + } + hasErrors() { + return __classPrivateFieldGet(this, _Context_errors, "f").hasErrors(); + } + throwIfErrorsFound() { + if (this.hasErrors()) + throw __classPrivateFieldGet(this, _Context_errors, "f"); + } +} +_Context_env = new WeakMap(), _Context_errors = new WeakMap(), _Context_callExpressions = new WeakMap(), _Context_functionExpressions = new WeakMap(), _Context_loadLocals = new WeakMap(), _Context_fireCalleesToFireFunctions = new WeakMap(), _Context_calleesWithInsertedFire = new WeakMap(), _Context_capturedCalleeIdentifierIds = new WeakMap(), _Context_inUseEffectLambda = new WeakMap(), _Context_loadGlobalInstructionIds = new WeakMap(), _Context_arrayExpressions = new WeakMap(); +function deleteInstructions(deleteInstrs, instructions) { + if (deleteInstrs.size > 0) { + const newInstrs = instructions.filter(instr => !deleteInstrs.has(instr.id)); + return newInstrs; + } + return instructions; +} +function rewriteInstructions(rewriteInstrs, instructions) { + if (rewriteInstrs.size > 0) { + const newInstrs = []; + for (const instr of instructions) { + const newInstrsAtId = rewriteInstrs.get(instr.id); + if (newInstrsAtId != null) { + newInstrs.push(...newInstrsAtId, instr); + } + else { + newInstrs.push(instr); + } + } + return newInstrs; + } + return instructions; +} + +function validateNoImpureFunctionsInRender(fn) { + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const value = instr.value; + if (value.kind === 'MethodCall' || value.kind == 'CallExpression') { + const callee = value.kind === 'MethodCall' ? value.property : value.callee; + const signature = getFunctionCallSignature(fn.env, callee.identifier.type); + if (signature != null && signature.impure === true) { + errors.push({ + reason: 'Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)', + description: signature.canonicalName != null + ? `\`${signature.canonicalName}\` is an impure function whose results may change on every call` + : null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + } + } + } + return errors.asResult(); +} + +function validateStaticComponents(fn) { + const error = new CompilerError(); + const knownDynamicComponents = new Map(); + for (const block of fn.body.blocks.values()) { + phis: for (const phi of block.phis) { + for (const operand of phi.operands.values()) { + const loc = knownDynamicComponents.get(operand.identifier.id); + if (loc != null) { + knownDynamicComponents.set(phi.place.identifier.id, loc); + continue phis; + } + } + } + for (const instr of block.instructions) { + const { lvalue, value } = instr; + switch (value.kind) { + case 'FunctionExpression': + case 'NewExpression': + case 'MethodCall': + case 'CallExpression': { + knownDynamicComponents.set(lvalue.identifier.id, value.loc); + break; + } + case 'LoadLocal': { + const loc = knownDynamicComponents.get(value.place.identifier.id); + if (loc != null) { + knownDynamicComponents.set(lvalue.identifier.id, loc); + } + break; + } + case 'StoreLocal': { + const loc = knownDynamicComponents.get(value.value.identifier.id); + if (loc != null) { + knownDynamicComponents.set(lvalue.identifier.id, loc); + knownDynamicComponents.set(value.lvalue.place.identifier.id, loc); + } + break; + } + case 'JsxExpression': { + if (value.tag.kind === 'Identifier') { + const location = knownDynamicComponents.get(value.tag.identifier.id); + if (location != null) { + error.push({ + reason: `Components created during render will reset their state each time they are created. Declare components outside of render. `, + severity: ErrorSeverity.InvalidReact, + loc: value.tag.loc, + description: null, + suggestions: null, + }); + error.push({ + reason: `The component may be created during render`, + severity: ErrorSeverity.InvalidReact, + loc: location, + description: null, + suggestions: null, + }); + } + } + } + } + } + } + return error.asResult(); +} + +function run(func, config, fnType, mode, programContext, logger, filename, code) { + var _a, _b; + const contextIdentifiers = findContextIdentifiers(func); + const env = new Environment(func.scope, fnType, mode, config, contextIdentifiers, logger, filename, code, programContext); + (_b = (_a = env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'debug', + name: 'EnvironmentConfig', + value: prettyFormat(env.config), + }); + return runWithEnvironment(func, env); +} +function runWithEnvironment(func, env) { + const log = (value) => { + var _a, _b; + (_b = (_a = env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, value); + }; + const hir = lower$1(func, env).unwrap(); + log({ kind: 'hir', name: 'HIR', value: hir }); + pruneMaybeThrows(hir); + log({ kind: 'hir', name: 'PruneMaybeThrows', value: hir }); + validateContextVariableLValues(hir); + validateUseMemo(hir).unwrap(); + if (env.isInferredMemoEnabled && + !env.config.enablePreserveExistingManualUseMemo && + !env.config.disableMemoizationForDebugging && + !env.config.enableChangeDetectionForDebugging) { + dropManualMemoization(hir); + log({ kind: 'hir', name: 'DropManualMemoization', value: hir }); + } + inlineImmediatelyInvokedFunctionExpressions(hir); + log({ + kind: 'hir', + name: 'InlineImmediatelyInvokedFunctionExpressions', + value: hir, + }); + mergeConsecutiveBlocks(hir); + log({ kind: 'hir', name: 'MergeConsecutiveBlocks', value: hir }); + assertConsistentIdentifiers(hir); + assertTerminalSuccessorsExist(hir); + enterSSA(hir); + log({ kind: 'hir', name: 'SSA', value: hir }); + eliminateRedundantPhi(hir); + log({ kind: 'hir', name: 'EliminateRedundantPhi', value: hir }); + assertConsistentIdentifiers(hir); + constantPropagation(hir); + log({ kind: 'hir', name: 'ConstantPropagation', value: hir }); + inferTypes(hir); + log({ kind: 'hir', name: 'InferTypes', value: hir }); + if (env.isInferredMemoEnabled) { + if (env.config.validateHooksUsage) { + validateHooksUsage(hir).unwrap(); + } + if (env.config.validateNoCapitalizedCalls) { + validateNoCapitalizedCalls(hir).unwrap(); + } + } + if (env.config.enableFire) { + transformFire(hir); + log({ kind: 'hir', name: 'TransformFire', value: hir }); + } + if (env.config.lowerContextAccess) { + lowerContextAccess(hir, env.config.lowerContextAccess); + } + optimizePropsMethodCalls(hir); + log({ kind: 'hir', name: 'OptimizePropsMethodCalls', value: hir }); + analyseFunctions(hir); + log({ kind: 'hir', name: 'AnalyseFunctions', value: hir }); + const fnEffectErrors = inferReferenceEffects(hir); + if (env.isInferredMemoEnabled) { + if (fnEffectErrors.length > 0) { + CompilerError.throw(fnEffectErrors[0]); + } + } + log({ kind: 'hir', name: 'InferReferenceEffects', value: hir }); + validateLocalsNotReassignedAfterRender(hir); + deadCodeElimination(hir); + log({ kind: 'hir', name: 'DeadCodeElimination', value: hir }); + if (env.config.enableInstructionReordering) { + instructionReordering(hir); + log({ kind: 'hir', name: 'InstructionReordering', value: hir }); + } + pruneMaybeThrows(hir); + log({ kind: 'hir', name: 'PruneMaybeThrows', value: hir }); + inferMutableRanges(hir); + log({ kind: 'hir', name: 'InferMutableRanges', value: hir }); + if (env.isInferredMemoEnabled) { + if (env.config.assertValidMutableRanges) { + assertValidMutableRanges(hir); + } + if (env.config.validateRefAccessDuringRender) { + validateNoRefAccessInRender(hir).unwrap(); + } + if (env.config.validateNoSetStateInRender) { + validateNoSetStateInRender(hir).unwrap(); + } + if (env.config.validateNoSetStateInPassiveEffects) { + env.logErrors(validateNoSetStateInPassiveEffects(hir)); + } + if (env.config.validateNoJSXInTryStatements) { + env.logErrors(validateNoJSXInTryStatement(hir)); + } + if (env.config.validateNoImpureFunctionsInRender) { + validateNoImpureFunctionsInRender(hir).unwrap(); + } + } + inferReactivePlaces(hir); + log({ kind: 'hir', name: 'InferReactivePlaces', value: hir }); + rewriteInstructionKindsBasedOnReassignment(hir); + log({ + kind: 'hir', + name: 'RewriteInstructionKindsBasedOnReassignment', + value: hir, + }); + propagatePhiTypes(hir); + log({ + kind: 'hir', + name: 'PropagatePhiTypes', + value: hir, + }); + if (env.isInferredMemoEnabled) { + if (env.config.validateStaticComponents) { + env.logErrors(validateStaticComponents(hir)); + } + inferReactiveScopeVariables(hir); + log({ kind: 'hir', name: 'InferReactiveScopeVariables', value: hir }); + } + const fbtOperands = memoizeFbtAndMacroOperandsInSameScope(hir); + log({ + kind: 'hir', + name: 'MemoizeFbtAndMacroOperandsInSameScope', + value: hir, + }); + if (env.config.enableJsxOutlining) { + outlineJSX(hir); + } + if (env.config.enableFunctionOutlining) { + outlineFunctions(hir, fbtOperands); + log({ kind: 'hir', name: 'OutlineFunctions', value: hir }); + } + alignMethodCallScopes(hir); + log({ + kind: 'hir', + name: 'AlignMethodCallScopes', + value: hir, + }); + alignObjectMethodScopes(hir); + log({ + kind: 'hir', + name: 'AlignObjectMethodScopes', + value: hir, + }); + pruneUnusedLabelsHIR(hir); + log({ + kind: 'hir', + name: 'PruneUnusedLabelsHIR', + value: hir, + }); + alignReactiveScopesToBlockScopesHIR(hir); + log({ + kind: 'hir', + name: 'AlignReactiveScopesToBlockScopesHIR', + value: hir, + }); + mergeOverlappingReactiveScopesHIR(hir); + log({ + kind: 'hir', + name: 'MergeOverlappingReactiveScopesHIR', + value: hir, + }); + assertValidBlockNesting(hir); + buildReactiveScopeTerminalsHIR(hir); + log({ + kind: 'hir', + name: 'BuildReactiveScopeTerminalsHIR', + value: hir, + }); + assertValidBlockNesting(hir); + flattenReactiveLoopsHIR(hir); + log({ + kind: 'hir', + name: 'FlattenReactiveLoopsHIR', + value: hir, + }); + flattenScopesWithHooksOrUseHIR(hir); + log({ + kind: 'hir', + name: 'FlattenScopesWithHooksOrUseHIR', + value: hir, + }); + assertTerminalSuccessorsExist(hir); + assertTerminalPredsExist(hir); + propagateScopeDependenciesHIR(hir); + log({ + kind: 'hir', + name: 'PropagateScopeDependenciesHIR', + value: hir, + }); + if (env.config.inferEffectDependencies) { + inferEffectDependencies(hir); + log({ + kind: 'hir', + name: 'InferEffectDependencies', + value: hir, + }); + } + if (env.config.inlineJsxTransform) { + inlineJsxTransform(hir, env.config.inlineJsxTransform); + log({ + kind: 'hir', + name: 'inlineJsxTransform', + value: hir, + }); + } + const reactiveFunction = buildReactiveFunction(hir); + log({ + kind: 'reactive', + name: 'BuildReactiveFunction', + value: reactiveFunction, + }); + assertWellFormedBreakTargets(reactiveFunction); + pruneUnusedLabels(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedLabels', + value: reactiveFunction, + }); + assertScopeInstructionsWithinScopes(reactiveFunction); + pruneNonEscapingScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneNonEscapingScopes', + value: reactiveFunction, + }); + pruneNonReactiveDependencies(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneNonReactiveDependencies', + value: reactiveFunction, + }); + pruneUnusedScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedScopes', + value: reactiveFunction, + }); + mergeReactiveScopesThatInvalidateTogether(reactiveFunction); + log({ + kind: 'reactive', + name: 'MergeReactiveScopesThatInvalidateTogether', + value: reactiveFunction, + }); + pruneAlwaysInvalidatingScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneAlwaysInvalidatingScopes', + value: reactiveFunction, + }); + if (env.config.enableChangeDetectionForDebugging != null) { + pruneInitializationDependencies(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneInitializationDependencies', + value: reactiveFunction, + }); + } + propagateEarlyReturns(reactiveFunction); + log({ + kind: 'reactive', + name: 'PropagateEarlyReturns', + value: reactiveFunction, + }); + pruneUnusedLValues(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedLValues', + value: reactiveFunction, + }); + promoteUsedTemporaries(reactiveFunction); + log({ + kind: 'reactive', + name: 'PromoteUsedTemporaries', + value: reactiveFunction, + }); + extractScopeDeclarationsFromDestructuring(reactiveFunction); + log({ + kind: 'reactive', + name: 'ExtractScopeDeclarationsFromDestructuring', + value: reactiveFunction, + }); + stabilizeBlockIds(reactiveFunction); + log({ + kind: 'reactive', + name: 'StabilizeBlockIds', + value: reactiveFunction, + }); + const uniqueIdentifiers = renameVariables(reactiveFunction); + log({ + kind: 'reactive', + name: 'RenameVariables', + value: reactiveFunction, + }); + pruneHoistedContexts(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneHoistedContexts', + value: reactiveFunction, + }); + if (env.config.validateMemoizedEffectDependencies) { + validateMemoizedEffectDependencies(reactiveFunction).unwrap(); + } + if (env.config.enablePreserveExistingMemoizationGuarantees || + env.config.validatePreserveExistingMemoizationGuarantees) { + validatePreservedManualMemoization(reactiveFunction).unwrap(); + } + const ast = codegenFunction(reactiveFunction, { + uniqueIdentifiers, + fbtOperands, + }).unwrap(); + log({ kind: 'ast', name: 'Codegen', value: ast }); + for (const outlined of ast.outlined) { + log({ kind: 'ast', name: 'Codegen (outlined)', value: outlined.fn }); + } + if (env.config.throwUnknownException__testonly) { + throw new Error('unexpected error'); + } + return ast; +} +function compileFn(func, config, fnType, mode, programContext, logger, filename, code) { + return run(func, config, fnType, mode, programContext, logger, filename, code); +} + +function filterSuppressionsThatAffectFunction(suppressionRanges, fn) { + const suppressionsInScope = []; + const fnNode = fn.node; + for (const suppressionRange of suppressionRanges) { + if (suppressionRange.disableComment.start == null || + fnNode.start == null || + fnNode.end == null) { + continue; + } + if (suppressionRange.disableComment.start > fnNode.start && + (suppressionRange.enableComment === null || + (suppressionRange.enableComment.end != null && + suppressionRange.enableComment.end < fnNode.end))) { + suppressionsInScope.push(suppressionRange); + } + if (suppressionRange.disableComment.start < fnNode.start && + (suppressionRange.enableComment === null || + (suppressionRange.enableComment.end != null && + suppressionRange.enableComment.end > fnNode.end))) { + suppressionsInScope.push(suppressionRange); + } + } + return suppressionsInScope; +} +function findProgramSuppressions(programComments, ruleNames, flowSuppressions) { + const suppressionRanges = []; + let disableComment = null; + let enableComment = null; + let source = null; + const rulePattern = `(${ruleNames.join('|')})`; + const disableNextLinePattern = new RegExp(`eslint-disable-next-line ${rulePattern}`); + const disablePattern = new RegExp(`eslint-disable ${rulePattern}`); + const enablePattern = new RegExp(`eslint-enable ${rulePattern}`); + const flowSuppressionPattern = new RegExp('\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule'); + for (const comment of programComments) { + if (comment.start == null || comment.end == null) { + continue; + } + if (disableComment == null && + disableNextLinePattern.test(comment.value)) { + disableComment = comment; + enableComment = comment; + source = 'Eslint'; + } + if (flowSuppressions && + disableComment == null && + flowSuppressionPattern.test(comment.value)) { + disableComment = comment; + enableComment = comment; + source = 'Flow'; + } + if (disablePattern.test(comment.value)) { + disableComment = comment; + source = 'Eslint'; + } + if (enablePattern.test(comment.value) && source === 'Eslint') { + enableComment = comment; + } + if (disableComment != null && source != null) { + suppressionRanges.push({ + disableComment: disableComment, + enableComment: enableComment, + source, + }); + disableComment = null; + enableComment = null; + source = null; + } + } + return suppressionRanges; +} +function suppressionsToCompilerError(suppressionRanges) { + var _a; + CompilerError.invariant(suppressionRanges.length !== 0, { + reason: `Expected at least suppression comment source range`, + loc: GeneratedSource, + }); + const error = new CompilerError(); + for (const suppressionRange of suppressionRanges) { + if (suppressionRange.disableComment.start == null || + suppressionRange.disableComment.end == null) { + continue; + } + let reason, suggestion; + switch (suppressionRange.source) { + case 'Eslint': + reason = + 'React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled'; + suggestion = + 'Remove the ESLint suppression and address the React error'; + break; + case 'Flow': + reason = + 'React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow'; + suggestion = 'Remove the Flow suppression and address the React error'; + break; + default: + assertExhaustive$1(suppressionRange.source, 'Unhandled suppression source'); + } + error.pushErrorDetail(new CompilerErrorDetail({ + reason: `${reason}. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior`, + description: suppressionRange.disableComment.value.trim(), + severity: ErrorSeverity.InvalidReact, + loc: (_a = suppressionRange.disableComment.loc) !== null && _a !== void 0 ? _a : null, + suggestions: [ + { + description: suggestion, + range: [ + suppressionRange.disableComment.start, + suppressionRange.disableComment.end, + ], + op: CompilerSuggestionOperation.Remove, + }, + ], + })); + } + return error; +} + +const OPT_IN_DIRECTIVES = new Set(['use forget', 'use memo']); +const OPT_OUT_DIRECTIVES = new Set(['use no forget', 'use no memo']); +function findDirectiveEnablingMemoization(directives) { + return directives.filter(directive => OPT_IN_DIRECTIVES.has(directive.value.value)); +} +function findDirectiveDisablingMemoization(directives) { + return directives.filter(directive => OPT_OUT_DIRECTIVES.has(directive.value.value)); +} +function isCriticalError(err) { + return !(err instanceof CompilerError) || err.isCritical(); +} +function isConfigError(err) { + if (err instanceof CompilerError) { + return err.details.some(detail => detail.severity === ErrorSeverity.InvalidConfig); + } + return false; +} +function logError(err, pass, fnLoc) { + var _a, _b; + if (pass.opts.logger) { + if (err instanceof CompilerError) { + for (const detail of err.details) { + pass.opts.logger.logEvent(pass.filename, { + kind: 'CompileError', + fnLoc, + detail: detail.options, + }); + } + } + else { + let stringifiedError; + if (err instanceof Error) { + stringifiedError = (_a = err.stack) !== null && _a !== void 0 ? _a : err.message; + } + else { + stringifiedError = (_b = err === null || err === void 0 ? void 0 : err.toString()) !== null && _b !== void 0 ? _b : '[ null ]'; + } + pass.opts.logger.logEvent(pass.filename, { + kind: 'PipelineError', + fnLoc, + data: stringifiedError, + }); + } + } +} +function handleError(err, pass, fnLoc) { + logError(err, pass, fnLoc); + if (pass.opts.panicThreshold === 'all_errors' || + (pass.opts.panicThreshold === 'critical_errors' && isCriticalError(err)) || + isConfigError(err)) { + throw err; + } +} +function createNewFunctionNode(originalFn, compiledFn) { + var _a, _b, _c; + let transformedFn; + switch (originalFn.node.type) { + case 'FunctionDeclaration': { + const fn = { + type: 'FunctionDeclaration', + id: compiledFn.id, + loc: (_a = originalFn.node.loc) !== null && _a !== void 0 ? _a : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + case 'ArrowFunctionExpression': { + const fn = { + type: 'ArrowFunctionExpression', + loc: (_b = originalFn.node.loc) !== null && _b !== void 0 ? _b : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + expression: originalFn.node.expression, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + case 'FunctionExpression': { + const fn = { + type: 'FunctionExpression', + id: compiledFn.id, + loc: (_c = originalFn.node.loc) !== null && _c !== void 0 ? _c : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + default: { + assertExhaustive$1(originalFn.node, `Creating unhandled function: ${originalFn.node}`); + } + } + ALREADY_COMPILED.add(transformedFn); + return transformedFn; +} +function insertNewOutlinedFunctionNode(program, originalFn, compiledFn) { + var _a, _b, _c; + switch (originalFn.type) { + case 'FunctionDeclaration': { + return originalFn.insertAfter(createNewFunctionNode(originalFn, compiledFn))[0]; + } + case 'ArrowFunctionExpression': + case 'FunctionExpression': { + const fn = { + type: 'FunctionDeclaration', + id: compiledFn.id, + loc: (_a = originalFn.node.loc) !== null && _a !== void 0 ? _a : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + const insertedFuncDecl = program.pushContainer('body', [fn])[0]; + CompilerError.invariant(insertedFuncDecl.isFunctionDeclaration(), { + reason: 'Expected inserted function declaration', + description: `Got: ${insertedFuncDecl}`, + loc: (_c = (_b = insertedFuncDecl.node) === null || _b === void 0 ? void 0 : _b.loc) !== null && _c !== void 0 ? _c : null, + }); + return insertedFuncDecl; + } + default: { + assertExhaustive$1(originalFn, `Inserting unhandled function: ${originalFn}`); + } + } +} +const ALREADY_COMPILED = new (WeakSet !== null && WeakSet !== void 0 ? WeakSet : Set)(); +const DEFAULT_ESLINT_SUPPRESSIONS = [ + 'react-hooks/exhaustive-deps', + 'react-hooks/rules-of-hooks', +]; +function isFilePartOfSources(sources, filename) { + if (typeof sources === 'function') { + return sources(filename); + } + for (const prefix of sources) { + if (filename.indexOf(prefix) !== -1) { + return true; + } + } + return false; +} +function compileProgram(program, pass) { + var _a, _b; + if (shouldSkipCompilation(program, pass)) { + return null; + } + const environment = pass.opts.environment; + const restrictedImportsErr = validateRestrictedImports(program, environment); + if (restrictedImportsErr) { + handleError(restrictedImportsErr, pass, null); + return null; + } + const programContext = new ProgramContext(program, pass.opts.target, environment.hookPattern); + const suppressions = findProgramSuppressions(pass.comments, (_a = pass.opts.eslintSuppressionRules) !== null && _a !== void 0 ? _a : DEFAULT_ESLINT_SUPPRESSIONS, pass.opts.flowSuppressions); + const queue = []; + const compiledFns = []; + const traverseFunction = (fn, pass) => { + const fnType = getReactFunctionType(fn, pass, environment); + if (fnType === null || ALREADY_COMPILED.has(fn.node)) { + return; + } + ALREADY_COMPILED.add(fn.node); + fn.skip(); + queue.push({ kind: 'original', fn, fnType }); + }; + program.traverse({ + ClassDeclaration(node) { + node.skip(); + return; + }, + ClassExpression(node) { + node.skip(); + return; + }, + FunctionDeclaration: traverseFunction, + FunctionExpression: traverseFunction, + ArrowFunctionExpression: traverseFunction, + }, Object.assign(Object.assign({}, pass), { opts: Object.assign(Object.assign({}, pass.opts), pass.opts), filename: (_b = pass.filename) !== null && _b !== void 0 ? _b : null })); + const retryErrors = []; + const inferredEffectLocations = new Set(); + const processFn = (fn, fnType) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + let optInDirectives = []; + let optOutDirectives = []; + if (fn.node.body.type === 'BlockStatement') { + optInDirectives = findDirectiveEnablingMemoization(fn.node.body.directives); + optOutDirectives = findDirectiveDisablingMemoization(fn.node.body.directives); + } + const suppressionsInFunction = filterSuppressionsThatAffectFunction(suppressions, fn); + let compileResult; + if (suppressionsInFunction.length > 0) { + compileResult = { + kind: 'error', + error: suppressionsToCompilerError(suppressionsInFunction), + }; + } + else { + try { + compileResult = { + kind: 'compile', + compiledFn: compileFn(fn, environment, fnType, 'all_features', programContext, pass.opts.logger, pass.filename, pass.code), + }; + } + catch (err) { + compileResult = { kind: 'error', error: err }; + } + } + if (compileResult.kind === 'error') { + if (optOutDirectives.length > 0) { + logError(compileResult.error, pass, (_a = fn.node.loc) !== null && _a !== void 0 ? _a : null); + } + else { + handleError(compileResult.error, pass, (_b = fn.node.loc) !== null && _b !== void 0 ? _b : null); + } + if (!(environment.enableFire || environment.inferEffectDependencies != null)) { + return null; + } + try { + compileResult = { + kind: 'compile', + compiledFn: compileFn(fn, environment, fnType, 'no_inferred_memo', programContext, pass.opts.logger, pass.filename, pass.code), + }; + if (!compileResult.compiledFn.hasFireRewrite && + !compileResult.compiledFn.hasInferredEffect) { + return null; + } + } + catch (err) { + if (err instanceof CompilerError) { + retryErrors.push({ fn, error: err }); + } + return null; + } + } + if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) { + for (const directive of optOutDirectives) { + (_c = pass.opts.logger) === null || _c === void 0 ? void 0 : _c.logEvent(pass.filename, { + kind: 'CompileSkip', + fnLoc: (_d = fn.node.body.loc) !== null && _d !== void 0 ? _d : null, + reason: `Skipped due to '${directive.value.value}' directive.`, + loc: (_e = directive.loc) !== null && _e !== void 0 ? _e : null, + }); + } + return null; + } + (_f = pass.opts.logger) === null || _f === void 0 ? void 0 : _f.logEvent(pass.filename, { + kind: 'CompileSuccess', + fnLoc: (_g = fn.node.loc) !== null && _g !== void 0 ? _g : null, + fnName: (_j = (_h = compileResult.compiledFn.id) === null || _h === void 0 ? void 0 : _h.name) !== null && _j !== void 0 ? _j : null, + memoSlots: compileResult.compiledFn.memoSlotsUsed, + memoBlocks: compileResult.compiledFn.memoBlocks, + memoValues: compileResult.compiledFn.memoValues, + prunedMemoBlocks: compileResult.compiledFn.prunedMemoBlocks, + prunedMemoValues: compileResult.compiledFn.prunedMemoValues, + }); + if (optInDirectives.length > 0) { + return compileResult.compiledFn; + } + else if (pass.opts.compilationMode === 'annotation') { + return null; + } + if (!pass.opts.noEmit) { + return compileResult.compiledFn; + } + for (const loc of compileResult.compiledFn.inferredEffectLocations) { + if (loc !== GeneratedSource) + inferredEffectLocations.add(loc); + } + return null; + }; + while (queue.length !== 0) { + const current = queue.shift(); + const compiled = processFn(current.fn, current.fnType); + if (compiled === null) { + continue; + } + for (const outlined of compiled.outlined) { + CompilerError.invariant(outlined.fn.outlined.length === 0, { + reason: 'Unexpected nested outlined functions', + loc: outlined.fn.loc, + }); + const fn = insertNewOutlinedFunctionNode(program, current.fn, outlined.fn); + fn.skip(); + ALREADY_COMPILED.add(fn.node); + if (outlined.type !== null) { + queue.push({ + kind: 'outlined', + fn, + fnType: outlined.type, + }); + } + } + compiledFns.push({ + kind: current.kind, + compiledFn: compiled, + originalFn: current.fn, + }); + } + const moduleScopeOptOutDirectives = findDirectiveDisablingMemoization(program.node.directives); + if (moduleScopeOptOutDirectives.length > 0) { + return null; + } + const referencedBeforeDeclared = pass.opts.gating != null + ? getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns) + : null; + for (const result of compiledFns) { + const { kind, originalFn, compiledFn } = result; + const transformedFn = createNewFunctionNode(originalFn, compiledFn); + if (referencedBeforeDeclared != null && kind === 'original') { + CompilerError.invariant(pass.opts.gating != null, { + reason: "Expected 'gating' import to be present", + loc: null, + }); + insertGatedFunctionDeclaration(originalFn, transformedFn, programContext, pass.opts.gating, referencedBeforeDeclared.has(result)); + } + else { + originalFn.replaceWith(transformedFn); + } + } + if (compiledFns.length > 0) { + addImportsToProgram(program, programContext); + } + return { retryErrors, inferredEffectLocations }; +} +function shouldSkipCompilation(program, pass) { + if (pass.opts.sources) { + if (pass.filename === null) { + const error = new CompilerError(); + error.pushErrorDetail(new CompilerErrorDetail({ + reason: `Expected a filename but found none.`, + description: "When the 'sources' config options is specified, the React compiler will only compile files with a name", + severity: ErrorSeverity.InvalidConfig, + loc: null, + })); + handleError(error, pass, null); + return true; + } + if (!isFilePartOfSources(pass.opts.sources, pass.filename)) { + return true; + } + } + if (hasMemoCacheFunctionImport(program, getReactCompilerRuntimeModule(pass.opts.target))) { + return true; + } + return false; +} +function getReactFunctionType(fn, pass, environment) { + var _a, _b; + const hookPattern = environment.hookPattern; + if (fn.node.body.type === 'BlockStatement') { + if (findDirectiveEnablingMemoization(fn.node.body.directives).length > 0) + return (_a = getComponentOrHookLike(fn, hookPattern)) !== null && _a !== void 0 ? _a : 'Other'; + } + let componentSyntaxType = null; + if (fn.isFunctionDeclaration()) { + if (isComponentDeclaration(fn.node)) { + componentSyntaxType = 'Component'; + } + else if (isHookDeclaration(fn.node)) { + componentSyntaxType = 'Hook'; + } + } + switch (pass.opts.compilationMode) { + case 'annotation': { + return null; + } + case 'infer': { + return componentSyntaxType !== null && componentSyntaxType !== void 0 ? componentSyntaxType : getComponentOrHookLike(fn, hookPattern); + } + case 'syntax': { + return componentSyntaxType; + } + case 'all': { + if (fn.scope.getProgramParent() !== fn.scope.parent) { + return null; + } + return (_b = getComponentOrHookLike(fn, hookPattern)) !== null && _b !== void 0 ? _b : 'Other'; + } + default: { + assertExhaustive$1(pass.opts.compilationMode, `Unexpected compilationMode \`${pass.opts.compilationMode}\``); + } + } +} +function hasMemoCacheFunctionImport(program, moduleName) { + let hasUseMemoCache = false; + program.traverse({ + ImportSpecifier(path) { + const imported = path.get('imported'); + let importedName = null; + if (imported.isIdentifier()) { + importedName = imported.node.name; + } + else if (imported.isStringLiteral()) { + importedName = imported.node.value; + } + if (importedName === 'c' && + path.parentPath.isImportDeclaration() && + path.parentPath.get('source').node.value === moduleName) { + hasUseMemoCache = true; + } + }, + }); + return hasUseMemoCache; +} +function isHookName$1(s, hookPattern) { + if (hookPattern !== null) { + return new RegExp(hookPattern).test(s); + } + return /^use[A-Z0-9]/.test(s); +} +function isHook$1(path, hookPattern) { + if (path.isIdentifier()) { + return isHookName$1(path.node.name, hookPattern); + } + else if (path.isMemberExpression() && + !path.node.computed && + isHook$1(path.get('property'), hookPattern)) { + const obj = path.get('object').node; + const isPascalCaseNameSpace = /^[A-Z].*/; + return obj.type === 'Identifier' && isPascalCaseNameSpace.test(obj.name); + } + else { + return false; + } +} +function isComponentName$1(path) { + return path.isIdentifier() && /^[A-Z]/.test(path.node.name); +} +function isReactAPI(path, functionName) { + const node = path.node; + return ((node.type === 'Identifier' && node.name === functionName) || + (node.type === 'MemberExpression' && + node.object.type === 'Identifier' && + node.object.name === 'React' && + node.property.type === 'Identifier' && + node.property.name === functionName)); +} +function isForwardRefCallback$1(path) { + return !!(path.parentPath.isCallExpression() && + path.parentPath.get('callee').isExpression() && + isReactAPI(path.parentPath.get('callee'), 'forwardRef')); +} +function isMemoCallback$1(path) { + return (path.parentPath.isCallExpression() && + path.parentPath.get('callee').isExpression() && + isReactAPI(path.parentPath.get('callee'), 'memo')); +} +function isValidPropsAnnotation(annot) { + if (annot == null) { + return true; + } + else if (annot.type === 'TSTypeAnnotation') { + switch (annot.typeAnnotation.type) { + case 'TSArrayType': + case 'TSBigIntKeyword': + case 'TSBooleanKeyword': + case 'TSConstructorType': + case 'TSFunctionType': + case 'TSLiteralType': + case 'TSNeverKeyword': + case 'TSNumberKeyword': + case 'TSStringKeyword': + case 'TSSymbolKeyword': + case 'TSTupleType': + return false; + } + return true; + } + else if (annot.type === 'TypeAnnotation') { + switch (annot.typeAnnotation.type) { + case 'ArrayTypeAnnotation': + case 'BooleanLiteralTypeAnnotation': + case 'BooleanTypeAnnotation': + case 'EmptyTypeAnnotation': + case 'FunctionTypeAnnotation': + case 'NumberLiteralTypeAnnotation': + case 'NumberTypeAnnotation': + case 'StringLiteralTypeAnnotation': + case 'StringTypeAnnotation': + case 'SymbolTypeAnnotation': + case 'ThisTypeAnnotation': + case 'TupleTypeAnnotation': + return false; + } + return true; + } + else if (annot.type === 'Noop') { + return true; + } + else { + assertExhaustive$1(annot, `Unexpected annotation node \`${annot}\``); + } +} +function isValidComponentParams(params) { + if (params.length === 0) { + return true; + } + else if (params.length > 0 && params.length <= 2) { + if (!isValidPropsAnnotation(params[0].node.typeAnnotation)) { + return false; + } + if (params.length === 1) { + return !params[0].isRestElement(); + } + else if (params[1].isIdentifier()) { + const { name } = params[1].node; + return name.includes('ref') || name.includes('Ref'); + } + else { + return false; + } + } + return false; +} +function getComponentOrHookLike(node, hookPattern) { + const functionName = getFunctionName$1(node); + if (functionName !== null && isComponentName$1(functionName)) { + let isComponent = callsHooksOrCreatesJsx(node, hookPattern) && + isValidComponentParams(node.get('params')) && + !returnsNonNode(node); + return isComponent ? 'Component' : null; + } + else if (functionName !== null && isHook$1(functionName, hookPattern)) { + return callsHooksOrCreatesJsx(node, hookPattern) ? 'Hook' : null; + } + if (node.isFunctionExpression() || node.isArrowFunctionExpression()) { + if (isForwardRefCallback$1(node) || isMemoCallback$1(node)) { + return callsHooksOrCreatesJsx(node, hookPattern) ? 'Component' : null; + } + } + return null; +} +function skipNestedFunctions(node) { + return (fn) => { + if (fn.node !== node.node) { + fn.skip(); + } + }; +} +function callsHooksOrCreatesJsx(node, hookPattern) { + let invokesHooks = false; + let createsJsx = false; + node.traverse({ + JSX() { + createsJsx = true; + }, + CallExpression(call) { + const callee = call.get('callee'); + if (callee.isExpression() && isHook$1(callee, hookPattern)) { + invokesHooks = true; + } + }, + ArrowFunctionExpression: skipNestedFunctions(node), + FunctionExpression: skipNestedFunctions(node), + FunctionDeclaration: skipNestedFunctions(node), + }); + return invokesHooks || createsJsx; +} +function isNonNode(node) { + if (!node) { + return true; + } + switch (node.type) { + case 'ObjectExpression': + case 'ArrowFunctionExpression': + case 'FunctionExpression': + case 'BigIntLiteral': + case 'ClassExpression': + case 'NewExpression': + return true; + } + return false; +} +function returnsNonNode(node) { + let returnsNonNode = false; + if (node.type === 'ArrowFunctionExpression' && + node.node.body.type !== 'BlockStatement') { + returnsNonNode = isNonNode(node.node.body); + } + node.traverse({ + ReturnStatement(ret) { + returnsNonNode = isNonNode(ret.node.argument); + }, + ArrowFunctionExpression: skipNestedFunctions(node), + FunctionExpression: skipNestedFunctions(node), + FunctionDeclaration: skipNestedFunctions(node), + ObjectMethod: node => node.skip(), + }); + return returnsNonNode; +} +function getFunctionName$1(path) { + if (path.isFunctionDeclaration()) { + const id = path.get('id'); + if (id.isIdentifier()) { + return id; + } + return null; + } + let id = null; + const parent = path.parentPath; + if (parent.isVariableDeclarator() && parent.get('init').node === path.node) { + id = parent.get('id'); + } + else if (parent.isAssignmentExpression() && + parent.get('right').node === path.node && + parent.get('operator') === '=') { + id = parent.get('left'); + } + else if (parent.isProperty() && + parent.get('value').node === path.node && + !parent.get('computed') && + parent.get('key').isLVal()) { + id = parent.get('key'); + } + else if (parent.isAssignmentPattern() && + parent.get('right').node === path.node && + !parent.get('computed')) { + id = parent.get('left'); + } + if (id !== null && (id.isIdentifier() || id.isMemberExpression())) { + return id; + } + else { + return null; + } +} +function getFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) { + const fnNames = new Map(fns + .map(fn => [ + getFunctionName$1(fn.originalFn), + fn, + ]) + .filter((entry) => !!entry[0] && entry[0].isIdentifier()) + .map(entry => [entry[0].node.name, { id: entry[0].node, fn: entry[1] }])); + const referencedBeforeDeclaration = new Set(); + program.traverse({ + TypeAnnotation(path) { + path.skip(); + }, + TSTypeAnnotation(path) { + path.skip(); + }, + TypeAlias(path) { + path.skip(); + }, + TSTypeAliasDeclaration(path) { + path.skip(); + }, + Identifier(id) { + const fn = fnNames.get(id.node.name); + if (!fn) { + return; + } + if (id.node === fn.id) { + fnNames.delete(id.node.name); + return; + } + const scope = id.scope.getFunctionParent(); + if (scope === null && id.isReferencedIdentifier()) { + referencedBeforeDeclaration.add(fn.fn); + } + }, + }); + return referencedBeforeDeclaration; +} +function getReactCompilerRuntimeModule(target) { + if (target === '19') { + return 'react/compiler-runtime'; + } + else if (target === '17' || target === '18') { + return 'react-compiler-runtime'; + } + else { + CompilerError.invariant(target != null && + target.kind === 'donotuse_meta_internal' && + typeof target.runtimeModule === 'string', { + reason: 'Expected target to already be validated', + description: null, + loc: null, + suggestions: null, + }); + return target.runtimeModule; + } +} + +function validateRestrictedImports(path, { validateBlocklistedImports }) { + if (validateBlocklistedImports == null || + validateBlocklistedImports.length === 0) { + return null; + } + const error = new CompilerError(); + const restrictedImports = new Set(validateBlocklistedImports); + path.traverse({ + ImportDeclaration(importDeclPath) { + var _a; + if (restrictedImports.has(importDeclPath.node.source.value)) { + error.push({ + severity: ErrorSeverity.Todo, + reason: 'Bailing out due to blocklisted import', + description: `Import from module ${importDeclPath.node.source.value}`, + loc: (_a = importDeclPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + } + }, + }); + if (error.hasErrors()) { + return error; + } + else { + return null; + } +} +class ProgramContext { + constructor(program, reactRuntimeModule, hookPattern) { + this.knownReferencedNames = new Set(); + this.imports = new Map(); + this.hookPattern = hookPattern; + this.scope = program.scope; + this.reactRuntimeModule = getReactCompilerRuntimeModule(reactRuntimeModule); + } + isHookName(name) { + if (this.hookPattern == null) { + return isHookName$2(name); + } + else { + const match = new RegExp(this.hookPattern).exec(name); + return (match != null && typeof match[1] === 'string' && isHookName$2(match[1])); + } + } + hasReference(name) { + return (this.knownReferencedNames.has(name) || + this.scope.hasBinding(name) || + this.scope.hasGlobal(name) || + this.scope.hasReference(name)); + } + newUid(name) { + let uid; + if (this.isHookName(name)) { + uid = name; + let i = 0; + while (this.hasReference(uid)) { + this.knownReferencedNames.add(uid); + uid = `${name}_${i++}`; + } + } + else if (!this.hasReference(name)) { + uid = name; + } + else { + uid = this.scope.generateUid(name); + } + this.knownReferencedNames.add(uid); + return uid; + } + addMemoCacheImport() { + return this.addImportSpecifier({ + source: this.reactRuntimeModule, + importSpecifierName: 'c', + }, '_c'); + } + addImportSpecifier({ source: module, importSpecifierName: specifier }, nameHint) { + var _a; + const maybeBinding = (_a = this.imports.get(module)) === null || _a === void 0 ? void 0 : _a.get(specifier); + if (maybeBinding != null) { + return Object.assign({}, maybeBinding); + } + const binding = { + kind: 'ImportSpecifier', + name: this.newUid(nameHint !== null && nameHint !== void 0 ? nameHint : specifier), + module, + imported: specifier, + }; + getOrInsertWith(this.imports, module, () => new Map()).set(specifier, Object.assign({}, binding)); + return binding; + } + addNewReference(name) { + this.knownReferencedNames.add(name); + } + assertGlobalBinding(name, localScope) { + var _a, _b; + const scope = localScope !== null && localScope !== void 0 ? localScope : this.scope; + if (!scope.hasReference(name) && !scope.hasBinding(name)) { + return Ok(undefined); + } + const error = new CompilerError(); + error.push({ + severity: ErrorSeverity.Todo, + reason: 'Encountered conflicting global in generated program', + description: `Conflict from local binding ${name}`, + loc: (_b = (_a = scope.getBinding(name)) === null || _a === void 0 ? void 0 : _a.path.node.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + return Err(error); + } +} +function getExistingImports(program) { + const existingImports = new Map(); + program.traverse({ + ImportDeclaration(path) { + if (isNonNamespacedImport(path)) { + existingImports.set(path.node.source.value, path); + } + }, + }); + return existingImports; +} +function addImportsToProgram(path, programContext) { + const existingImports = getExistingImports(path); + const stmts = []; + const sortedModules = [...programContext.imports.entries()].sort(([a], [b]) => a.localeCompare(b)); + for (const [moduleName, importsMap] of sortedModules) { + for (const [specifierName, loweredImport] of importsMap) { + CompilerError.invariant(path.scope.getBinding(loweredImport.name) == null, { + reason: 'Encountered conflicting import specifiers in generated program', + description: `Conflict from import ${loweredImport.module}:(${loweredImport.imported} as ${loweredImport.name}).`, + loc: GeneratedSource, + suggestions: null, + }); + CompilerError.invariant(loweredImport.module === moduleName && + loweredImport.imported === specifierName, { + reason: 'Found inconsistent import specifier. This is an internal bug.', + description: `Expected import ${moduleName}:${specifierName} but found ${loweredImport.module}:${loweredImport.imported}`, + loc: GeneratedSource, + }); + } + const sortedImport = [ + ...importsMap.values(), + ].sort(({ imported: a }, { imported: b }) => a.localeCompare(b)); + const importSpecifiers = sortedImport.map(specifier => { + return libExports$1.importSpecifier(libExports$1.identifier(specifier.name), libExports$1.identifier(specifier.imported)); + }); + const maybeExistingImports = existingImports.get(moduleName); + if (maybeExistingImports != null) { + maybeExistingImports.pushContainer('specifiers', importSpecifiers); + } + else { + stmts.push(libExports$1.importDeclaration(importSpecifiers, libExports$1.stringLiteral(moduleName))); + } + } + path.unshiftContainer('body', stmts); +} +function isNonNamespacedImport(importDeclPath) { + return (importDeclPath + .get('specifiers') + .every(specifier => specifier.isImportSpecifier()) && + importDeclPath.node.importKind !== 'type' && + importDeclPath.node.importKind !== 'typeof'); +} + +zod.z.enum([ + 'all_errors', + 'critical_errors', + 'none', +]); +const CompilerReactTargetSchema = zod.z.union([ + zod.z.literal('17'), + zod.z.literal('18'), + zod.z.literal('19'), + zod.z.object({ + kind: zod.z.literal('donotuse_meta_internal'), + runtimeModule: zod.z.string().default('react'), + }), +]); +zod.z.enum([ + 'infer', + 'syntax', + 'annotation', + 'all', +]); +const defaultOptions = { + compilationMode: 'infer', + panicThreshold: 'none', + environment: parseEnvironmentConfig({}).unwrap(), + logger: null, + gating: null, + noEmit: false, + eslintSuppressionRules: null, + flowSuppressions: true, + ignoreUseNoForget: false, + sources: filename => { + return filename.indexOf('node_modules') === -1; + }, + enableReanimatedCheck: true, + target: '19', +}; +function parsePluginOptions(obj) { + if (obj == null || typeof obj !== 'object') { + return defaultOptions; + } + const parsedOptions = Object.create(null); + for (let [key, value] of Object.entries(obj)) { + if (typeof value === 'string') { + value = value.toLowerCase(); + } + if (isCompilerFlag(key)) { + switch (key) { + case 'environment': { + const environmentResult = parseEnvironmentConfig(value); + if (environmentResult.isErr()) { + CompilerError.throwInvalidConfig({ + reason: 'Error in validating environment config. This is an advanced setting and not meant to be used directly', + description: environmentResult.unwrapErr().toString(), + suggestions: null, + loc: null, + }); + } + parsedOptions[key] = environmentResult.unwrap(); + break; + } + case 'target': { + parsedOptions[key] = parseTargetConfig(value); + break; + } + case 'gating': { + if (value == null) { + parsedOptions[key] = null; + } + else { + parsedOptions[key] = tryParseExternalFunction(value); + } + break; + } + default: { + parsedOptions[key] = value; + } + } + } + } + return Object.assign(Object.assign({}, defaultOptions), parsedOptions); +} +function parseTargetConfig(value) { + const parsed = CompilerReactTargetSchema.safeParse(value); + if (parsed.success) { + return parsed.data; + } + else { + CompilerError.throwInvalidConfig({ + reason: 'Not a valid target', + description: `${zodValidationError.fromZodError(parsed.error)}`, + suggestions: null, + loc: null, + }); + } +} +function isCompilerFlag(s) { + return hasOwnProperty$1(defaultOptions, s); +} + +function hasModule(name) { + if (typeof require === 'undefined') { + return false; + } + try { + return !!require.resolve(name); + } + catch (error) { + if (error.code === 'MODULE_NOT_FOUND' && + error.message.indexOf(name) !== -1) { + return false; + } + throw error; + } +} +function pipelineUsesReanimatedPlugin(plugins) { + if (Array.isArray(plugins)) { + for (const plugin of plugins) { + if (hasOwnProperty$1(plugin, 'key')) { + const key = plugin.key; + if (typeof key === 'string' && + key.indexOf('react-native-reanimated') !== -1) { + return true; + } + } + } + } + return hasModule('react-native-reanimated'); +} +function injectReanimatedFlag(options) { + return Object.assign(Object.assign({}, options), { environment: Object.assign(Object.assign({}, options.environment), { enableCustomTypeDefinitionForReanimated: true }) }); +} + +function throwInvalidReact(options, { logger, filename }) { + const detail = Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidReact }); + logger === null || logger === void 0 ? void 0 : logger.logEvent(filename, { + kind: 'CompileError', + fnLoc: null, + detail, + }); + CompilerError.throw(detail); +} +function assertValidEffectImportReference(numArgs, paths, context) { + var _a; + for (const path of paths) { + const parent = path.parentPath; + if (parent != null && parent.isCallExpression()) { + const args = parent.get('arguments'); + const maybeCalleeLoc = path.node.loc; + const hasInferredEffect = maybeCalleeLoc != null && + context.inferredEffectLocations.has(maybeCalleeLoc); + if (args.length === numArgs && !hasInferredEffect) { + const maybeErrorDiagnostic = matchCompilerDiagnostic(path, context.transformErrors); + throwInvalidReact({ + reason: '[InferEffectDependencies] React Compiler is unable to infer dependencies of this effect. ' + + 'This will break your build! ' + + 'To resolve, either pass your own dependency array or fix reported compiler bailout diagnostics.', + description: maybeErrorDiagnostic + ? `(Bailout reason: ${maybeErrorDiagnostic})` + : null, + loc: (_a = parent.node.loc) !== null && _a !== void 0 ? _a : null, + }, context); + } + } + } +} +function assertValidFireImportReference(paths, context) { + var _a; + if (paths.length > 0) { + const maybeErrorDiagnostic = matchCompilerDiagnostic(paths[0], context.transformErrors); + throwInvalidReact({ + reason: '[Fire] Untransformed reference to compiler-required feature. ' + + 'Either remove this `fire` call or ensure it is successfully transformed by the compiler', + description: maybeErrorDiagnostic + ? `(Bailout reason: ${maybeErrorDiagnostic})` + : null, + loc: (_a = paths[0].node.loc) !== null && _a !== void 0 ? _a : null, + }, context); + } +} +function validateNoUntransformedReferences(path, filename, logger, env, compileResult) { + const moduleLoadChecks = new Map(); + if (env.enableFire) { + for (const module of Environment.knownReactModules) { + const react = getOrInsertWith(moduleLoadChecks, module, () => new Map()); + react.set('fire', assertValidFireImportReference); + } + } + if (env.inferEffectDependencies) { + for (const { function: { source, importSpecifierName }, numRequiredArgs, } of env.inferEffectDependencies) { + const module = getOrInsertWith(moduleLoadChecks, source, () => new Map()); + module.set(importSpecifierName, assertValidEffectImportReference.bind(null, numRequiredArgs)); + } + } + if (moduleLoadChecks.size > 0) { + transformProgram(path, moduleLoadChecks, filename, logger, compileResult); + } +} +function validateImportSpecifier(specifier, importSpecifierChecks, state) { + var _a; + const imported = specifier.get('imported'); + const specifierName = imported.node.type === 'Identifier' + ? imported.node.name + : imported.node.value; + const checkFn = importSpecifierChecks.get(specifierName); + if (checkFn == null) { + return; + } + if (state.shouldInvalidateScopes) { + state.shouldInvalidateScopes = false; + state.program.scope.crawl(); + } + const local = specifier.get('local'); + const binding = local.scope.getBinding(local.node.name); + CompilerError.invariant(binding != null, { + reason: 'Expected binding to be found for import specifier', + loc: (_a = local.node.loc) !== null && _a !== void 0 ? _a : null, + }); + checkFn(binding.referencePaths, state); +} +function validateNamespacedImport(specifier, importSpecifierChecks, state) { + var _a; + if (state.shouldInvalidateScopes) { + state.shouldInvalidateScopes = false; + state.program.scope.crawl(); + } + const local = specifier.get('local'); + const binding = local.scope.getBinding(local.node.name); + const defaultCheckFn = importSpecifierChecks.get(DEFAULT_EXPORT); + CompilerError.invariant(binding != null, { + reason: 'Expected binding to be found for import specifier', + loc: (_a = local.node.loc) !== null && _a !== void 0 ? _a : null, + }); + const filteredReferences = new Map(); + for (const reference of binding.referencePaths) { + if (defaultCheckFn != null) { + getOrInsertWith(filteredReferences, defaultCheckFn, () => []).push(reference); + } + const parent = reference.parentPath; + if (parent != null && + parent.isMemberExpression() && + parent.get('object') === reference) { + if (parent.node.computed || parent.node.property.type !== 'Identifier') { + continue; + } + const checkFn = importSpecifierChecks.get(parent.node.property.name); + if (checkFn != null) { + getOrInsertWith(filteredReferences, checkFn, () => []).push(parent); + } + } + } + for (const [checkFn, references] of filteredReferences) { + checkFn(references, state); + } +} +function transformProgram(path, moduleLoadChecks, filename, logger, compileResult) { + var _a, _b; + const traversalState = { + shouldInvalidateScopes: true, + program: path, + filename, + logger, + transformErrors: (_a = compileResult === null || compileResult === void 0 ? void 0 : compileResult.retryErrors) !== null && _a !== void 0 ? _a : [], + inferredEffectLocations: (_b = compileResult === null || compileResult === void 0 ? void 0 : compileResult.inferredEffectLocations) !== null && _b !== void 0 ? _b : new Set(), + }; + path.traverse({ + ImportDeclaration(path) { + const importSpecifierChecks = moduleLoadChecks.get(path.node.source.value); + if (importSpecifierChecks == null) { + return; + } + const specifiers = path.get('specifiers'); + for (const specifier of specifiers) { + if (specifier.isImportSpecifier()) { + validateImportSpecifier(specifier, importSpecifierChecks, traversalState); + } + else { + validateNamespacedImport(specifier, importSpecifierChecks, traversalState); + } + } + }, + }); +} +function matchCompilerDiagnostic(badReference, transformErrors) { + for (const { fn, error } of transformErrors) { + if (fn.isAncestor(badReference)) { + return error.toString(); + } + } + return null; +} + +const ENABLE_REACT_COMPILER_TIMINGS = process.env['ENABLE_REACT_COMPILER_TIMINGS'] === '1'; +function BabelPluginReactCompiler(_babel) { + return { + name: 'react-forget', + visitor: { + Program: { + enter(prog, pass) { + var _a, _b, _c, _d; + const filename = (_a = pass.filename) !== null && _a !== void 0 ? _a : 'unknown'; + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + performance.mark(`${filename}:start`, { + detail: 'BabelPlugin:Program:start', + }); + } + let opts = parsePluginOptions(pass.opts); + const isDev = (true === true) ; + if (opts.enableReanimatedCheck === true && + pipelineUsesReanimatedPlugin(pass.file.opts.plugins)) { + opts = injectReanimatedFlag(opts); + } + if (opts.environment.enableResetCacheOnSourceFileChanges !== false && + isDev) { + opts = Object.assign(Object.assign({}, opts), { environment: Object.assign(Object.assign({}, opts.environment), { enableResetCacheOnSourceFileChanges: true }) }); + } + const result = compileProgram(prog, { + opts, + filename: (_b = pass.filename) !== null && _b !== void 0 ? _b : null, + comments: (_c = pass.file.ast.comments) !== null && _c !== void 0 ? _c : [], + code: pass.file.code, + }); + validateNoUntransformedReferences(prog, (_d = pass.filename) !== null && _d !== void 0 ? _d : null, opts.logger, opts.environment, result); + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + performance.mark(`${filename}:end`, { + detail: 'BabelPlugin:Program:end', + }); + } + }, + exit(_, pass) { + var _a; + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + const filename = (_a = pass.filename) !== null && _a !== void 0 ? _a : 'unknown'; + const measurement = performance.measure(filename, { + start: `${filename}:start`, + end: `${filename}:end`, + detail: 'BabelPlugin:Program', + }); + if ('logger' in pass.opts && pass.opts.logger != null) { + const logger = pass.opts.logger; + logger.logEvent(filename, { + kind: 'Timing', + measurement, + }); + } + } + }, + }, + }, + }; +} + +function assertExhaustive(_, errorMsg) { + throw new Error(errorMsg); +} +const DEFAULT_REPORTABLE_LEVELS = new Set([ + ErrorSeverity.InvalidReact, + ErrorSeverity.InvalidJS, +]); +let reportableLevels = DEFAULT_REPORTABLE_LEVELS; +function isReportableDiagnostic(detail) { + return (reportableLevels.has(detail.severity) && + detail.loc != null && + typeof detail.loc !== 'symbol'); +} +function makeSuggestions(detail) { + const suggest = []; + if (Array.isArray(detail.suggestions)) { + for (const suggestion of detail.suggestions) { + switch (suggestion.op) { + case CompilerSuggestionOperation.InsertBefore: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.insertTextBeforeRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.InsertAfter: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.insertTextAfterRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.Replace: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.replaceTextRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.Remove: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.removeRange(suggestion.range); + }, + }); + break; + default: + assertExhaustive(suggestion, 'Unhandled suggestion operation'); + } + } + } + return suggest; +} +const COMPILER_OPTIONS = { + noEmit: true, + panicThreshold: 'none', + flowSuppressions: false, + environment: validateEnvironmentConfig({ + validateRefAccessDuringRender: false, + }), +}; +const rule$1 = { + meta: { + type: 'problem', + docs: { + description: 'Surfaces diagnostics from React Forget', + recommended: true, + }, + fixable: 'code', + hasSuggestions: true, + schema: [{ type: 'object', additionalProperties: true }], + }, + create(context) { + var _a, _b, _c, _d, _e; + const sourceCode = (_a = context.sourceCode) !== null && _a !== void 0 ? _a : context.getSourceCode(); + const filename = (_b = context.filename) !== null && _b !== void 0 ? _b : context.getFilename(); + const userOpts = (_c = context.options[0]) !== null && _c !== void 0 ? _c : {}; + if (userOpts.reportableLevels != null && + userOpts.reportableLevels instanceof Set) { + reportableLevels = userOpts.reportableLevels; + } + else { + reportableLevels = DEFAULT_REPORTABLE_LEVELS; + } + let __unstable_donotuse_reportAllBailouts = false; + if (userOpts.__unstable_donotuse_reportAllBailouts != null && + typeof userOpts.__unstable_donotuse_reportAllBailouts === 'boolean') { + __unstable_donotuse_reportAllBailouts = + userOpts.__unstable_donotuse_reportAllBailouts; + } + let shouldReportUnusedOptOutDirective = true; + const options = parsePluginOptions(Object.assign(Object.assign(Object.assign({}, COMPILER_OPTIONS), userOpts), { environment: Object.assign(Object.assign({}, COMPILER_OPTIONS.environment), userOpts.environment) })); + const userLogger = options.logger; + options.logger = { + logEvent: (eventFilename, event) => { + var _a, _b; + userLogger === null || userLogger === void 0 ? void 0 : userLogger.logEvent(eventFilename, event); + if (event.kind === 'CompileError') { + shouldReportUnusedOptOutDirective = false; + const detail = event.detail; + const suggest = makeSuggestions(detail); + if (__unstable_donotuse_reportAllBailouts && event.fnLoc != null) { + const locStr = detail.loc != null && typeof detail.loc !== 'symbol' + ? ` (@:${detail.loc.start.line}:${detail.loc.start.column})` + : ''; + let endLoc; + if (event.fnLoc.end.line === event.fnLoc.start.line) { + endLoc = event.fnLoc.end; + } + else { + endLoc = { + line: event.fnLoc.start.line, + column: (_b = (_a = sourceCode.text.split(/\r?\n|\r|\n/g)[event.fnLoc.start.line - 1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, + }; + } + const firstLineLoc = { + start: event.fnLoc.start, + end: endLoc, + }; + context.report({ + message: `[ReactCompilerBailout] ${detail.reason}${locStr}`, + loc: firstLineLoc, + suggest, + }); + } + if (!isReportableDiagnostic(detail)) { + return; + } + if (hasFlowSuppression(detail.loc, 'react-rule-hook') || + hasFlowSuppression(detail.loc, 'react-rule-unsafe-ref')) { + return; + } + const loc = detail.loc == null || typeof detail.loc === 'symbol' + ? event.fnLoc + : detail.loc; + if (loc != null) { + context.report({ + message: detail.reason, + loc, + suggest, + }); + } + } + }, + }; + try { + options.environment = validateEnvironmentConfig((_d = options.environment) !== null && _d !== void 0 ? _d : {}); + } + catch (err) { + (_e = options.logger) === null || _e === void 0 ? void 0 : _e.logEvent('', err); + } + function hasFlowSuppression(nodeLoc, suppression) { + const comments = sourceCode.getAllComments(); + const flowSuppressionRegex = new RegExp('\\$FlowFixMe\\[' + suppression + '\\]'); + for (const commentNode of comments) { + if (flowSuppressionRegex.test(commentNode.value) && + commentNode.loc.end.line === nodeLoc.start.line - 1) { + return true; + } + } + return false; + } + let babelAST; + if (filename.endsWith('.tsx') || filename.endsWith('.ts')) { + try { + const { parse: babelParse } = require('@babel/parser'); + babelAST = babelParse(sourceCode.text, { + filename, + sourceType: 'unambiguous', + plugins: ['typescript', 'jsx'], + }); + } + catch (_f) { + } + } + else { + try { + babelAST = HermesParser.parse(sourceCode.text, { + babel: true, + enableExperimentalComponentSyntax: true, + sourceFilename: filename, + sourceType: 'module', + }); + } + catch (_g) { + } + } + if (babelAST != null) { + try { + core$1.transformFromAstSync(babelAST, sourceCode.text, { + filename, + highlightCode: false, + retainLines: true, + plugins: [ + [PluginProposalPrivateMethods.default, { loose: true }], + [BabelPluginReactCompiler, options], + ], + sourceType: 'module', + configFile: false, + babelrc: false, + }); + } + catch (err) { + } + } + function reportUnusedOptOutDirective(stmt) { + if (stmt.type === 'ExpressionStatement' && + stmt.expression.type === 'Literal' && + typeof stmt.expression.value === 'string' && + OPT_OUT_DIRECTIVES.has(stmt.expression.value) && + stmt.loc != null) { + context.report({ + message: `Unused '${stmt.expression.value}' directive`, + loc: stmt.loc, + suggest: [ + { + desc: 'Remove the directive', + fix(fixer) { + return fixer.remove(stmt); + }, + }, + ], + }); + } + } + if (shouldReportUnusedOptOutDirective) { + return { + FunctionDeclaration(fnDecl) { + for (const stmt of fnDecl.body.body) { + reportUnusedOptOutDirective(stmt); + } + }, + ArrowFunctionExpression(fnExpr) { + if (fnExpr.body.type === 'BlockStatement') { + for (const stmt of fnExpr.body.body) { + reportUnusedOptOutDirective(stmt); + } + } + }, + FunctionExpression(fnExpr) { + for (const stmt of fnExpr.body.body) { + reportUnusedOptOutDirective(stmt); + } + }, + }; + } + else { + return {}; + } + }, +}; + +var assert_1; +var hasRequiredAssert; +function requireAssert() { + if (hasRequiredAssert) return assert_1; + hasRequiredAssert = 1; + function assert(cond) { + if (!cond) { + throw new Error('Assertion violated.'); + } + } + assert_1 = assert; + return assert_1; +} + +var codePathSegment; +var hasRequiredCodePathSegment; +function requireCodePathSegment() { + if (hasRequiredCodePathSegment) return codePathSegment; + hasRequiredCodePathSegment = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Checks whether or not a given segment is reachable. + * @param {CodePathSegment} segment A segment to check. + * @returns {boolean} `true` if the segment is reachable. + */ + function isReachable(segment) { + return segment.reachable; + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A code path segment. + */ + class CodePathSegment { + /** + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * This array includes unreachable segments. + * @param {boolean} reachable A flag which shows this is reachable. + */ + constructor(id, allPrevSegments, reachable) { + /** + * The identifier of this code path. + * Rules use it to store additional information of each rule. + * @type {string} + */ + this.id = id; + + /** + * An array of the next segments. + * @type {CodePathSegment[]} + */ + this.nextSegments = []; + + /** + * An array of the previous segments. + * @type {CodePathSegment[]} + */ + this.prevSegments = allPrevSegments.filter(isReachable); + + /** + * An array of the next segments. + * This array includes unreachable segments. + * @type {CodePathSegment[]} + */ + this.allNextSegments = []; + + /** + * An array of the previous segments. + * This array includes unreachable segments. + * @type {CodePathSegment[]} + */ + this.allPrevSegments = allPrevSegments; + + /** + * A flag which shows this is reachable. + * @type {boolean} + */ + this.reachable = reachable; + + // Internal data. + Object.defineProperty(this, 'internal', { + value: { + used: false, + loopedPrevSegments: [] + } + }); + } + + /** + * Checks a given previous segment is coming from the end of a loop. + * @param {CodePathSegment} segment A previous segment to check. + * @returns {boolean} `true` if the segment is coming from the end of a loop. + */ + isLoopedPrevSegment(segment) { + return this.internal.loopedPrevSegments.includes(segment); + } + + /** + * Creates the root segment. + * @param {string} id An identifier. + * @returns {CodePathSegment} The created segment. + */ + static newRoot(id) { + return new CodePathSegment(id, [], true); + } + + /** + * Creates a segment that follows given segments. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newNext(id, allPrevSegments) { + return new CodePathSegment(id, CodePathSegment.flattenUnusedSegments(allPrevSegments), allPrevSegments.some(isReachable)); + } + + /** + * Creates an unreachable segment that follows given segments. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newUnreachable(id, allPrevSegments) { + var segment = new CodePathSegment(id, CodePathSegment.flattenUnusedSegments(allPrevSegments), false); + + /* + * In `if (a) return a; foo();` case, the unreachable segment preceded by + * the return statement is not used but must not be remove. + */ + CodePathSegment.markUsed(segment); + return segment; + } + + /** + * Creates a segment that follows given segments. + * This factory method does not connect with `allPrevSegments`. + * But this inherits `reachable` flag. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newDisconnected(id, allPrevSegments) { + return new CodePathSegment(id, [], allPrevSegments.some(isReachable)); + } + + /** + * Makes a given segment being used. + * + * And this function registers the segment into the previous segments as a next. + * @param {CodePathSegment} segment A segment to mark. + * @returns {void} + */ + static markUsed(segment) { + if (segment.internal.used) { + return; + } + segment.internal.used = true; + var i; + if (segment.reachable) { + for (i = 0; i < segment.allPrevSegments.length; ++i) { + var prevSegment = segment.allPrevSegments[i]; + prevSegment.allNextSegments.push(segment); + prevSegment.nextSegments.push(segment); + } + } else { + for (i = 0; i < segment.allPrevSegments.length; ++i) { + segment.allPrevSegments[i].allNextSegments.push(segment); + } + } + } + + /** + * Marks a previous segment as looped. + * @param {CodePathSegment} segment A segment. + * @param {CodePathSegment} prevSegment A previous segment to mark. + * @returns {void} + */ + static markPrevSegmentAsLooped(segment, prevSegment) { + segment.internal.loopedPrevSegments.push(prevSegment); + } + + /** + * Replaces unused segments with the previous segments of each unused segment. + * @param {CodePathSegment[]} segments An array of segments to replace. + * @returns {CodePathSegment[]} The replaced array. + */ + static flattenUnusedSegments(segments) { + var done = Object.create(null); + var retv = []; + for (var i = 0; i < segments.length; ++i) { + var segment = segments[i]; + + // Ignores duplicated. + if (done[segment.id]) { + continue; + } + + // Use previous segments if unused. + if (!segment.internal.used) { + for (var j = 0; j < segment.allPrevSegments.length; ++j) { + var prevSegment = segment.allPrevSegments[j]; + if (!done[prevSegment.id]) { + done[prevSegment.id] = true; + retv.push(prevSegment); + } + } + } else { + done[segment.id] = true; + retv.push(segment); + } + } + return retv; + } + } + codePathSegment = CodePathSegment; + return codePathSegment; +} + +var forkContext; +var hasRequiredForkContext; +function requireForkContext() { + if (hasRequiredForkContext) return forkContext; + hasRequiredForkContext = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + var assert = requireAssert(); + // eslint-disable-next-line + var CodePathSegment = requireCodePathSegment(); + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Gets whether or not a given segment is reachable. + * @param {CodePathSegment} segment A segment to get. + * @returns {boolean} `true` if the segment is reachable. + */ + function isReachable(segment) { + return segment.reachable; + } + + /** + * Creates new segments from the specific range of `context.segmentsList`. + * + * When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and + * `end` is `-1`, this creates `[g, h]`. This `g` is from `a`, `c`, and `e`. + * This `h` is from `b`, `d`, and `f`. + * @param {ForkContext} context An instance. + * @param {number} begin The first index of the previous segments. + * @param {number} end The last index of the previous segments. + * @param {Function} create A factory function of new segments. + * @returns {CodePathSegment[]} New segments. + */ + function makeSegments(context, begin, end, create) { + var list = context.segmentsList; + var normalizedBegin = begin >= 0 ? begin : list.length + begin; + var normalizedEnd = end >= 0 ? end : list.length + end; + var segments = []; + for (var i = 0; i < context.count; ++i) { + var allPrevSegments = []; + for (var j = normalizedBegin; j <= normalizedEnd; ++j) { + allPrevSegments.push(list[j][i]); + } + segments.push(create(context.idGenerator.next(), allPrevSegments)); + } + return segments; + } + + /** + * `segments` becomes doubly in a `finally` block. Then if a code path exits by a + * control statement (such as `break`, `continue`) from the `finally` block, the + * destination's segments may be half of the source segments. In that case, this + * merges segments. + * @param {ForkContext} context An instance. + * @param {CodePathSegment[]} segments Segments to merge. + * @returns {CodePathSegment[]} The merged segments. + */ + function mergeExtraSegments(context, segments) { + var currentSegments = segments; + while (currentSegments.length > context.count) { + var merged = []; + for (var i = 0, length = currentSegments.length / 2 | 0; i < length; ++i) { + merged.push(CodePathSegment.newNext(context.idGenerator.next(), [currentSegments[i], currentSegments[i + length]])); + } + currentSegments = merged; + } + return currentSegments; + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A class to manage forking. + */ + class ForkContext { + /** + * @param {IdGenerator} idGenerator An identifier generator for segments. + * @param {ForkContext|null} upper An upper fork context. + * @param {number} count A number of parallel segments. + */ + constructor(idGenerator, upper, count) { + this.idGenerator = idGenerator; + this.upper = upper; + this.count = count; + this.segmentsList = []; + } + + /** + * The head segments. + * @type {CodePathSegment[]} + */ + get head() { + var list = this.segmentsList; + return list.length === 0 ? [] : list[list.length - 1]; + } + + /** + * A flag which shows empty. + * @type {boolean} + */ + get empty() { + return this.segmentsList.length === 0; + } + + /** + * A flag which shows reachable. + * @type {boolean} + */ + get reachable() { + var segments = this.head; + return segments.length > 0 && segments.some(isReachable); + } + + /** + * Creates new segments from this context. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeNext(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newNext); + } + + /** + * Creates new segments from this context. + * The new segments is always unreachable. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeUnreachable(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newUnreachable); + } + + /** + * Creates new segments from this context. + * The new segments don't have connections for previous segments. + * But these inherit the reachable flag from this context. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeDisconnected(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newDisconnected); + } + + /** + * Adds segments into this context. + * The added segments become the head. + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + add(segments) { + assert(segments.length >= this.count, segments.length + " >= " + this.count); + this.segmentsList.push(mergeExtraSegments(this, segments)); + } + + /** + * Replaces the head segments with given segments. + * The current head segments are removed. + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + replaceHead(segments) { + assert(segments.length >= this.count, segments.length + " >= " + this.count); + this.segmentsList.splice(-1, 1, mergeExtraSegments(this, segments)); + } + + /** + * Adds all segments of a given fork context into this context. + * @param {ForkContext} context A fork context to add. + * @returns {void} + */ + addAll(context) { + assert(context.count === this.count); + var source = context.segmentsList; + for (var i = 0; i < source.length; ++i) { + this.segmentsList.push(source[i]); + } + } + + /** + * Clears all segments in this context. + * @returns {void} + */ + clear() { + this.segmentsList = []; + } + + /** + * Creates the root fork context. + * @param {IdGenerator} idGenerator An identifier generator for segments. + * @returns {ForkContext} New fork context. + */ + static newRoot(idGenerator) { + var context = new ForkContext(idGenerator, null, 1); + context.add([CodePathSegment.newRoot(idGenerator.next())]); + return context; + } + + /** + * Creates an empty fork context preceded by a given context. + * @param {ForkContext} parentContext The parent fork context. + * @param {boolean} forkLeavingPath A flag which shows inside of `finally` block. + * @returns {ForkContext} New fork context. + */ + static newEmpty(parentContext, forkLeavingPath) { + return new ForkContext(parentContext.idGenerator, parentContext, (forkLeavingPath ? 2 : 1) * parentContext.count); + } + } + forkContext = ForkContext; + return forkContext; +} + +var codePathState; +var hasRequiredCodePathState; +function requireCodePathState() { + if (hasRequiredCodePathState) return codePathState; + hasRequiredCodePathState = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + var CodePathSegment = requireCodePathSegment(); + // eslint-disable-next-line + var ForkContext = requireForkContext(); + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Adds given segments into the `dest` array. + * If the `others` array does not includes the given segments, adds to the `all` + * array as well. + * + * This adds only reachable and used segments. + * @param {CodePathSegment[]} dest A destination array (`returnedSegments` or `thrownSegments`). + * @param {CodePathSegment[]} others Another destination array (`returnedSegments` or `thrownSegments`). + * @param {CodePathSegment[]} all The unified destination array (`finalSegments`). + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + function addToReturnedOrThrown(dest, others, all, segments) { + for (var i = 0; i < segments.length; ++i) { + var segment = segments[i]; + dest.push(segment); + if (!others.includes(segment)) { + all.push(segment); + } + } + } + + /** + * Gets a loop-context for a `continue` statement. + * @param {CodePathState} state A state to get. + * @param {string} label The label of a `continue` statement. + * @returns {LoopContext} A loop-context for a `continue` statement. + */ + function getContinueContext(state, label) { + if (!label) { + return state.loopContext; + } + var context = state.loopContext; + while (context) { + if (context.label === label) { + return context; + } + context = context.upper; + } + + /* c8 ignore next */ + return null; + } + + /** + * Gets a context for a `break` statement. + * @param {CodePathState} state A state to get. + * @param {string} label The label of a `break` statement. + * @returns {LoopContext|SwitchContext} A context for a `break` statement. + */ + function getBreakContext(state, label) { + var context = state.breakContext; + while (context) { + if (label ? context.label === label : context.breakable) { + return context; + } + context = context.upper; + } + + /* c8 ignore next */ + return null; + } + + /** + * Gets a context for a `return` statement. + * @param {CodePathState} state A state to get. + * @returns {TryContext|CodePathState} A context for a `return` statement. + */ + function getReturnContext(state) { + var context = state.tryContext; + while (context) { + if (context.hasFinalizer && context.position !== 'finally') { + return context; + } + context = context.upper; + } + return state; + } + + /** + * Gets a context for a `throw` statement. + * @param {CodePathState} state A state to get. + * @returns {TryContext|CodePathState} A context for a `throw` statement. + */ + function getThrowContext(state) { + var context = state.tryContext; + while (context) { + if (context.position === 'try' || context.hasFinalizer && context.position === 'catch') { + return context; + } + context = context.upper; + } + return state; + } + + /** + * Removes a given element from a given array. + * @param {any[]} xs An array to remove the specific element. + * @param {any} x An element to be removed. + * @returns {void} + */ + function remove(xs, x) { + xs.splice(xs.indexOf(x), 1); + } + + /** + * Disconnect given segments. + * + * This is used in a process for switch statements. + * If there is the "default" chunk before other cases, the order is different + * between node's and running's. + * @param {CodePathSegment[]} prevSegments Forward segments to disconnect. + * @param {CodePathSegment[]} nextSegments Backward segments to disconnect. + * @returns {void} + */ + function removeConnection(prevSegments, nextSegments) { + for (var i = 0; i < prevSegments.length; ++i) { + var prevSegment = prevSegments[i]; + var nextSegment = nextSegments[i]; + remove(prevSegment.nextSegments, nextSegment); + remove(prevSegment.allNextSegments, nextSegment); + remove(nextSegment.prevSegments, prevSegment); + remove(nextSegment.allPrevSegments, prevSegment); + } + } + + /** + * Creates looping path. + * @param {CodePathState} state The instance. + * @param {CodePathSegment[]} unflattenedFromSegments Segments which are source. + * @param {CodePathSegment[]} unflattenedToSegments Segments which are destination. + * @returns {void} + */ + function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) { + var fromSegments = CodePathSegment.flattenUnusedSegments(unflattenedFromSegments); + var toSegments = CodePathSegment.flattenUnusedSegments(unflattenedToSegments); + var end = Math.min(fromSegments.length, toSegments.length); + for (var i = 0; i < end; ++i) { + var fromSegment = fromSegments[i]; + var toSegment = toSegments[i]; + if (toSegment.reachable) { + fromSegment.nextSegments.push(toSegment); + } + if (fromSegment.reachable) { + toSegment.prevSegments.push(fromSegment); + } + fromSegment.allNextSegments.push(toSegment); + toSegment.allPrevSegments.push(fromSegment); + if (toSegment.allPrevSegments.length >= 2) { + CodePathSegment.markPrevSegmentAsLooped(toSegment, fromSegment); + } + state.notifyLooped(fromSegment, toSegment); + } + } + + /** + * Finalizes segments of `test` chunk of a ForStatement. + * + * - Adds `false` paths to paths which are leaving from the loop. + * - Sets `true` paths to paths which go to the body. + * @param {LoopContext} context A loop context to modify. + * @param {ChoiceContext} choiceContext A choice context of this loop. + * @param {CodePathSegment[]} head The current head paths. + * @returns {void} + */ + function finalizeTestSegmentsOfFor(context, choiceContext, head) { + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(head); + choiceContext.falseForkContext.add(head); + choiceContext.qqForkContext.add(head); + } + if (context.test !== true) { + context.brokenForkContext.addAll(choiceContext.falseForkContext); + } + context.endOfTestSegments = choiceContext.trueForkContext.makeNext(0, -1); + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A class which manages state to analyze code paths. + */ + class CodePathState { + /** + * @param {IdGenerator} idGenerator An id generator to generate id for code + * path segments. + * @param {Function} onLooped A callback function to notify looping. + */ + constructor(idGenerator, onLooped) { + this.idGenerator = idGenerator; + this.notifyLooped = onLooped; + this.forkContext = ForkContext.newRoot(idGenerator); + this.choiceContext = null; + this.switchContext = null; + this.tryContext = null; + this.loopContext = null; + this.breakContext = null; + this.chainContext = null; + this.currentSegments = []; + this.initialSegment = this.forkContext.head[0]; + + // returnedSegments and thrownSegments push elements into finalSegments also. + var final = this.finalSegments = []; + var returned = this.returnedForkContext = []; + var thrown = this.thrownForkContext = []; + returned.add = addToReturnedOrThrown.bind(null, returned, thrown, final); + thrown.add = addToReturnedOrThrown.bind(null, thrown, returned, final); + } + + /** + * The head segments. + * @type {CodePathSegment[]} + */ + get headSegments() { + return this.forkContext.head; + } + + /** + * The parent forking context. + * This is used for the root of new forks. + * @type {ForkContext} + */ + get parentForkContext() { + var current = this.forkContext; + return current && current.upper; + } + + /** + * Creates and stacks new forking context. + * @param {boolean} forkLeavingPath A flag which shows being in a + * "finally" block. + * @returns {ForkContext} The created context. + */ + pushForkContext(forkLeavingPath) { + this.forkContext = ForkContext.newEmpty(this.forkContext, forkLeavingPath); + return this.forkContext; + } + + /** + * Pops and merges the last forking context. + * @returns {ForkContext} The last context. + */ + popForkContext() { + var lastContext = this.forkContext; + this.forkContext = lastContext.upper; + this.forkContext.replaceHead(lastContext.makeNext(0, -1)); + return lastContext; + } + + /** + * Creates a new path. + * @returns {void} + */ + forkPath() { + this.forkContext.add(this.parentForkContext.makeNext(-1, -1)); + } + + /** + * Creates a bypass path. + * This is used for such as IfStatement which does not have "else" chunk. + * @returns {void} + */ + forkBypassPath() { + this.forkContext.add(this.parentForkContext.head); + } + + //-------------------------------------------------------------------------- + // ConditionalExpression, LogicalExpression, IfStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context for ConditionalExpression, LogicalExpression, AssignmentExpression (logical assignments only), + * IfStatement, WhileStatement, DoWhileStatement, or ForStatement. + * + * LogicalExpressions have cases that it goes different paths between the + * `true` case and the `false` case. + * + * For Example: + * + * if (a || b) { + * foo(); + * } else { + * bar(); + * } + * + * In this case, `b` is evaluated always in the code path of the `else` + * block, but it's not so in the code path of the `if` block. + * So there are 3 paths. + * + * a -> foo(); + * a -> b -> foo(); + * a -> b -> bar(); + * @param {string} kind A kind string. + * If the new context is LogicalExpression's or AssignmentExpression's, this is `"&&"` or `"||"` or `"??"`. + * If it's IfStatement's or ConditionalExpression's, this is `"test"`. + * Otherwise, this is `"loop"`. + * @param {boolean} isForkingAsResult A flag that shows that goes different + * paths between `true` and `false`. + * @returns {void} + */ + pushChoiceContext(kind, isForkingAsResult) { + this.choiceContext = { + upper: this.choiceContext, + kind: kind, + isForkingAsResult: isForkingAsResult, + trueForkContext: ForkContext.newEmpty(this.forkContext), + falseForkContext: ForkContext.newEmpty(this.forkContext), + qqForkContext: ForkContext.newEmpty(this.forkContext), + processed: false + }; + } + + /** + * Pops the last choice context and finalizes it. + * @throws {Error} (Unreachable.) + * @returns {ChoiceContext} The popped context. + */ + popChoiceContext() { + var context = this.choiceContext; + this.choiceContext = context.upper; + var forkContext = this.forkContext; + var headSegments = forkContext.head; + switch (context.kind) { + case '&&': + case '||': + case '??': + /* + * If any result were not transferred from child contexts, + * this sets the head segments to both cases. + * The head segments are the path of the right-hand operand. + */ + if (!context.processed) { + context.trueForkContext.add(headSegments); + context.falseForkContext.add(headSegments); + context.qqForkContext.add(headSegments); + } + + /* + * Transfers results to upper context if this context is in + * test chunk. + */ + if (context.isForkingAsResult) { + var parentContext = this.choiceContext; + parentContext.trueForkContext.addAll(context.trueForkContext); + parentContext.falseForkContext.addAll(context.falseForkContext); + parentContext.qqForkContext.addAll(context.qqForkContext); + parentContext.processed = true; + return context; + } + break; + case 'test': + if (!context.processed) { + /* + * The head segments are the path of the `if` block here. + * Updates the `true` path with the end of the `if` block. + */ + context.trueForkContext.clear(); + context.trueForkContext.add(headSegments); + } else { + /* + * The head segments are the path of the `else` block here. + * Updates the `false` path with the end of the `else` + * block. + */ + context.falseForkContext.clear(); + context.falseForkContext.add(headSegments); + } + break; + case 'loop': + /* + * Loops are addressed in popLoopContext(). + * This is called from popLoopContext(). + */ + return context; + + /* c8 ignore next */ + default: + throw new Error('unreachable'); + } + + // Merges all paths. + var prevForkContext = context.trueForkContext; + prevForkContext.addAll(context.falseForkContext); + forkContext.replaceHead(prevForkContext.makeNext(0, -1)); + return context; + } + + /** + * Makes a code path segment of the right-hand operand of a logical + * expression. + * @throws {Error} (Unreachable.) + * @returns {void} + */ + makeLogicalRight() { + var context = this.choiceContext; + var forkContext = this.forkContext; + if (context.processed) { + /* + * This got segments already from the child choice context. + * Creates the next path from own true/false fork context. + */ + var prevForkContext; + switch (context.kind) { + case '&&': + // if true then go to the right-hand side. + prevForkContext = context.trueForkContext; + break; + case '||': + // if false then go to the right-hand side. + prevForkContext = context.falseForkContext; + break; + case '??': + // Both true/false can short-circuit, so needs the third path to go to the right-hand side. That's qqForkContext. + prevForkContext = context.qqForkContext; + break; + default: + throw new Error('unreachable'); + } + forkContext.replaceHead(prevForkContext.makeNext(0, -1)); + prevForkContext.clear(); + context.processed = false; + } else { + /* + * This did not get segments from the child choice context. + * So addresses the head segments. + * The head segments are the path of the left-hand operand. + */ + switch (context.kind) { + case '&&': + // the false path can short-circuit. + context.falseForkContext.add(forkContext.head); + break; + case '||': + // the true path can short-circuit. + context.trueForkContext.add(forkContext.head); + break; + case '??': + // both can short-circuit. + context.trueForkContext.add(forkContext.head); + context.falseForkContext.add(forkContext.head); + break; + default: + throw new Error('unreachable'); + } + forkContext.replaceHead(forkContext.makeNext(-1, -1)); + } + } + + /** + * Makes a code path segment of the `if` block. + * @returns {void} + */ + makeIfConsequent() { + var context = this.choiceContext; + var forkContext = this.forkContext; + + /* + * If any result were not transferred from child contexts, + * this sets the head segments to both cases. + * The head segments are the path of the test expression. + */ + if (!context.processed) { + context.trueForkContext.add(forkContext.head); + context.falseForkContext.add(forkContext.head); + context.qqForkContext.add(forkContext.head); + } + context.processed = false; + + // Creates new path from the `true` case. + forkContext.replaceHead(context.trueForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment of the `else` block. + * @returns {void} + */ + makeIfAlternate() { + var context = this.choiceContext; + var forkContext = this.forkContext; + + /* + * The head segments are the path of the `if` block. + * Updates the `true` path with the end of the `if` block. + */ + context.trueForkContext.clear(); + context.trueForkContext.add(forkContext.head); + context.processed = true; + + // Creates new path from the `false` case. + forkContext.replaceHead(context.falseForkContext.makeNext(0, -1)); + } + + //-------------------------------------------------------------------------- + // ChainExpression + //-------------------------------------------------------------------------- + + /** + * Push a new `ChainExpression` context to the stack. + * This method is called on entering to each `ChainExpression` node. + * This context is used to count forking in the optional chain then merge them on the exiting from the `ChainExpression` node. + * @returns {void} + */ + pushChainContext() { + this.chainContext = { + upper: this.chainContext, + countChoiceContexts: 0 + }; + } + + /** + * Pop a `ChainExpression` context from the stack. + * This method is called on exiting from each `ChainExpression` node. + * This merges all forks of the last optional chaining. + * @returns {void} + */ + popChainContext() { + var context = this.chainContext; + this.chainContext = context.upper; + + // pop all choice contexts of this. + for (var i = context.countChoiceContexts; i > 0; --i) { + this.popChoiceContext(); + } + } + + /** + * Create a choice context for optional access. + * This method is called on entering to each `(Call|Member)Expression[optional=true]` node. + * This creates a choice context as similar to `LogicalExpression[operator="??"]` node. + * @returns {void} + */ + makeOptionalNode() { + if (this.chainContext) { + this.chainContext.countChoiceContexts += 1; + this.pushChoiceContext('??', false); + } + } + + /** + * Create a fork. + * This method is called on entering to the `arguments|property` property of each `(Call|Member)Expression` node. + * @returns {void} + */ + makeOptionalRight() { + if (this.chainContext) { + this.makeLogicalRight(); + } + } + + //-------------------------------------------------------------------------- + // SwitchStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context object of SwitchStatement and stacks it. + * @param {boolean} hasCase `true` if the switch statement has one or more + * case parts. + * @param {string|null} label The label text. + * @returns {void} + */ + pushSwitchContext(hasCase, label) { + this.switchContext = { + upper: this.switchContext, + hasCase: hasCase, + defaultSegments: null, + defaultBodySegments: null, + foundDefault: false, + lastIsDefault: false, + countForks: 0 + }; + this.pushBreakContext(true, label); + } + + /** + * Pops the last context of SwitchStatement and finalizes it. + * + * - Disposes all forking stack for `case` and `default`. + * - Creates the next code path segment from `context.brokenForkContext`. + * - If the last `SwitchCase` node is not a `default` part, creates a path + * to the `default` body. + * @returns {void} + */ + popSwitchContext() { + var context = this.switchContext; + this.switchContext = context.upper; + var forkContext = this.forkContext; + var brokenForkContext = this.popBreakContext().brokenForkContext; + if (context.countForks === 0) { + /* + * When there is only one `default` chunk and there is one or more + * `break` statements, even if forks are nothing, it needs to merge + * those. + */ + if (!brokenForkContext.empty) { + brokenForkContext.add(forkContext.makeNext(-1, -1)); + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + return; + } + var lastSegments = forkContext.head; + this.forkBypassPath(); + var lastCaseSegments = forkContext.head; + + /* + * `brokenForkContext` is used to make the next segment. + * It must add the last segment into `brokenForkContext`. + */ + brokenForkContext.add(lastSegments); + + /* + * A path which is failed in all case test should be connected to path + * of `default` chunk. + */ + if (!context.lastIsDefault) { + if (context.defaultBodySegments) { + /* + * Remove a link from `default` label to its chunk. + * It's false route. + */ + removeConnection(context.defaultSegments, context.defaultBodySegments); + makeLooped(this, lastCaseSegments, context.defaultBodySegments); + } else { + /* + * It handles the last case body as broken if `default` chunk + * does not exist. + */ + brokenForkContext.add(lastCaseSegments); + } + } + + // Pops the segment context stack until the entry segment. + for (var i = 0; i < context.countForks; ++i) { + this.forkContext = this.forkContext.upper; + } + + /* + * Creates a path from all brokenForkContext paths. + * This is a path after switch statement. + */ + this.forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment for a `SwitchCase` node. + * @param {boolean} isEmpty `true` if the body is empty. + * @param {boolean} isDefault `true` if the body is the default case. + * @returns {void} + */ + makeSwitchCaseBody(isEmpty, isDefault) { + var context = this.switchContext; + if (!context.hasCase) { + return; + } + + /* + * Merge forks. + * The parent fork context has two segments. + * Those are from the current case and the body of the previous case. + */ + var parentForkContext = this.forkContext; + var forkContext = this.pushForkContext(); + forkContext.add(parentForkContext.makeNext(0, -1)); + + /* + * Save `default` chunk info. + * If the `default` label is not at the last, we must make a path from + * the last `case` to the `default` chunk. + */ + if (isDefault) { + context.defaultSegments = parentForkContext.head; + if (isEmpty) { + context.foundDefault = true; + } else { + context.defaultBodySegments = forkContext.head; + } + } else { + if (!isEmpty && context.foundDefault) { + context.foundDefault = false; + context.defaultBodySegments = forkContext.head; + } + } + context.lastIsDefault = isDefault; + context.countForks += 1; + } + + //-------------------------------------------------------------------------- + // TryStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context object of TryStatement and stacks it. + * @param {boolean} hasFinalizer `true` if the try statement has a + * `finally` block. + * @returns {void} + */ + pushTryContext(hasFinalizer) { + this.tryContext = { + upper: this.tryContext, + position: 'try', + hasFinalizer: hasFinalizer, + returnedForkContext: hasFinalizer ? ForkContext.newEmpty(this.forkContext) : null, + thrownForkContext: ForkContext.newEmpty(this.forkContext), + lastOfTryIsReachable: false, + lastOfCatchIsReachable: false + }; + } + + /** + * Pops the last context of TryStatement and finalizes it. + * @returns {void} + */ + popTryContext() { + var context = this.tryContext; + this.tryContext = context.upper; + if (context.position === 'catch') { + // Merges two paths from the `try` block and `catch` block merely. + this.popForkContext(); + return; + } + + /* + * The following process is executed only when there is the `finally` + * block. + */ + + var returned = context.returnedForkContext; + var thrown = context.thrownForkContext; + if (returned.empty && thrown.empty) { + return; + } + + // Separate head to normal paths and leaving paths. + var headSegments = this.forkContext.head; + this.forkContext = this.forkContext.upper; + var normalSegments = headSegments.slice(0, headSegments.length / 2 | 0); + var leavingSegments = headSegments.slice(headSegments.length / 2 | 0); + + // Forwards the leaving path to upper contexts. + if (!returned.empty) { + getReturnContext(this).returnedForkContext.add(leavingSegments); + } + if (!thrown.empty) { + getThrowContext(this).thrownForkContext.add(leavingSegments); + } + + // Sets the normal path as the next. + this.forkContext.replaceHead(normalSegments); + + /* + * If both paths of the `try` block and the `catch` block are + * unreachable, the next path becomes unreachable as well. + */ + if (!context.lastOfTryIsReachable && !context.lastOfCatchIsReachable) { + this.forkContext.makeUnreachable(); + } + } + + /** + * Makes a code path segment for a `catch` block. + * @returns {void} + */ + makeCatchBlock() { + var context = this.tryContext; + var forkContext = this.forkContext; + var thrown = context.thrownForkContext; + + // Update state. + context.position = 'catch'; + context.thrownForkContext = ForkContext.newEmpty(forkContext); + context.lastOfTryIsReachable = forkContext.reachable; + + // Merge thrown paths. + thrown.add(forkContext.head); + var thrownSegments = thrown.makeNext(0, -1); + + // Fork to a bypass and the merged thrown path. + this.pushForkContext(); + this.forkBypassPath(); + this.forkContext.add(thrownSegments); + } + + /** + * Makes a code path segment for a `finally` block. + * + * In the `finally` block, parallel paths are created. The parallel paths + * are used as leaving-paths. The leaving-paths are paths from `return` + * statements and `throw` statements in a `try` block or a `catch` block. + * @returns {void} + */ + makeFinallyBlock() { + var context = this.tryContext; + var forkContext = this.forkContext; + var returned = context.returnedForkContext; + var thrown = context.thrownForkContext; + var headOfLeavingSegments = forkContext.head; + + // Update state. + if (context.position === 'catch') { + // Merges two paths from the `try` block and `catch` block. + this.popForkContext(); + forkContext = this.forkContext; + context.lastOfCatchIsReachable = forkContext.reachable; + } else { + context.lastOfTryIsReachable = forkContext.reachable; + } + context.position = 'finally'; + if (returned.empty && thrown.empty) { + // This path does not leave. + return; + } + + /* + * Create a parallel segment from merging returned and thrown. + * This segment will leave at the end of this finally block. + */ + var segments = forkContext.makeNext(-1, -1); + for (var i = 0; i < forkContext.count; ++i) { + var prevSegsOfLeavingSegment = [headOfLeavingSegments[i]]; + for (var j = 0; j < returned.segmentsList.length; ++j) { + prevSegsOfLeavingSegment.push(returned.segmentsList[j][i]); + } + for (var _j = 0; _j < thrown.segmentsList.length; ++_j) { + prevSegsOfLeavingSegment.push(thrown.segmentsList[_j][i]); + } + segments.push(CodePathSegment.newNext(this.idGenerator.next(), prevSegsOfLeavingSegment)); + } + this.pushForkContext(true); + this.forkContext.add(segments); + } + + /** + * Makes a code path segment from the first throwable node to the `catch` + * block or the `finally` block. + * @returns {void} + */ + makeFirstThrowablePathInTryBlock() { + var forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + var context = getThrowContext(this); + if (context === this || context.position !== 'try' || !context.thrownForkContext.empty) { + return; + } + context.thrownForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeNext(-1, -1)); + } + + //-------------------------------------------------------------------------- + // Loop Statements + //-------------------------------------------------------------------------- + + /** + * Creates a context object of a loop statement and stacks it. + * @param {string} type The type of the node which was triggered. One of + * `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`, + * and `ForStatement`. + * @param {string|null} label A label of the node which was triggered. + * @throws {Error} (Unreachable - unknown type.) + * @returns {void} + */ + pushLoopContext(type, label) { + var forkContext = this.forkContext; + var breakContext = this.pushBreakContext(true, label); + switch (type) { + case 'WhileStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type: type, + label: label, + test: void 0, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'DoWhileStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type: type, + label: label, + test: void 0, + entrySegments: null, + continueForkContext: ForkContext.newEmpty(forkContext), + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'ForStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type: type, + label: label, + test: void 0, + endOfInitSegments: null, + testSegments: null, + endOfTestSegments: null, + updateSegments: null, + endOfUpdateSegments: null, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'ForInStatement': + case 'ForOfStatement': + this.loopContext = { + upper: this.loopContext, + type: type, + label: label, + prevSegments: null, + leftSegments: null, + endOfLeftSegments: null, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + + /* c8 ignore next */ + default: + throw new Error("unknown type: \"" + type + "\""); + } + } + + /** + * Pops the last context of a loop statement and finalizes it. + * @throws {Error} (Unreachable - unknown type.) + * @returns {void} + */ + popLoopContext() { + var context = this.loopContext; + this.loopContext = context.upper; + var forkContext = this.forkContext; + var brokenForkContext = this.popBreakContext().brokenForkContext; + + // Creates a looped path. + switch (context.type) { + case 'WhileStatement': + case 'ForStatement': + this.popChoiceContext(); + makeLooped(this, forkContext.head, context.continueDestSegments); + break; + case 'DoWhileStatement': + { + var choiceContext = this.popChoiceContext(); + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(forkContext.head); + choiceContext.falseForkContext.add(forkContext.head); + } + if (context.test !== true) { + brokenForkContext.addAll(choiceContext.falseForkContext); + } + + // `true` paths go to looping. + var segmentsList = choiceContext.trueForkContext.segmentsList; + for (var i = 0; i < segmentsList.length; ++i) { + makeLooped(this, segmentsList[i], context.entrySegments); + } + break; + } + case 'ForInStatement': + case 'ForOfStatement': + brokenForkContext.add(forkContext.head); + makeLooped(this, forkContext.head, context.leftSegments); + break; + + /* c8 ignore next */ + default: + throw new Error('unreachable'); + } + + // Go next. + if (brokenForkContext.empty) { + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } else { + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + } + + /** + * Makes a code path segment for the test part of a WhileStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeWhileTest(test) { + var context = this.loopContext; + var forkContext = this.forkContext; + var testSegments = forkContext.makeNext(0, -1); + + // Update state. + context.test = test; + context.continueDestSegments = testSegments; + forkContext.replaceHead(testSegments); + } + + /** + * Makes a code path segment for the body part of a WhileStatement. + * @returns {void} + */ + makeWhileBody() { + var context = this.loopContext; + var choiceContext = this.choiceContext; + var forkContext = this.forkContext; + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(forkContext.head); + choiceContext.falseForkContext.add(forkContext.head); + } + + // Update state. + if (context.test !== true) { + context.brokenForkContext.addAll(choiceContext.falseForkContext); + } + forkContext.replaceHead(choiceContext.trueForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment for the body part of a DoWhileStatement. + * @returns {void} + */ + makeDoWhileBody() { + var context = this.loopContext; + var forkContext = this.forkContext; + var bodySegments = forkContext.makeNext(-1, -1); + + // Update state. + context.entrySegments = bodySegments; + forkContext.replaceHead(bodySegments); + } + + /** + * Makes a code path segment for the test part of a DoWhileStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeDoWhileTest(test) { + var context = this.loopContext; + var forkContext = this.forkContext; + context.test = test; + + // Creates paths of `continue` statements. + if (!context.continueForkContext.empty) { + context.continueForkContext.add(forkContext.head); + var testSegments = context.continueForkContext.makeNext(0, -1); + forkContext.replaceHead(testSegments); + } + } + + /** + * Makes a code path segment for the test part of a ForStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeForTest(test) { + var context = this.loopContext; + var forkContext = this.forkContext; + var endOfInitSegments = forkContext.head; + var testSegments = forkContext.makeNext(-1, -1); + + // Update state. + context.test = test; + context.endOfInitSegments = endOfInitSegments; + context.continueDestSegments = context.testSegments = testSegments; + forkContext.replaceHead(testSegments); + } + + /** + * Makes a code path segment for the update part of a ForStatement. + * @returns {void} + */ + makeForUpdate() { + var context = this.loopContext; + var choiceContext = this.choiceContext; + var forkContext = this.forkContext; + + // Make the next paths of the test. + if (context.testSegments) { + finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head); + } else { + context.endOfInitSegments = forkContext.head; + } + + // Update state. + var updateSegments = forkContext.makeDisconnected(-1, -1); + context.continueDestSegments = context.updateSegments = updateSegments; + forkContext.replaceHead(updateSegments); + } + + /** + * Makes a code path segment for the body part of a ForStatement. + * @returns {void} + */ + makeForBody() { + var context = this.loopContext; + var choiceContext = this.choiceContext; + var forkContext = this.forkContext; + + // Update state. + if (context.updateSegments) { + context.endOfUpdateSegments = forkContext.head; + + // `update` -> `test` + if (context.testSegments) { + makeLooped(this, context.endOfUpdateSegments, context.testSegments); + } + } else if (context.testSegments) { + finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head); + } else { + context.endOfInitSegments = forkContext.head; + } + var bodySegments = context.endOfTestSegments; + if (!bodySegments) { + /* + * If there is not the `test` part, the `body` path comes from the + * `init` part and the `update` part. + */ + var prevForkContext = ForkContext.newEmpty(forkContext); + prevForkContext.add(context.endOfInitSegments); + if (context.endOfUpdateSegments) { + prevForkContext.add(context.endOfUpdateSegments); + } + bodySegments = prevForkContext.makeNext(0, -1); + } + context.continueDestSegments = context.continueDestSegments || bodySegments; + forkContext.replaceHead(bodySegments); + } + + /** + * Makes a code path segment for the left part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfLeft() { + var context = this.loopContext; + var forkContext = this.forkContext; + var leftSegments = forkContext.makeDisconnected(-1, -1); + + // Update state. + context.prevSegments = forkContext.head; + context.leftSegments = context.continueDestSegments = leftSegments; + forkContext.replaceHead(leftSegments); + } + + /** + * Makes a code path segment for the right part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfRight() { + var context = this.loopContext; + var forkContext = this.forkContext; + var temp = ForkContext.newEmpty(forkContext); + temp.add(context.prevSegments); + var rightSegments = temp.makeNext(-1, -1); + + // Update state. + context.endOfLeftSegments = forkContext.head; + forkContext.replaceHead(rightSegments); + } + + /** + * Makes a code path segment for the body part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfBody() { + var context = this.loopContext; + var forkContext = this.forkContext; + var temp = ForkContext.newEmpty(forkContext); + temp.add(context.endOfLeftSegments); + var bodySegments = temp.makeNext(-1, -1); + + // Make a path: `right` -> `left`. + makeLooped(this, forkContext.head, context.leftSegments); + + // Update state. + context.brokenForkContext.add(forkContext.head); + forkContext.replaceHead(bodySegments); + } + + //-------------------------------------------------------------------------- + // Control Statements + //-------------------------------------------------------------------------- + + /** + * Creates new context for BreakStatement. + * @param {boolean} breakable The flag to indicate it can break by + * an unlabeled BreakStatement. + * @param {string|null} label The label of this context. + * @returns {Object} The new context. + */ + pushBreakContext(breakable, label) { + this.breakContext = { + upper: this.breakContext, + breakable: breakable, + label: label, + brokenForkContext: ForkContext.newEmpty(this.forkContext) + }; + return this.breakContext; + } + + /** + * Removes the top item of the break context stack. + * @returns {Object} The removed context. + */ + popBreakContext() { + var context = this.breakContext; + var forkContext = this.forkContext; + this.breakContext = context.upper; + + // Process this context here for other than switches and loops. + if (!context.breakable) { + var brokenForkContext = context.brokenForkContext; + if (!brokenForkContext.empty) { + brokenForkContext.add(forkContext.head); + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + } + return context; + } + + /** + * Makes a path for a `break` statement. + * + * It registers the head segment to a context of `break`. + * It makes new unreachable segment, then it set the head with the segment. + * @param {string} label A label of the break statement. + * @returns {void} + */ + makeBreak(label) { + var forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + var context = getBreakContext(this, label); + if (context) { + context.brokenForkContext.add(forkContext.head); + } + + /* c8 ignore next */ + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + + /** + * Makes a path for a `continue` statement. + * + * It makes a looping path. + * It makes new unreachable segment, then it set the head with the segment. + * @param {string} label A label of the continue statement. + * @returns {void} + */ + makeContinue(label) { + var forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + var context = getContinueContext(this, label); + if (context) { + if (context.continueDestSegments) { + makeLooped(this, forkContext.head, context.continueDestSegments); + + // If the context is a for-in/of loop, this effects a break also. + if (context.type === 'ForInStatement' || context.type === 'ForOfStatement') { + context.brokenForkContext.add(forkContext.head); + } + } else { + context.continueForkContext.add(forkContext.head); + } + } + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + + /** + * Makes a path for a `return` statement. + * + * It registers the head segment to a context of `return`. + * It makes new unreachable segment, then it set the head with the segment. + * @returns {void} + */ + makeReturn() { + var forkContext = this.forkContext; + if (forkContext.reachable) { + getReturnContext(this).returnedForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + } + + /** + * Makes a path for a `throw` statement. + * + * It registers the head segment to a context of `throw`. + * It makes new unreachable segment, then it set the head with the segment. + * @returns {void} + */ + makeThrow() { + var forkContext = this.forkContext; + if (forkContext.reachable) { + getThrowContext(this).thrownForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + } + + /** + * Makes the final path. + * @returns {void} + */ + makeFinal() { + var segments = this.currentSegments; + if (segments.length > 0 && segments[0].reachable) { + this.returnedForkContext.add(segments); + } + } + } + codePathState = CodePathState; + return codePathState; +} + +var idGenerator; +var hasRequiredIdGenerator; +function requireIdGenerator() { + if (hasRequiredIdGenerator) return idGenerator; + hasRequiredIdGenerator = 1; + + /* eslint-disable react-internal/safe-string-coercion */ + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A generator for unique ids. + */ + class IdGenerator { + /** + * @param {string} prefix Optional. A prefix of generated ids. + */ + constructor(prefix) { + this.prefix = String(prefix); + this.n = 0; + } + + /** + * Generates id. + * @returns {string} A generated id. + */ + next() { + this.n = 1 + this.n | 0; + + /* c8 ignore start */ + if (this.n < 0) { + this.n = 1; + } /* c8 ignore stop */ + + return this.prefix + this.n; + } + } + idGenerator = IdGenerator; + return idGenerator; +} + +var codePath; +var hasRequiredCodePath; +function requireCodePath() { + if (hasRequiredCodePath) return codePath; + hasRequiredCodePath = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + var CodePathState = requireCodePathState(); + // eslint-disable-next-line + var IdGenerator = requireIdGenerator(); + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A code path. + */ + class CodePath { + /** + * Creates a new instance. + * @param {Object} options Options for the function (see below). + * @param {string} options.id An identifier. + * @param {string} options.origin The type of code path origin. + * @param {CodePath|null} options.upper The code path of the upper function scope. + * @param {Function} options.onLooped A callback function to notify looping. + */ + constructor(_ref) { + var id = _ref.id, + origin = _ref.origin, + upper = _ref.upper, + onLooped = _ref.onLooped; + /** + * The identifier of this code path. + * Rules use it to store additional information of each rule. + * @type {string} + */ + this.id = id; + + /** + * The reason that this code path was started. May be "program", + * "function", "class-field-initializer", or "class-static-block". + * @type {string} + */ + this.origin = origin; + + /** + * The code path of the upper function scope. + * @type {CodePath|null} + */ + this.upper = upper; + + /** + * The code paths of nested function scopes. + * @type {CodePath[]} + */ + this.childCodePaths = []; + + // Initializes internal state. + Object.defineProperty(this, 'internal', { + value: new CodePathState(new IdGenerator(id + "_"), onLooped) + }); + + // Adds this into `childCodePaths` of `upper`. + if (upper) { + upper.childCodePaths.push(this); + } + } + + /** + * Gets the state of a given code path. + * @param {CodePath} codePath A code path to get. + * @returns {CodePathState} The state of the code path. + */ + static getState(codePath) { + return codePath.internal; + } + + /** + * The initial code path segment. + * @type {CodePathSegment} + */ + get initialSegment() { + return this.internal.initialSegment; + } + + /** + * Final code path segments. + * This array is a mix of `returnedSegments` and `thrownSegments`. + * @type {CodePathSegment[]} + */ + get finalSegments() { + return this.internal.finalSegments; + } + + /** + * Final code path segments which is with `return` statements. + * This array contains the last path segment if it's reachable. + * Since the reachable last path returns `undefined`. + * @type {CodePathSegment[]} + */ + get returnedSegments() { + return this.internal.returnedForkContext; + } + + /** + * Final code path segments which is with `throw` statements. + * @type {CodePathSegment[]} + */ + get thrownSegments() { + return this.internal.thrownForkContext; + } + + /** + * Current code path segments. + * @type {CodePathSegment[]} + */ + get currentSegments() { + return this.internal.currentSegments; + } + + /** + * Traverses all segments in this code path. + * + * codePath.traverseSegments(function(segment, controller) { + * // do something. + * }); + * + * This method enumerates segments in order from the head. + * + * The `controller` object has two methods. + * + * - `controller.skip()` - Skip the following segments in this branch. + * - `controller.break()` - Skip all following segments. + * @param {Object} [options] Omittable. + * @param {CodePathSegment} [options.first] The first segment to traverse. + * @param {CodePathSegment} [options.last] The last segment to traverse. + * @param {Function} callback A callback function. + * @returns {void} + */ + traverseSegments(options, callback) { + var resolvedOptions; + var resolvedCallback; + if (typeof options === 'function') { + resolvedCallback = options; + resolvedOptions = {}; + } else { + resolvedOptions = options || {}; + resolvedCallback = callback; + } + var startSegment = resolvedOptions.first || this.internal.initialSegment; + var lastSegment = resolvedOptions.last; + var item = null; + var index = 0; + var end = 0; + var segment = null; + var visited = Object.create(null); + var stack = [[startSegment, 0]]; + var skippedSegment = null; + var broken = false; + var controller = { + skip: function () { + if (stack.length <= 1) { + broken = true; + } else { + skippedSegment = stack[stack.length - 2][0]; + } + }, + break: function () { + broken = true; + } + }; + + /** + * Checks a given previous segment has been visited. + * @param {CodePathSegment} prevSegment A previous segment to check. + * @returns {boolean} `true` if the segment has been visited. + */ + function isVisited(prevSegment) { + return visited[prevSegment.id] || segment.isLoopedPrevSegment(prevSegment); + } + while (stack.length > 0) { + item = stack[stack.length - 1]; + segment = item[0]; + index = item[1]; + if (index === 0) { + // Skip if this segment has been visited already. + if (visited[segment.id]) { + stack.pop(); + continue; + } + + // Skip if all previous segments have not been visited. + if (segment !== startSegment && segment.prevSegments.length > 0 && !segment.prevSegments.every(isVisited)) { + stack.pop(); + continue; + } + + // Reset the flag of skipping if all branches have been skipped. + if (skippedSegment && segment.prevSegments.includes(skippedSegment)) { + skippedSegment = null; + } + visited[segment.id] = true; + + // Call the callback when the first time. + if (!skippedSegment) { + resolvedCallback.call(this, segment, controller); + if (segment === lastSegment) { + controller.skip(); + } + if (broken) { + break; + } + } + } + + // Update the stack. + end = segment.nextSegments.length - 1; + if (index < end) { + item[1] += 1; + stack.push([segment.nextSegments[index], 0]); + } else if (index === end) { + item[0] = segment.nextSegments[index]; + item[1] = 0; + } else { + stack.pop(); + } + } + } + } + codePath = CodePath; + return codePath; +} + +var codePathAnalyzer; +var hasRequiredCodePathAnalyzer; +function requireCodePathAnalyzer() { + if (hasRequiredCodePathAnalyzer) return codePathAnalyzer; + hasRequiredCodePathAnalyzer = 1; + + /* eslint-disable react-internal/no-primitive-constructors */ + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + var assert = requireAssert(); + // eslint-disable-next-line + var CodePath = requireCodePath(); + // eslint-disable-next-line + var CodePathSegment = requireCodePathSegment(); + // eslint-disable-next-line + var IdGenerator = requireIdGenerator(); + var breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u; + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Checks whether or not a given node is a `case` node (not `default` node). + * @param {ASTNode} node A `SwitchCase` node to check. + * @returns {boolean} `true` if the node is a `case` node (not `default` node). + */ + function isCaseNode(node) { + return Boolean(node.test); + } + + /** + * Checks if a given node appears as the value of a PropertyDefinition node. + * @param {ASTNode} node THe node to check. + * @returns {boolean} `true` if the node is a PropertyDefinition value, + * false if not. + */ + function isPropertyDefinitionValue(node) { + var parent = node.parent; + return parent && parent.type === 'PropertyDefinition' && parent.value === node; + } + + /** + * Checks whether the given logical operator is taken into account for the code + * path analysis. + * @param {string} operator The operator found in the LogicalExpression node + * @returns {boolean} `true` if the operator is "&&" or "||" or "??" + */ + function isHandledLogicalOperator(operator) { + return operator === '&&' || operator === '||' || operator === '??'; + } + + /** + * Checks whether the given assignment operator is a logical assignment operator. + * Logical assignments are taken into account for the code path analysis + * because of their short-circuiting semantics. + * @param {string} operator The operator found in the AssignmentExpression node + * @returns {boolean} `true` if the operator is "&&=" or "||=" or "??=" + */ + function isLogicalAssignmentOperator(operator) { + return operator === '&&=' || operator === '||=' || operator === '??='; + } + + /** + * Gets the label if the parent node of a given node is a LabeledStatement. + * @param {ASTNode} node A node to get. + * @returns {string|null} The label or `null`. + */ + function getLabel(node) { + if (node.parent.type === 'LabeledStatement') { + return node.parent.label.name; + } + return null; + } + + /** + * Checks whether or not a given logical expression node goes different path + * between the `true` case and the `false` case. + * @param {ASTNode} node A node to check. + * @returns {boolean} `true` if the node is a test of a choice statement. + */ + function isForkingByTrueOrFalse(node) { + var parent = node.parent; + switch (parent.type) { + case 'ConditionalExpression': + case 'IfStatement': + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + return parent.test === node; + case 'LogicalExpression': + return isHandledLogicalOperator(parent.operator); + case 'AssignmentExpression': + return isLogicalAssignmentOperator(parent.operator); + default: + return false; + } + } + + /** + * Gets the boolean value of a given literal node. + * + * This is used to detect infinity loops (e.g. `while (true) {}`). + * Statements preceded by an infinity loop are unreachable if the loop didn't + * have any `break` statement. + * @param {ASTNode} node A node to get. + * @returns {boolean|undefined} a boolean value if the node is a Literal node, + * otherwise `undefined`. + */ + function getBooleanValueIfSimpleConstant(node) { + if (node.type === 'Literal') { + return Boolean(node.value); + } + return void 0; + } + + /** + * Checks that a given identifier node is a reference or not. + * + * This is used to detect the first throwable node in a `try` block. + * @param {ASTNode} node An Identifier node to check. + * @returns {boolean} `true` if the node is a reference. + */ + function isIdentifierReference(node) { + var parent = node.parent; + switch (parent.type) { + case 'LabeledStatement': + case 'BreakStatement': + case 'ContinueStatement': + case 'ArrayPattern': + case 'RestElement': + case 'ImportSpecifier': + case 'ImportDefaultSpecifier': + case 'ImportNamespaceSpecifier': + case 'CatchClause': + return false; + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + case 'ClassDeclaration': + case 'ClassExpression': + case 'VariableDeclarator': + return parent.id !== node; + case 'Property': + case 'PropertyDefinition': + case 'MethodDefinition': + return parent.key !== node || parent.computed || parent.shorthand; + case 'AssignmentPattern': + return parent.key !== node; + default: + return true; + } + } + + /** + * Updates the current segment with the head segment. + * This is similar to local branches and tracking branches of git. + * + * To separate the current and the head is in order to not make useless segments. + * + * In this process, both "onCodePathSegmentStart" and "onCodePathSegmentEnd" + * events are fired. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function forwardCurrentToHead(analyzer, node) { + var codePath = analyzer.codePath; + var state = CodePath.getState(codePath); + var currentSegments = state.currentSegments; + var headSegments = state.headSegments; + var end = Math.max(currentSegments.length, headSegments.length); + var i, currentSegment, headSegment; + + // Fires leaving events. + for (i = 0; i < end; ++i) { + currentSegment = currentSegments[i]; + headSegment = headSegments[i]; + if (currentSegment !== headSegment && currentSegment) { + if (currentSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentEnd', currentSegment, node); + } + } + } + + // Update state. + state.currentSegments = headSegments; + + // Fires entering events. + for (i = 0; i < end; ++i) { + currentSegment = currentSegments[i]; + headSegment = headSegments[i]; + if (currentSegment !== headSegment && headSegment) { + CodePathSegment.markUsed(headSegment); + if (headSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentStart', headSegment, node); + } + } + } + } + + /** + * Updates the current segment with empty. + * This is called at the last of functions or the program. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function leaveFromCurrentSegment(analyzer, node) { + var state = CodePath.getState(analyzer.codePath); + var currentSegments = state.currentSegments; + for (var i = 0; i < currentSegments.length; ++i) { + var currentSegment = currentSegments[i]; + if (currentSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentEnd', currentSegment, node); + } + } + state.currentSegments = []; + } + + /** + * Updates the code path due to the position of a given node in the parent node + * thereof. + * + * For example, if the node is `parent.consequent`, this creates a fork from the + * current path. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function preprocess(analyzer, node) { + var codePath = analyzer.codePath; + var state = CodePath.getState(codePath); + var parent = node.parent; + switch (parent.type) { + // The `arguments.length == 0` case is in `postprocess` function. + case 'CallExpression': + if (parent.optional === true && parent.arguments.length >= 1 && parent.arguments[0] === node) { + state.makeOptionalRight(); + } + break; + case 'MemberExpression': + if (parent.optional === true && parent.property === node) { + state.makeOptionalRight(); + } + break; + case 'LogicalExpression': + if (parent.right === node && isHandledLogicalOperator(parent.operator)) { + state.makeLogicalRight(); + } + break; + case 'AssignmentExpression': + if (parent.right === node && isLogicalAssignmentOperator(parent.operator)) { + state.makeLogicalRight(); + } + break; + case 'ConditionalExpression': + case 'IfStatement': + /* + * Fork if this node is at `consequent`/`alternate`. + * `popForkContext()` exists at `IfStatement:exit` and + * `ConditionalExpression:exit`. + */ + if (parent.consequent === node) { + state.makeIfConsequent(); + } else if (parent.alternate === node) { + state.makeIfAlternate(); + } + break; + case 'SwitchCase': + if (parent.consequent[0] === node) { + state.makeSwitchCaseBody(false, !parent.test); + } + break; + case 'TryStatement': + if (parent.handler === node) { + state.makeCatchBlock(); + } else if (parent.finalizer === node) { + state.makeFinallyBlock(); + } + break; + case 'WhileStatement': + if (parent.test === node) { + state.makeWhileTest(getBooleanValueIfSimpleConstant(node)); + } else { + assert(parent.body === node); + state.makeWhileBody(); + } + break; + case 'DoWhileStatement': + if (parent.body === node) { + state.makeDoWhileBody(); + } else { + assert(parent.test === node); + state.makeDoWhileTest(getBooleanValueIfSimpleConstant(node)); + } + break; + case 'ForStatement': + if (parent.test === node) { + state.makeForTest(getBooleanValueIfSimpleConstant(node)); + } else if (parent.update === node) { + state.makeForUpdate(); + } else if (parent.body === node) { + state.makeForBody(); + } + break; + case 'ForInStatement': + case 'ForOfStatement': + if (parent.left === node) { + state.makeForInOfLeft(); + } else if (parent.right === node) { + state.makeForInOfRight(); + } else { + assert(parent.body === node); + state.makeForInOfBody(); + } + break; + case 'AssignmentPattern': + /* + * Fork if this node is at `right`. + * `left` is executed always, so it uses the current path. + * `popForkContext()` exists at `AssignmentPattern:exit`. + */ + if (parent.right === node) { + state.pushForkContext(); + state.forkBypassPath(); + state.forkPath(); + } + break; + } + } + + /** + * Updates the code path due to the type of a given node in entering. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function processCodePathToEnter(analyzer, node) { + var codePath = analyzer.codePath; + var state = codePath && CodePath.getState(codePath); + var parent = node.parent; + + /** + * Creates a new code path and trigger the onCodePathStart event + * based on the currently selected node. + * @param {string} origin The reason the code path was started. + * @returns {void} + */ + function startCodePath(origin) { + if (codePath) { + // Emits onCodePathSegmentStart events if updated. + forwardCurrentToHead(analyzer, node); + } + + // Create the code path of this scope. + codePath = analyzer.codePath = new CodePath({ + id: analyzer.idGenerator.next(), + origin: origin, + upper: codePath, + onLooped: analyzer.onLooped + }); + state = CodePath.getState(codePath); + + // Emits onCodePathStart events. + analyzer.emitter.emit('onCodePathStart', codePath, node); + } + + /* + * Special case: The right side of class field initializer is considered + * to be its own function, so we need to start a new code path in this + * case. + */ + if (isPropertyDefinitionValue(node)) { + startCodePath('class-field-initializer'); + + /* + * Intentional fall through because `node` needs to also be + * processed by the code below. For example, if we have: + * + * class Foo { + * a = () => {} + * } + * + * In this case, we also need start a second code path. + */ + } + switch (node.type) { + case 'Program': + startCodePath('program'); + break; + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + startCodePath('function'); + break; + case 'StaticBlock': + startCodePath('class-static-block'); + break; + case 'ChainExpression': + state.pushChainContext(); + break; + case 'CallExpression': + if (node.optional === true) { + state.makeOptionalNode(); + } + break; + case 'MemberExpression': + if (node.optional === true) { + state.makeOptionalNode(); + } + break; + case 'LogicalExpression': + if (isHandledLogicalOperator(node.operator)) { + state.pushChoiceContext(node.operator, isForkingByTrueOrFalse(node)); + } + break; + case 'AssignmentExpression': + if (isLogicalAssignmentOperator(node.operator)) { + state.pushChoiceContext(node.operator.slice(0, -1), + // removes `=` from the end + isForkingByTrueOrFalse(node)); + } + break; + case 'ConditionalExpression': + case 'IfStatement': + state.pushChoiceContext('test', false); + break; + case 'SwitchStatement': + state.pushSwitchContext(node.cases.some(isCaseNode), getLabel(node)); + break; + case 'TryStatement': + state.pushTryContext(Boolean(node.finalizer)); + break; + case 'SwitchCase': + /* + * Fork if this node is after the 2st node in `cases`. + * It's similar to `else` blocks. + * The next `test` node is processed in this path. + */ + if (parent.discriminant !== node && parent.cases[0] !== node) { + state.forkPath(); + } + break; + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + case 'ForInStatement': + case 'ForOfStatement': + state.pushLoopContext(node.type, getLabel(node)); + break; + case 'LabeledStatement': + if (!breakableTypePattern.test(node.body.type)) { + state.pushBreakContext(false, node.label.name); + } + break; + } + + // Emits onCodePathSegmentStart events if updated. + forwardCurrentToHead(analyzer, node); + } + + /** + * Updates the code path due to the type of a given node in leaving. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function processCodePathToExit(analyzer, node) { + var codePath = analyzer.codePath; + var state = CodePath.getState(codePath); + var dontForward = false; + switch (node.type) { + case 'ChainExpression': + state.popChainContext(); + break; + case 'IfStatement': + case 'ConditionalExpression': + state.popChoiceContext(); + break; + case 'LogicalExpression': + if (isHandledLogicalOperator(node.operator)) { + state.popChoiceContext(); + } + break; + case 'AssignmentExpression': + if (isLogicalAssignmentOperator(node.operator)) { + state.popChoiceContext(); + } + break; + case 'SwitchStatement': + state.popSwitchContext(); + break; + case 'SwitchCase': + /* + * This is the same as the process at the 1st `consequent` node in + * `preprocess` function. + * Must do if this `consequent` is empty. + */ + if (node.consequent.length === 0) { + state.makeSwitchCaseBody(true, !node.test); + } + if (state.forkContext.reachable) { + dontForward = true; + } + break; + case 'TryStatement': + state.popTryContext(); + break; + case 'BreakStatement': + forwardCurrentToHead(analyzer, node); + state.makeBreak(node.label && node.label.name); + dontForward = true; + break; + case 'ContinueStatement': + forwardCurrentToHead(analyzer, node); + state.makeContinue(node.label && node.label.name); + dontForward = true; + break; + case 'ReturnStatement': + forwardCurrentToHead(analyzer, node); + state.makeReturn(); + dontForward = true; + break; + case 'ThrowStatement': + forwardCurrentToHead(analyzer, node); + state.makeThrow(); + dontForward = true; + break; + case 'Identifier': + if (isIdentifierReference(node)) { + state.makeFirstThrowablePathInTryBlock(); + dontForward = true; + } + break; + case 'CallExpression': + case 'ImportExpression': + case 'MemberExpression': + case 'NewExpression': + case 'YieldExpression': + state.makeFirstThrowablePathInTryBlock(); + break; + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + case 'ForInStatement': + case 'ForOfStatement': + state.popLoopContext(); + break; + case 'AssignmentPattern': + state.popForkContext(); + break; + case 'LabeledStatement': + if (!breakableTypePattern.test(node.body.type)) { + state.popBreakContext(); + } + break; + } + + // Emits onCodePathSegmentStart events if updated. + if (!dontForward) { + forwardCurrentToHead(analyzer, node); + } + } + + /** + * Updates the code path to finalize the current code path. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function postprocess(analyzer, node) { + /** + * Ends the code path for the current node. + * @returns {void} + */ + function endCodePath() { + var codePath = analyzer.codePath; + + // Mark the current path as the final node. + CodePath.getState(codePath).makeFinal(); + + // Emits onCodePathSegmentEnd event of the current segments. + leaveFromCurrentSegment(analyzer, node); + + // Emits onCodePathEnd event of this code path. + analyzer.emitter.emit('onCodePathEnd', codePath, node); + codePath = analyzer.codePath = analyzer.codePath.upper; + } + switch (node.type) { + case 'Program': + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + case 'StaticBlock': + { + endCodePath(); + break; + } + + // The `arguments.length >= 1` case is in `preprocess` function. + case 'CallExpression': + if (node.optional === true && node.arguments.length === 0) { + CodePath.getState(analyzer.codePath).makeOptionalRight(); + } + break; + } + + /* + * Special case: The right side of class field initializer is considered + * to be its own function, so we need to end a code path in this + * case. + * + * We need to check after the other checks in order to close the + * code paths in the correct order for code like this: + * + * + * class Foo { + * a = () => {} + * } + * + * In this case, The ArrowFunctionExpression code path is closed first + * and then we need to close the code path for the PropertyDefinition + * value. + */ + if (isPropertyDefinitionValue(node)) { + endCodePath(); + } + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * The class to analyze code paths. + * This class implements the EventGenerator interface. + */ + class CodePathAnalyzer { + /** + * @param {EventGenerator} eventGenerator An event generator to wrap. + */ + constructor(emitters) { + this.emitter = { + emit: function (event) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + emitters[event]?.(...args); + } + }; + this.codePath = null; + this.idGenerator = new IdGenerator('s'); + this.currentNode = null; + this.onLooped = this.onLooped.bind(this); + } + + /** + * Does the process to enter a given AST node. + * This updates state of analysis and calls `enterNode` of the wrapped. + * @param {ASTNode} node A node which is entering. + * @returns {void} + */ + enterNode(node) { + this.currentNode = node; + + // Updates the code path due to node's position in its parent node. + if (node.parent) { + preprocess(this, node); + } + + /* + * Updates the code path. + * And emits onCodePathStart/onCodePathSegmentStart events. + */ + processCodePathToEnter(this, node); + this.currentNode = null; + } + + /** + * Does the process to leave a given AST node. + * This updates state of analysis and calls `leaveNode` of the wrapped. + * @param {ASTNode} node A node which is leaving. + * @returns {void} + */ + leaveNode(node) { + this.currentNode = node; + + /* + * Updates the code path. + * And emits onCodePathStart/onCodePathSegmentStart events. + */ + processCodePathToExit(this, node); + + // Emits the last onCodePathStart/onCodePathSegmentStart events. + postprocess(this, node); + this.currentNode = null; + } + + /** + * This is called on a code path looped. + * Then this raises a looped event. + * @param {CodePathSegment} fromSegment A segment of prev. + * @param {CodePathSegment} toSegment A segment of next. + * @returns {void} + */ + onLooped(fromSegment, toSegment) { + if (fromSegment.reachable && toSegment.reachable) { + this.emitter.emit('onCodePathSegmentLoop', fromSegment, toSegment, this.currentNode); + } + } + } + codePathAnalyzer = CodePathAnalyzer; + return codePathAnalyzer; +} + +var codePathAnalyzerExports = requireCodePathAnalyzer(); +var CodePathAnalyzer = /*@__PURE__*/getDefaultExportFromCjs(codePathAnalyzerExports); + +function isHookName(s) { + return s === 'use' || /^use[A-Z0-9]/.test(s); +} +function isHook(node) { + if (node.type === 'Identifier') { + return isHookName(node.name); + } + else if (node.type === 'MemberExpression' && + !node.computed && + isHook(node.property)) { + const obj = node.object; + const isPascalCaseNameSpace = /^[A-Z].*/; + return obj.type === 'Identifier' && isPascalCaseNameSpace.test(obj.name); + } + else { + return false; + } +} +function isComponentName(node) { + return node.type === 'Identifier' && /^[A-Z]/.test(node.name); +} +function isReactFunction(node, functionName) { + return (('name' in node && node.name === functionName) || + (node.type === 'MemberExpression' && + 'name' in node.object && + node.object.name === 'React' && + 'name' in node.property && + node.property.name === functionName)); +} +function isForwardRefCallback(node) { + return !!(node.parent && + 'callee' in node.parent && + node.parent.callee && + isReactFunction(node.parent.callee, 'forwardRef')); +} +function isMemoCallback(node) { + return !!(node.parent && + 'callee' in node.parent && + node.parent.callee && + isReactFunction(node.parent.callee, 'memo')); +} +function isInsideComponentOrHook(node) { + while (node) { + const functionName = getFunctionName(node); + if (functionName) { + if (isComponentName(functionName) || isHook(functionName)) { + return true; + } + } + if (isForwardRefCallback(node) || isMemoCallback(node)) { + return true; + } + node = node.parent; + } + return false; +} +function isInsideDoWhileLoop(node) { + while (node) { + if (node.type === 'DoWhileStatement') { + return true; + } + node = node.parent; + } + return false; +} +function isUseEffectEventIdentifier(node) { + { + return node.type === 'Identifier' && node.name === 'useEffectEvent'; + } +} +function isUseIdentifier(node) { + return isReactFunction(node, 'use'); +} +const rule = { + meta: { + type: 'problem', + docs: { + description: 'enforces the Rules of Hooks', + recommended: true, + url: 'https://reactjs.org/docs/hooks-rules.html', + }, + }, + create(context) { + let lastEffect = null; + const codePathReactHooksMapStack = []; + const codePathSegmentStack = []; + const useEffectEventFunctions = new WeakSet(); + function recordAllUseEffectEventFunctions(scope) { + for (const reference of scope.references) { + const parent = reference.identifier.parent; + if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && + parent.init && + parent.init.type === 'CallExpression' && + parent.init.callee && + isUseEffectEventIdentifier(parent.init.callee)) { + if (reference.resolved === null) { + throw new Error('Unexpected null reference.resolved'); + } + for (const ref of reference.resolved.references) { + if (ref !== reference) { + useEffectEventFunctions.add(ref.identifier); + } + } + } + } + } + const getSourceCode = typeof context.getSourceCode === 'function' + ? () => { + return context.getSourceCode(); + } + : () => { + return context.sourceCode; + }; + const getScope = typeof context.getScope === 'function' + ? () => { + return context.getScope(); + } + : (node) => { + return getSourceCode().getScope(node); + }; + function hasFlowSuppression(node, suppression) { + const sourceCode = getSourceCode(); + const comments = sourceCode.getAllComments(); + const flowSuppressionRegex = new RegExp('\\$FlowFixMe\\[' + suppression + '\\]'); + return comments.some(commentNode => flowSuppressionRegex.test(commentNode.value) && + commentNode.loc != null && + node.loc != null && + commentNode.loc.end.line === node.loc.start.line - 1); + } + const analyzer = new CodePathAnalyzer({ + onCodePathSegmentStart: (segment) => codePathSegmentStack.push(segment), + onCodePathSegmentEnd: () => codePathSegmentStack.pop(), + onCodePathStart: () => codePathReactHooksMapStack.push(new Map()), + onCodePathEnd(codePath, codePathNode) { + const reactHooksMap = codePathReactHooksMapStack.pop(); + if ((reactHooksMap === null || reactHooksMap === void 0 ? void 0 : reactHooksMap.size) === 0) { + return; + } + else if (typeof reactHooksMap === 'undefined') { + throw new Error('Unexpected undefined reactHooksMap'); + } + const cyclic = new Set(); + function countPathsFromStart(segment, pathHistory) { + const { cache } = countPathsFromStart; + let paths = cache.get(segment.id); + const pathList = new Set(pathHistory); + if (pathList.has(segment.id)) { + const pathArray = [...pathList]; + const cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1); + for (const cyclicSegment of cyclicSegments) { + cyclic.add(cyclicSegment); + } + return BigInt('0'); + } + pathList.add(segment.id); + if (paths !== undefined) { + return paths; + } + if (codePath.thrownSegments.includes(segment)) { + paths = BigInt('0'); + } + else if (segment.prevSegments.length === 0) { + paths = BigInt('1'); + } + else { + paths = BigInt('0'); + for (const prevSegment of segment.prevSegments) { + paths += countPathsFromStart(prevSegment, pathList); + } + } + if (segment.reachable && paths === BigInt('0')) { + cache.delete(segment.id); + } + else { + cache.set(segment.id, paths); + } + return paths; + } + function countPathsToEnd(segment, pathHistory) { + const { cache } = countPathsToEnd; + let paths = cache.get(segment.id); + const pathList = new Set(pathHistory); + if (pathList.has(segment.id)) { + const pathArray = Array.from(pathList); + const cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1); + for (const cyclicSegment of cyclicSegments) { + cyclic.add(cyclicSegment); + } + return BigInt('0'); + } + pathList.add(segment.id); + if (paths !== undefined) { + return paths; + } + if (codePath.thrownSegments.includes(segment)) { + paths = BigInt('0'); + } + else if (segment.nextSegments.length === 0) { + paths = BigInt('1'); + } + else { + paths = BigInt('0'); + for (const nextSegment of segment.nextSegments) { + paths += countPathsToEnd(nextSegment, pathList); + } + } + cache.set(segment.id, paths); + return paths; + } + function shortestPathLengthToStart(segment) { + const { cache } = shortestPathLengthToStart; + let length = cache.get(segment.id); + if (length === null) { + return Infinity; + } + if (length !== undefined) { + return length; + } + cache.set(segment.id, null); + if (segment.prevSegments.length === 0) { + length = 1; + } + else { + length = Infinity; + for (const prevSegment of segment.prevSegments) { + const prevLength = shortestPathLengthToStart(prevSegment); + if (prevLength < length) { + length = prevLength; + } + } + length += 1; + } + cache.set(segment.id, length); + return length; + } + countPathsFromStart.cache = new Map(); + countPathsToEnd.cache = new Map(); + shortestPathLengthToStart.cache = new Map(); + const allPathsFromStartToEnd = countPathsToEnd(codePath.initialSegment); + const codePathFunctionName = getFunctionName(codePathNode); + const isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode); + const isDirectlyInsideComponentOrHook = codePathFunctionName + ? isComponentName(codePathFunctionName) || + isHook(codePathFunctionName) + : isForwardRefCallback(codePathNode) || isMemoCallback(codePathNode); + let shortestFinalPathLength = Infinity; + for (const finalSegment of codePath.finalSegments) { + if (!finalSegment.reachable) { + continue; + } + const length = shortestPathLengthToStart(finalSegment); + if (length < shortestFinalPathLength) { + shortestFinalPathLength = length; + } + } + for (const [segment, reactHooks] of reactHooksMap) { + if (!segment.reachable) { + continue; + } + const possiblyHasEarlyReturn = segment.nextSegments.length === 0 + ? shortestFinalPathLength <= shortestPathLengthToStart(segment) + : shortestFinalPathLength < shortestPathLengthToStart(segment); + const pathsFromStartToEnd = countPathsFromStart(segment) * countPathsToEnd(segment); + const cycled = cyclic.has(segment.id); + for (const hook of reactHooks) { + if (hasFlowSuppression(hook, 'react-rule-hook')) { + continue; + } + if ((cycled || isInsideDoWhileLoop(hook)) && + !isUseIdentifier(hook)) { + context.report({ + node: hook, + message: `React Hook "${getSourceCode().getText(hook)}" may be executed ` + + 'more than once. Possibly because it is called in a loop. ' + + 'React Hooks must be called in the exact same order in ' + + 'every component render.', + }); + } + if (isDirectlyInsideComponentOrHook) { + const isAsyncFunction = codePathNode.async; + if (isAsyncFunction) { + context.report({ + node: hook, + message: `React Hook "${getSourceCode().getText(hook)}" cannot be ` + + 'called in an async function.', + }); + } + if (!cycled && + pathsFromStartToEnd !== allPathsFromStartToEnd && + !isUseIdentifier(hook) && + !isInsideDoWhileLoop(hook)) { + const message = `React Hook "${getSourceCode().getText(hook)}" is called ` + + 'conditionally. React Hooks must be called in the exact ' + + 'same order in every component render.' + + (possiblyHasEarlyReturn + ? ' Did you accidentally call a React Hook after an' + + ' early return?' + : ''); + context.report({ node: hook, message }); + } + } + else if (codePathNode.parent != null && + (codePathNode.parent.type === 'MethodDefinition' || + codePathNode.parent.type === 'ClassProperty' || + codePathNode.parent.type === 'PropertyDefinition') && + codePathNode.parent.value === codePathNode) { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'in a class component. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + else if (codePathFunctionName) { + const message = `React Hook "${getSourceCode().getText(hook)}" is called in ` + + `function "${getSourceCode().getText(codePathFunctionName)}" ` + + 'that is neither a React function component nor a custom ' + + 'React Hook function.' + + ' React component names must start with an uppercase letter.' + + ' React Hook names must start with the word "use".'; + context.report({ node: hook, message }); + } + else if (codePathNode.type === 'Program') { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'at the top level. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + else { + if (isSomewhereInsideComponentOrHook && !isUseIdentifier(hook)) { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'inside a callback. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + } + } + } + }, + }); + return { + '*'(node) { + analyzer.enterNode(node); + }, + '*:exit'(node) { + analyzer.leaveNode(node); + }, + CallExpression(node) { + if (isHook(node.callee)) { + const reactHooksMap = last(codePathReactHooksMapStack); + const codePathSegment = last(codePathSegmentStack); + let reactHooks = reactHooksMap.get(codePathSegment); + if (!reactHooks) { + reactHooks = []; + reactHooksMap.set(codePathSegment, reactHooks); + } + reactHooks.push(node.callee); + } + if (node.callee.type === 'Identifier' && + (node.callee.name === 'useEffect' || + isUseEffectEventIdentifier(node.callee)) && + node.arguments.length > 0) { + lastEffect = node; + } + }, + Identifier(node) { + if (lastEffect == null && + useEffectEventFunctions.has(node) && + node.parent.type !== 'CallExpression') { + context.report({ + node, + message: `\`${getSourceCode().getText(node)}\` is a function created with React Hook "useEffectEvent", and can only be called from ` + + 'the same component. They cannot be assigned to variables or passed down.', + }); + } + }, + 'CallExpression:exit'(node) { + if (node === lastEffect) { + lastEffect = null; + } + }, + FunctionDeclaration(node) { + if (isInsideComponentOrHook(node)) { + recordAllUseEffectEventFunctions(getScope(node)); + } + }, + ArrowFunctionExpression(node) { + if (isInsideComponentOrHook(node)) { + recordAllUseEffectEventFunctions(getScope(node)); + } + }, + }; + }, +}; +function getFunctionName(node) { + var _a, _b, _c, _d; + if (node.type === 'ComponentDeclaration' || + node.type === 'HookDeclaration' || + node.type === 'FunctionDeclaration' || + (node.type === 'FunctionExpression' && node.id)) { + return node.id; + } + else if (node.type === 'FunctionExpression' || + node.type === 'ArrowFunctionExpression') { + if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'VariableDeclarator' && + node.parent.init === node) { + return node.parent.id; + } + else if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === 'AssignmentExpression' && + node.parent.right === node && + node.parent.operator === '=') { + return node.parent.left; + } + else if (((_c = node.parent) === null || _c === void 0 ? void 0 : _c.type) === 'Property' && + node.parent.value === node && + !node.parent.computed) { + return node.parent.key; + } + else if (((_d = node.parent) === null || _d === void 0 ? void 0 : _d.type) === 'AssignmentPattern' && + node.parent.right === node && + !node.parent.computed) { + return node.parent.left; + } + else { + return undefined; + } + } + else { + return undefined; + } +} +function last(array) { + return array[array.length - 1]; +} + +const rules = { + 'exhaustive-deps': rule$2, + 'react-compiler': rule$1, + 'rules-of-hooks': rule, +}; +const configRules = { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', +}; +const recommendedConfig = { + name: 'react-hooks/recommended', + plugins: { + get 'react-hooks'() { + return plugin; + }, + }, + rules: configRules, +}; +const plugin = { + meta: { name: 'eslint-plugin-react-hooks' }, + rules, + configs: { + 'recommended-legacy': { + plugins: ['react-hooks'], + rules: configRules, + }, + recommended: recommendedConfig, + 'recommended-latest': recommendedConfig, + }, +}; +const configs = plugin.configs; +const meta = plugin.meta; + +exports.configs = configs; +exports.meta = meta; +exports.rules = rules; + })(); +} diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js new file mode 100644 index 0000000000..0657aed593 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js @@ -0,0 +1,60068 @@ +/** + * @license React + * eslint-plugin-react-hooks.production.js + * + * 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. + * @generated SignedSource<> + */ + +'use strict'; + +var core$1 = require('@babel/core'); +var PluginProposalPrivateMethods = require('@babel/plugin-transform-private-methods'); +require('@babel/parser'); +var zod = require('zod'); +var zodValidationError = require('zod-validation-error'); +var crypto = require('crypto'); +var HermesParser = require('hermes-parser'); + +const rule$2 = { + meta: { + type: 'suggestion', + docs: { + description: 'verifies the list of dependencies for Hooks like useEffect and similar', + recommended: true, + url: 'https://github.com/facebook/react/issues/14920', + }, + fixable: 'code', + hasSuggestions: true, + schema: [ + { + type: 'object', + additionalProperties: false, + enableDangerousAutofixThisMayCauseInfiniteLoops: false, + properties: { + additionalHooks: { + type: 'string', + }, + enableDangerousAutofixThisMayCauseInfiniteLoops: { + type: 'boolean', + }, + }, + }, + ], + }, + create(context) { + const additionalHooks = context.options && + context.options[0] && + context.options[0].additionalHooks + ? new RegExp(context.options[0].additionalHooks) + : undefined; + const enableDangerousAutofixThisMayCauseInfiniteLoops = (context.options && + context.options[0] && + context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops) || + false; + const options = { + additionalHooks, + enableDangerousAutofixThisMayCauseInfiniteLoops, + }; + function reportProblem(problem) { + if (enableDangerousAutofixThisMayCauseInfiniteLoops) { + if (Array.isArray(problem.suggest) && + problem.suggest.length > 0 && + problem.suggest[0]) { + problem.fix = problem.suggest[0].fix; + } + } + context.report(problem); + } + const getSourceCode = typeof context.getSourceCode === 'function' + ? () => { + return context.getSourceCode(); + } + : () => { + return context.sourceCode; + }; + const getScope = typeof context.getScope === 'function' + ? () => { + return context.getScope(); + } + : (node) => { + return context.sourceCode.getScope(node); + }; + const scopeManager = getSourceCode().scopeManager; + const setStateCallSites = new WeakMap(); + const stateVariables = new WeakSet(); + const stableKnownValueCache = new WeakMap(); + const functionWithoutCapturedValueCache = new WeakMap(); + const useEffectEventVariables = new WeakSet(); + function memoizeWithWeakMap(fn, map) { + return function (arg) { + if (map.has(arg)) { + return map.get(arg); + } + const result = fn(arg); + map.set(arg, result); + return result; + }; + } + function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect) { + if (isEffect && node.async) { + reportProblem({ + node: node, + message: `Effect callbacks are synchronous to prevent race conditions. ` + + `Put the async function inside:\n\n` + + 'useEffect(() => {\n' + + ' async function fetchData() {\n' + + ' // You can await here\n' + + ' const response = await MyAPI.getData(someId);\n' + + ' // ...\n' + + ' }\n' + + ' fetchData();\n' + + `}, [someId]); // Or [] if effect doesn't need props or state\n\n` + + 'Learn more about data fetching with Hooks: https://react.dev/link/hooks-data-fetching', + }); + } + const scope = scopeManager.acquire(node); + if (!scope) { + throw new Error('Unable to acquire scope for the current node. This is a bug in eslint-plugin-react-hooks, please file an issue.'); + } + const pureScopes = new Set(); + let componentScope = null; + { + let currentScope = scope.upper; + while (currentScope) { + pureScopes.add(currentScope); + if (currentScope.type === 'function') { + break; + } + currentScope = currentScope.upper; + } + if (!currentScope) { + return; + } + componentScope = currentScope; + } + const isArray = Array.isArray; + function isStableKnownHookValue(resolved) { + if (!isArray(resolved.defs)) { + return false; + } + const def = resolved.defs[0]; + if (def == null) { + return false; + } + const defNode = def.node; + if (defNode.type !== 'VariableDeclarator') { + return false; + } + let init = defNode.init; + if (init == null) { + return false; + } + while (init.type === 'TSAsExpression' || init.type === 'AsExpression') { + init = init.expression; + } + let declaration = defNode.parent; + if (declaration == null && componentScope != null) { + fastFindReferenceWithParent(componentScope.block, def.node.id); + declaration = def.node.parent; + if (declaration == null) { + return false; + } + } + if (declaration != null && + 'kind' in declaration && + declaration.kind === 'const' && + init.type === 'Literal' && + (typeof init.value === 'string' || + typeof init.value === 'number' || + init.value === null)) { + return true; + } + if (init.type !== 'CallExpression') { + return false; + } + let callee = init.callee; + if (callee.type === 'MemberExpression' && + 'name' in callee.object && + callee.object.name === 'React' && + callee.property != null && + !callee.computed) { + callee = callee.property; + } + if (callee.type !== 'Identifier') { + return false; + } + const definitionNode = def.node; + const id = definitionNode.id; + const { name } = callee; + if (name === 'useRef' && id.type === 'Identifier') { + return true; + } + else if (isUseEffectEventIdentifier$1(callee) && + id.type === 'Identifier') { + for (const ref of resolved.references) { + if (ref !== id) { + useEffectEventVariables.add(ref.identifier); + } + } + return true; + } + else if (name === 'useState' || + name === 'useReducer' || + name === 'useActionState') { + if (id.type === 'ArrayPattern' && + id.elements.length === 2 && + isArray(resolved.identifiers)) { + if (id.elements[1] === resolved.identifiers[0]) { + if (name === 'useState') { + const references = resolved.references; + let writeCount = 0; + for (const reference of references) { + if (reference.isWrite()) { + writeCount++; + } + if (writeCount > 1) { + return false; + } + setStateCallSites.set(reference.identifier, id.elements[0]); + } + } + return true; + } + else if (id.elements[0] === resolved.identifiers[0]) { + if (name === 'useState') { + const references = resolved.references; + for (const reference of references) { + stateVariables.add(reference.identifier); + } + } + return false; + } + } + } + else if (name === 'useTransition') { + if (id.type === 'ArrayPattern' && + id.elements.length === 2 && + Array.isArray(resolved.identifiers)) { + if (id.elements[1] === resolved.identifiers[0]) { + return true; + } + } + } + return false; + } + function isFunctionWithoutCapturedValues(resolved) { + if (!isArray(resolved.defs)) { + return false; + } + const def = resolved.defs[0]; + if (def == null) { + return false; + } + if (def.node == null || def.node.id == null) { + return false; + } + const fnNode = def.node; + const childScopes = (componentScope === null || componentScope === void 0 ? void 0 : componentScope.childScopes) || []; + let fnScope = null; + for (const childScope of childScopes) { + const childScopeBlock = childScope.block; + if ((fnNode.type === 'FunctionDeclaration' && + childScopeBlock === fnNode) || + (fnNode.type === 'VariableDeclarator' && + childScopeBlock.parent === fnNode)) { + fnScope = childScope; + break; + } + } + if (fnScope == null) { + return false; + } + for (const ref of fnScope.through) { + if (ref.resolved == null) { + continue; + } + if (pureScopes.has(ref.resolved.scope) && + !memoizedIsStableKnownHookValue(ref.resolved)) { + return false; + } + } + return true; + } + const memoizedIsStableKnownHookValue = memoizeWithWeakMap(isStableKnownHookValue, stableKnownValueCache); + const memoizedIsFunctionWithoutCapturedValues = memoizeWithWeakMap(isFunctionWithoutCapturedValues, functionWithoutCapturedValueCache); + const currentRefsInEffectCleanup = new Map(); + function isInsideEffectCleanup(reference) { + let curScope = reference.from; + let isInReturnedFunction = false; + while (curScope != null && curScope.block !== node) { + if (curScope.type === 'function') { + isInReturnedFunction = + curScope.block.parent != null && + curScope.block.parent.type === 'ReturnStatement'; + } + curScope = curScope.upper; + } + return isInReturnedFunction; + } + const dependencies = new Map(); + const optionalChains = new Map(); + gatherDependenciesRecursively(scope); + function gatherDependenciesRecursively(currentScope) { + var _a, _b, _c, _d, _e; + for (const reference of currentScope.references) { + if (!reference.resolved) { + continue; + } + if (!pureScopes.has(reference.resolved.scope)) { + continue; + } + const referenceNode = fastFindReferenceWithParent(node, reference.identifier); + if (referenceNode == null) { + continue; + } + const dependencyNode = getDependency(referenceNode); + const dependency = analyzePropertyChain(dependencyNode, optionalChains); + if (isEffect && + dependencyNode.type === 'Identifier' && + (((_a = dependencyNode.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' || + ((_b = dependencyNode.parent) === null || _b === void 0 ? void 0 : _b.type) === 'OptionalMemberExpression') && + !dependencyNode.parent.computed && + dependencyNode.parent.property.type === 'Identifier' && + dependencyNode.parent.property.name === 'current' && + isInsideEffectCleanup(reference)) { + currentRefsInEffectCleanup.set(dependency, { + reference, + dependencyNode, + }); + } + if (((_c = dependencyNode.parent) === null || _c === void 0 ? void 0 : _c.type) === 'TSTypeQuery' || + ((_d = dependencyNode.parent) === null || _d === void 0 ? void 0 : _d.type) === 'TSTypeReference') { + continue; + } + const def = reference.resolved.defs[0]; + if (def == null) { + continue; + } + if (def.node != null && def.node.init === node.parent) { + continue; + } + if (def.type === 'TypeParameter') { + continue; + } + if (!dependencies.has(dependency)) { + const resolved = reference.resolved; + const isStable = memoizedIsStableKnownHookValue(resolved) || + memoizedIsFunctionWithoutCapturedValues(resolved); + dependencies.set(dependency, { + isStable, + references: [reference], + }); + } + else { + (_e = dependencies.get(dependency)) === null || _e === void 0 ? void 0 : _e.references.push(reference); + } + } + for (const childScope of currentScope.childScopes) { + gatherDependenciesRecursively(childScope); + } + } + currentRefsInEffectCleanup.forEach(({ reference, dependencyNode }, dependency) => { + var _a, _b; + const references = ((_a = reference.resolved) === null || _a === void 0 ? void 0 : _a.references) || []; + let foundCurrentAssignment = false; + for (const ref of references) { + const { identifier } = ref; + const { parent } = identifier; + if (parent != null && + parent.type === 'MemberExpression' && + !parent.computed && + parent.property.type === 'Identifier' && + parent.property.name === 'current' && + ((_b = parent.parent) === null || _b === void 0 ? void 0 : _b.type) === 'AssignmentExpression' && + parent.parent.left === parent) { + foundCurrentAssignment = true; + break; + } + } + if (foundCurrentAssignment) { + return; + } + reportProblem({ + node: dependencyNode.parent.property, + message: `The ref value '${dependency}.current' will likely have ` + + `changed by the time this effect cleanup function runs. If ` + + `this ref points to a node rendered by React, copy ` + + `'${dependency}.current' to a variable inside the effect, and ` + + `use that variable in the cleanup function.`, + }); + }); + const staleAssignments = new Set(); + function reportStaleAssignment(writeExpr, key) { + if (staleAssignments.has(key)) { + return; + } + staleAssignments.add(key); + reportProblem({ + node: writeExpr, + message: `Assignments to the '${key}' variable from inside React Hook ` + + `${getSourceCode().getText(reactiveHook)} will be lost after each ` + + `render. To preserve the value over time, store it in a useRef ` + + `Hook and keep the mutable value in the '.current' property. ` + + `Otherwise, you can move this variable directly inside ` + + `${getSourceCode().getText(reactiveHook)}.`, + }); + } + const stableDependencies = new Set(); + dependencies.forEach(({ isStable, references }, key) => { + if (isStable) { + stableDependencies.add(key); + } + references.forEach(reference => { + if (reference.writeExpr) { + reportStaleAssignment(reference.writeExpr, key); + } + }); + }); + if (staleAssignments.size > 0) { + return; + } + if (!declaredDependenciesNode) { + let setStateInsideEffectWithoutDeps = null; + dependencies.forEach(({ references }, key) => { + if (setStateInsideEffectWithoutDeps) { + return; + } + references.forEach(reference => { + if (setStateInsideEffectWithoutDeps) { + return; + } + const id = reference.identifier; + const isSetState = setStateCallSites.has(id); + if (!isSetState) { + return; + } + let fnScope = reference.from; + while (fnScope != null && fnScope.type !== 'function') { + fnScope = fnScope.upper; + } + const isDirectlyInsideEffect = (fnScope === null || fnScope === void 0 ? void 0 : fnScope.block) === node; + if (isDirectlyInsideEffect) { + setStateInsideEffectWithoutDeps = key; + } + }); + }); + if (setStateInsideEffectWithoutDeps) { + const { suggestedDependencies } = collectRecommendations({ + dependencies, + declaredDependencies: [], + stableDependencies, + externalDependencies: new Set(), + isEffect: true, + }); + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} contains a call to '${setStateInsideEffectWithoutDeps}'. ` + + `Without a list of dependencies, this can lead to an infinite chain of updates. ` + + `To fix this, pass [` + + suggestedDependencies.join(', ') + + `] as a second argument to the ${reactiveHookName} Hook.`, + suggest: [ + { + desc: `Add dependencies array: [${suggestedDependencies.join(', ')}]`, + fix(fixer) { + return fixer.insertTextAfter(node, `, [${suggestedDependencies.join(', ')}]`); + }, + }, + ], + }); + } + return; + } + const declaredDependencies = []; + const externalDependencies = new Set(); + const isArrayExpression = declaredDependenciesNode.type === 'ArrayExpression'; + const isTSAsArrayExpression = declaredDependenciesNode.type === 'TSAsExpression' && + declaredDependenciesNode.expression.type === 'ArrayExpression'; + if (!isArrayExpression && !isTSAsArrayExpression) { + reportProblem({ + node: declaredDependenciesNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} was passed a ` + + 'dependency list that is not an array literal. This means we ' + + "can't statically verify whether you've passed the correct " + + 'dependencies.', + }); + } + else { + const arrayExpression = isTSAsArrayExpression + ? declaredDependenciesNode.expression + : declaredDependenciesNode; + arrayExpression.elements.forEach(declaredDependencyNode => { + if (declaredDependencyNode === null) { + return; + } + if (declaredDependencyNode.type === 'SpreadElement') { + reportProblem({ + node: declaredDependencyNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has a spread ` + + "element in its dependency array. This means we can't " + + "statically verify whether you've passed the " + + 'correct dependencies.', + }); + return; + } + if (useEffectEventVariables.has(declaredDependencyNode)) { + reportProblem({ + node: declaredDependencyNode, + message: 'Functions returned from `useEffectEvent` must not be included in the dependency array. ' + + `Remove \`${getSourceCode().getText(declaredDependencyNode)}\` from the list.`, + suggest: [ + { + desc: `Remove the dependency \`${getSourceCode().getText(declaredDependencyNode)}\``, + fix(fixer) { + return fixer.removeRange(declaredDependencyNode.range); + }, + }, + ], + }); + } + let declaredDependency; + try { + declaredDependency = analyzePropertyChain(declaredDependencyNode, null); + } + catch (error) { + if (error instanceof Error && + /Unsupported node type/.test(error.message)) { + if (declaredDependencyNode.type === 'Literal') { + if (declaredDependencyNode.value && + dependencies.has(declaredDependencyNode.value)) { + reportProblem({ + node: declaredDependencyNode, + message: `The ${declaredDependencyNode.raw} literal is not a valid dependency ` + + `because it never changes. ` + + `Did you mean to include ${declaredDependencyNode.value} in the array instead?`, + }); + } + else { + reportProblem({ + node: declaredDependencyNode, + message: `The ${declaredDependencyNode.raw} literal is not a valid dependency ` + + 'because it never changes. You can safely remove it.', + }); + } + } + else { + reportProblem({ + node: declaredDependencyNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has a ` + + `complex expression in the dependency array. ` + + 'Extract it to a separate variable so it can be statically checked.', + }); + } + return; + } + else { + throw error; + } + } + let maybeID = declaredDependencyNode; + while (maybeID.type === 'MemberExpression' || + maybeID.type === 'OptionalMemberExpression' || + maybeID.type === 'ChainExpression') { + maybeID = maybeID.object || maybeID.expression.object; + } + const isDeclaredInComponent = !componentScope.through.some(ref => ref.identifier === maybeID); + declaredDependencies.push({ + key: declaredDependency, + node: declaredDependencyNode, + }); + if (!isDeclaredInComponent) { + externalDependencies.add(declaredDependency); + } + }); + } + const { suggestedDependencies, unnecessaryDependencies, missingDependencies, duplicateDependencies, } = collectRecommendations({ + dependencies, + declaredDependencies, + stableDependencies, + externalDependencies, + isEffect, + }); + let suggestedDeps = suggestedDependencies; + const problemCount = duplicateDependencies.size + + missingDependencies.size + + unnecessaryDependencies.size; + if (problemCount === 0) { + const constructions = scanForConstructions({ + declaredDependencies, + declaredDependenciesNode, + componentScope, + scope, + }); + constructions.forEach(({ construction, isUsedOutsideOfHook, depType }) => { + var _a; + const wrapperHook = depType === 'function' ? 'useCallback' : 'useMemo'; + const constructionType = depType === 'function' ? 'definition' : 'initialization'; + const defaultAdvice = `wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`; + const advice = isUsedOutsideOfHook + ? `To fix this, ${defaultAdvice}` + : `Move it inside the ${reactiveHookName} callback. Alternatively, ${defaultAdvice}`; + const causation = depType === 'conditional' || depType === 'logical expression' + ? 'could make' + : 'makes'; + const message = `The '${construction.name.name}' ${depType} ${causation} the dependencies of ` + + `${reactiveHookName} Hook (at line ${(_a = declaredDependenciesNode.loc) === null || _a === void 0 ? void 0 : _a.start.line}) ` + + `change on every render. ${advice}`; + let suggest; + if (isUsedOutsideOfHook && + construction.type === 'Variable' && + depType === 'function') { + suggest = [ + { + desc: `Wrap the ${constructionType} of '${construction.name.name}' in its own ${wrapperHook}() Hook.`, + fix(fixer) { + const [before, after] = wrapperHook === 'useMemo' + ? [`useMemo(() => { return `, '; })'] + : ['useCallback(', ')']; + return [ + fixer.insertTextBefore(construction.node.init, before), + fixer.insertTextAfter(construction.node.init, after), + ]; + }, + }, + ]; + } + reportProblem({ + node: construction.node, + message, + suggest, + }); + }); + return; + } + if (!isEffect && missingDependencies.size > 0) { + suggestedDeps = collectRecommendations({ + dependencies, + declaredDependencies: [], + stableDependencies, + externalDependencies, + isEffect, + }).suggestedDependencies; + } + function areDeclaredDepsAlphabetized() { + if (declaredDependencies.length === 0) { + return true; + } + const declaredDepKeys = declaredDependencies.map(dep => dep.key); + const sortedDeclaredDepKeys = declaredDepKeys.slice().sort(); + return declaredDepKeys.join(',') === sortedDeclaredDepKeys.join(','); + } + if (areDeclaredDepsAlphabetized()) { + suggestedDeps.sort(); + } + function formatDependency(path) { + const members = path.split('.'); + let finalPath = ''; + for (let i = 0; i < members.length; i++) { + if (i !== 0) { + const pathSoFar = members.slice(0, i + 1).join('.'); + const isOptional = optionalChains.get(pathSoFar) === true; + finalPath += isOptional ? '?.' : '.'; + } + finalPath += members[i]; + } + return finalPath; + } + function getWarningMessage(deps, singlePrefix, label, fixVerb) { + if (deps.size === 0) { + return null; + } + return ((deps.size > 1 ? '' : singlePrefix + ' ') + + label + + ' ' + + (deps.size > 1 ? 'dependencies' : 'dependency') + + ': ' + + joinEnglish(Array.from(deps) + .sort() + .map(name => "'" + formatDependency(name) + "'")) + + `. Either ${fixVerb} ${deps.size > 1 ? 'them' : 'it'} or remove the dependency array.`); + } + let extraWarning = ''; + if (unnecessaryDependencies.size > 0) { + let badRef = null; + Array.from(unnecessaryDependencies.keys()).forEach(key => { + if (badRef !== null) { + return; + } + if (key.endsWith('.current')) { + badRef = key; + } + }); + if (badRef !== null) { + extraWarning = + ` Mutable values like '${badRef}' aren't valid dependencies ` + + "because mutating them doesn't re-render the component."; + } + else if (externalDependencies.size > 0) { + const dep = Array.from(externalDependencies)[0]; + if (!scope.set.has(dep)) { + extraWarning = + ` Outer scope values like '${dep}' aren't valid dependencies ` + + `because mutating them doesn't re-render the component.`; + } + } + } + if (!extraWarning && missingDependencies.has('props')) { + const propDep = dependencies.get('props'); + if (propDep == null) { + return; + } + const refs = propDep.references; + if (!Array.isArray(refs)) { + return; + } + let isPropsOnlyUsedInMembers = true; + for (const ref of refs) { + const id = fastFindReferenceWithParent(componentScope.block, ref.identifier); + if (!id) { + isPropsOnlyUsedInMembers = false; + break; + } + const parent = id.parent; + if (parent == null) { + isPropsOnlyUsedInMembers = false; + break; + } + if (parent.type !== 'MemberExpression' && + parent.type !== 'OptionalMemberExpression') { + isPropsOnlyUsedInMembers = false; + break; + } + } + if (isPropsOnlyUsedInMembers) { + extraWarning = + ` However, 'props' will change when *any* prop changes, so the ` + + `preferred fix is to destructure the 'props' object outside of ` + + `the ${reactiveHookName} call and refer to those specific props ` + + `inside ${getSourceCode().getText(reactiveHook)}.`; + } + } + if (!extraWarning && missingDependencies.size > 0) { + let missingCallbackDep = null; + missingDependencies.forEach(missingDep => { + var _a; + if (missingCallbackDep) { + return; + } + const topScopeRef = componentScope.set.get(missingDep); + const usedDep = dependencies.get(missingDep); + if (!(usedDep === null || usedDep === void 0 ? void 0 : usedDep.references) || + ((_a = usedDep === null || usedDep === void 0 ? void 0 : usedDep.references[0]) === null || _a === void 0 ? void 0 : _a.resolved) !== topScopeRef) { + return; + } + const def = topScopeRef === null || topScopeRef === void 0 ? void 0 : topScopeRef.defs[0]; + if (def == null || def.name == null || def.type !== 'Parameter') { + return; + } + let isFunctionCall = false; + let id; + for (const reference of usedDep.references) { + id = reference.identifier; + if (id != null && + id.parent != null && + (id.parent.type === 'CallExpression' || + id.parent.type === 'OptionalCallExpression') && + id.parent.callee === id) { + isFunctionCall = true; + break; + } + } + if (!isFunctionCall) { + return; + } + missingCallbackDep = missingDep; + }); + if (missingCallbackDep !== null) { + extraWarning = + ` If '${missingCallbackDep}' changes too often, ` + + `find the parent component that defines it ` + + `and wrap that definition in useCallback.`; + } + } + if (!extraWarning && missingDependencies.size > 0) { + let setStateRecommendation = null; + for (const missingDep of missingDependencies) { + if (setStateRecommendation !== null) { + break; + } + const usedDep = dependencies.get(missingDep); + const references = usedDep.references; + let id; + let maybeCall; + for (const reference of references) { + id = reference.identifier; + maybeCall = id.parent; + while (maybeCall != null && maybeCall !== componentScope.block) { + if (maybeCall.type === 'CallExpression') { + const correspondingStateVariable = setStateCallSites.get(maybeCall.callee); + if (correspondingStateVariable != null) { + if ('name' in correspondingStateVariable && + correspondingStateVariable.name === missingDep) { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee ? maybeCall.callee.name : '', + form: 'updater', + }; + } + else if (stateVariables.has(id)) { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee ? maybeCall.callee.name : '', + form: 'reducer', + }; + } + else { + const resolved = reference.resolved; + if (resolved != null) { + const def = resolved.defs[0]; + if (def != null && def.type === 'Parameter') { + setStateRecommendation = { + missingDep, + setter: 'name' in maybeCall.callee + ? maybeCall.callee.name + : '', + form: 'inlineReducer', + }; + } + } + } + break; + } + } + maybeCall = maybeCall.parent; + } + if (setStateRecommendation !== null) { + break; + } + } + } + if (setStateRecommendation !== null) { + switch (setStateRecommendation.form) { + case 'reducer': + extraWarning = + ` You can also replace multiple useState variables with useReducer ` + + `if '${setStateRecommendation.setter}' needs the ` + + `current value of '${setStateRecommendation.missingDep}'.`; + break; + case 'inlineReducer': + extraWarning = + ` If '${setStateRecommendation.setter}' needs the ` + + `current value of '${setStateRecommendation.missingDep}', ` + + `you can also switch to useReducer instead of useState and ` + + `read '${setStateRecommendation.missingDep}' in the reducer.`; + break; + case 'updater': + extraWarning = + ` You can also do a functional update '${setStateRecommendation.setter}(${setStateRecommendation.missingDep.slice(0, 1)} => ...)' if you only need '${setStateRecommendation.missingDep}'` + ` in the '${setStateRecommendation.setter}' call.`; + break; + default: + throw new Error('Unknown case.'); + } + } + } + reportProblem({ + node: declaredDependenciesNode, + message: `React Hook ${getSourceCode().getText(reactiveHook)} has ` + + (getWarningMessage(missingDependencies, 'a', 'missing', 'include') || + getWarningMessage(unnecessaryDependencies, 'an', 'unnecessary', 'exclude') || + getWarningMessage(duplicateDependencies, 'a', 'duplicate', 'omit')) + + extraWarning, + suggest: [ + { + desc: `Update the dependencies array to be: [${suggestedDeps + .map(formatDependency) + .join(', ')}]`, + fix(fixer) { + return fixer.replaceText(declaredDependenciesNode, `[${suggestedDeps.map(formatDependency).join(', ')}]`); + }, + }, + ], + }); + } + function visitCallExpression(node) { + const callbackIndex = getReactiveHookCallbackIndex(node.callee, options); + if (callbackIndex === -1) { + return; + } + let callback = node.arguments[callbackIndex]; + const reactiveHook = node.callee; + const nodeWithoutNamespace = getNodeWithoutReactNamespace(reactiveHook); + const reactiveHookName = 'name' in nodeWithoutNamespace ? nodeWithoutNamespace.name : ''; + const maybeNode = node.arguments[callbackIndex + 1]; + const declaredDependenciesNode = maybeNode && + !(maybeNode.type === 'Identifier' && maybeNode.name === 'undefined') + ? maybeNode + : undefined; + const isEffect = /Effect($|[^a-z])/g.test(reactiveHookName); + if (!callback) { + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} requires an effect callback. ` + + `Did you forget to pass a callback to the hook?`, + }); + return; + } + if (!declaredDependenciesNode && !isEffect) { + if (reactiveHookName === 'useMemo' || + reactiveHookName === 'useCallback') { + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} does nothing when called with ` + + `only one argument. Did you forget to pass an array of ` + + `dependencies?`, + }); + } + return; + } + while (callback.type === 'TSAsExpression' || + callback.type === 'AsExpression') { + callback = callback.expression; + } + switch (callback.type) { + case 'FunctionExpression': + case 'ArrowFunctionExpression': + visitFunctionWithDependencies(callback, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + case 'Identifier': + if (!declaredDependenciesNode) { + return; + } + if ('elements' in declaredDependenciesNode && + declaredDependenciesNode.elements && + declaredDependenciesNode.elements.some(el => el && el.type === 'Identifier' && el.name === callback.name)) { + return; + } + const variable = getScope(callback).set.get(callback.name); + if (variable == null || variable.defs == null) { + return; + } + const def = variable.defs[0]; + if (!def || !def.node) { + break; + } + if (def.type === 'Parameter') { + reportProblem({ + node: reactiveHook, + message: getUnknownDependenciesMessage(reactiveHookName), + }); + return; + } + if (def.type !== 'Variable' && def.type !== 'FunctionName') { + break; + } + switch (def.node.type) { + case 'FunctionDeclaration': + visitFunctionWithDependencies(def.node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + case 'VariableDeclarator': + const init = def.node.init; + if (!init) { + break; + } + switch (init.type) { + case 'ArrowFunctionExpression': + case 'FunctionExpression': + visitFunctionWithDependencies(init, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect); + return; + } + break; + } + break; + default: + reportProblem({ + node: reactiveHook, + message: getUnknownDependenciesMessage(reactiveHookName), + }); + return; + } + reportProblem({ + node: reactiveHook, + message: `React Hook ${reactiveHookName} has a missing dependency: '${callback.name}'. ` + + `Either include it or remove the dependency array.`, + suggest: [ + { + desc: `Update the dependencies array to be: [${callback.name}]`, + fix(fixer) { + return fixer.replaceText(declaredDependenciesNode, `[${callback.name}]`); + }, + }, + ], + }); + } + return { + CallExpression: visitCallExpression, + }; + }, +}; +function collectRecommendations({ dependencies, declaredDependencies, stableDependencies, externalDependencies, isEffect, }) { + const depTree = createDepTree(); + function createDepTree() { + return { + isUsed: false, + isSatisfiedRecursively: false, + isSubtreeUsed: false, + children: new Map(), + }; + } + dependencies.forEach((_, key) => { + const node = getOrCreateNodeByPath(depTree, key); + node.isUsed = true; + markAllParentsByPath(depTree, key, parent => { + parent.isSubtreeUsed = true; + }); + }); + declaredDependencies.forEach(({ key }) => { + const node = getOrCreateNodeByPath(depTree, key); + node.isSatisfiedRecursively = true; + }); + stableDependencies.forEach(key => { + const node = getOrCreateNodeByPath(depTree, key); + node.isSatisfiedRecursively = true; + }); + function getOrCreateNodeByPath(rootNode, path) { + const keys = path.split('.'); + let node = rootNode; + for (const key of keys) { + let child = node.children.get(key); + if (!child) { + child = createDepTree(); + node.children.set(key, child); + } + node = child; + } + return node; + } + function markAllParentsByPath(rootNode, path, fn) { + const keys = path.split('.'); + let node = rootNode; + for (const key of keys) { + const child = node.children.get(key); + if (!child) { + return; + } + fn(child); + node = child; + } + } + const missingDependencies = new Set(); + const satisfyingDependencies = new Set(); + scanTreeRecursively(depTree, missingDependencies, satisfyingDependencies, key => key); + function scanTreeRecursively(node, missingPaths, satisfyingPaths, keyToPath) { + node.children.forEach((child, key) => { + const path = keyToPath(key); + if (child.isSatisfiedRecursively) { + if (child.isSubtreeUsed) { + satisfyingPaths.add(path); + } + return; + } + if (child.isUsed) { + missingPaths.add(path); + return; + } + scanTreeRecursively(child, missingPaths, satisfyingPaths, childKey => path + '.' + childKey); + }); + } + const suggestedDependencies = []; + const unnecessaryDependencies = new Set(); + const duplicateDependencies = new Set(); + declaredDependencies.forEach(({ key }) => { + if (satisfyingDependencies.has(key)) { + if (suggestedDependencies.indexOf(key) === -1) { + suggestedDependencies.push(key); + } + else { + duplicateDependencies.add(key); + } + } + else { + if (isEffect && + !key.endsWith('.current') && + !externalDependencies.has(key)) { + if (suggestedDependencies.indexOf(key) === -1) { + suggestedDependencies.push(key); + } + } + else { + unnecessaryDependencies.add(key); + } + } + }); + missingDependencies.forEach(key => { + suggestedDependencies.push(key); + }); + return { + suggestedDependencies, + unnecessaryDependencies, + duplicateDependencies, + missingDependencies, + }; +} +function getConstructionExpressionType(node) { + switch (node.type) { + case 'ObjectExpression': + return 'object'; + case 'ArrayExpression': + return 'array'; + case 'ArrowFunctionExpression': + case 'FunctionExpression': + return 'function'; + case 'ClassExpression': + return 'class'; + case 'ConditionalExpression': + if (getConstructionExpressionType(node.consequent) != null || + getConstructionExpressionType(node.alternate) != null) { + return 'conditional'; + } + return null; + case 'LogicalExpression': + if (getConstructionExpressionType(node.left) != null || + getConstructionExpressionType(node.right) != null) { + return 'logical expression'; + } + return null; + case 'JSXFragment': + return 'JSX fragment'; + case 'JSXElement': + return 'JSX element'; + case 'AssignmentExpression': + if (getConstructionExpressionType(node.right) != null) { + return 'assignment expression'; + } + return null; + case 'NewExpression': + return 'object construction'; + case 'Literal': + if (node.value instanceof RegExp) { + return 'regular expression'; + } + return null; + case 'TypeCastExpression': + case 'AsExpression': + case 'TSAsExpression': + return getConstructionExpressionType(node.expression); + } + return null; +} +function scanForConstructions({ declaredDependencies, declaredDependenciesNode, componentScope, scope, }) { + const constructions = declaredDependencies + .map(({ key }) => { + const ref = componentScope.variables.find(v => v.name === key); + if (ref == null) { + return null; + } + const node = ref.defs[0]; + if (node == null) { + return null; + } + if (node.type === 'Variable' && + node.node.type === 'VariableDeclarator' && + node.node.id.type === 'Identifier' && + node.node.init != null) { + const constantExpressionType = getConstructionExpressionType(node.node.init); + if (constantExpressionType) { + return [ref, constantExpressionType]; + } + } + if (node.type === 'FunctionName' && + node.node.type === 'FunctionDeclaration') { + return [ref, 'function']; + } + if (node.type === 'ClassName' && node.node.type === 'ClassDeclaration') { + return [ref, 'class']; + } + return null; + }) + .filter(Boolean); + function isUsedOutsideOfHook(ref) { + let foundWriteExpr = false; + for (const reference of ref.references) { + if (reference.writeExpr) { + if (foundWriteExpr) { + return true; + } + else { + foundWriteExpr = true; + continue; + } + } + let currentScope = reference.from; + while (currentScope !== scope && currentScope != null) { + currentScope = currentScope.upper; + } + if (currentScope !== scope) { + if (!isAncestorNodeOf(declaredDependenciesNode, reference.identifier)) { + return true; + } + } + } + return false; + } + return constructions.map(([ref, depType]) => ({ + construction: ref.defs[0], + depType, + isUsedOutsideOfHook: isUsedOutsideOfHook(ref), + })); +} +function getDependency(node) { + if (node.parent && + (node.parent.type === 'MemberExpression' || + node.parent.type === 'OptionalMemberExpression') && + node.parent.object === node && + 'name' in node.parent.property && + node.parent.property.name !== 'current' && + !node.parent.computed && + !(node.parent.parent != null && + (node.parent.parent.type === 'CallExpression' || + node.parent.parent.type === 'OptionalCallExpression') && + node.parent.parent.callee === node.parent)) { + return getDependency(node.parent); + } + else if (node.type === 'MemberExpression' && + node.parent && + node.parent.type === 'AssignmentExpression' && + node.parent.left === node) { + return node.object; + } + else { + return node; + } +} +function markNode(node, optionalChains, result) { + if (optionalChains) { + if ('optional' in node && node.optional) { + if (!optionalChains.has(result)) { + optionalChains.set(result, true); + } + } + else { + optionalChains.set(result, false); + } + } +} +function analyzePropertyChain(node, optionalChains) { + if (node.type === 'Identifier' || node.type === 'JSXIdentifier') { + const result = node.name; + if (optionalChains) { + optionalChains.set(result, false); + } + return result; + } + else if (node.type === 'MemberExpression' && !node.computed) { + const object = analyzePropertyChain(node.object, optionalChains); + const property = analyzePropertyChain(node.property, null); + const result = `${object}.${property}`; + markNode(node, optionalChains, result); + return result; + } + else if (node.type === 'OptionalMemberExpression' && !node.computed) { + const object = analyzePropertyChain(node.object, optionalChains); + const property = analyzePropertyChain(node.property, null); + const result = `${object}.${property}`; + markNode(node, optionalChains, result); + return result; + } + else if (node.type === 'ChainExpression' && + (!('computed' in node) || !node.computed)) { + const expression = node.expression; + if (expression.type === 'CallExpression') { + throw new Error(`Unsupported node type: ${expression.type}`); + } + const object = analyzePropertyChain(expression.object, optionalChains); + const property = analyzePropertyChain(expression.property, null); + const result = `${object}.${property}`; + markNode(expression, optionalChains, result); + return result; + } + else { + throw new Error(`Unsupported node type: ${node.type}`); + } +} +function getNodeWithoutReactNamespace(node) { + if (node.type === 'MemberExpression' && + node.object.type === 'Identifier' && + node.object.name === 'React' && + node.property.type === 'Identifier' && + !node.computed) { + return node.property; + } + return node; +} +function getReactiveHookCallbackIndex(calleeNode, options) { + const node = getNodeWithoutReactNamespace(calleeNode); + if (node.type !== 'Identifier') { + return -1; + } + switch (node.name) { + case 'useEffect': + case 'useLayoutEffect': + case 'useCallback': + case 'useMemo': + return 0; + case 'useImperativeHandle': + return 1; + default: + if (node === calleeNode && options && options.additionalHooks) { + let name; + try { + name = analyzePropertyChain(node, null); + } + catch (error) { + if (error instanceof Error && + /Unsupported node type/.test(error.message)) { + return 0; + } + else { + throw error; + } + } + return options.additionalHooks.test(name) ? 0 : -1; + } + else { + return -1; + } + } +} +function fastFindReferenceWithParent(start, target) { + const queue = [start]; + let item; + while (queue.length) { + item = queue.shift(); + if (isSameIdentifier(item, target)) { + return item; + } + if (!isAncestorNodeOf(item, target)) { + continue; + } + for (const [key, value] of Object.entries(item)) { + if (key === 'parent') { + continue; + } + if (isNodeLike(value)) { + value.parent = item; + queue.push(value); + } + else if (Array.isArray(value)) { + value.forEach(val => { + if (isNodeLike(val)) { + val.parent = item; + queue.push(val); + } + }); + } + } + } + return null; +} +function joinEnglish(arr) { + let s = ''; + for (let i = 0; i < arr.length; i++) { + s += arr[i]; + if (i === 0 && arr.length === 2) { + s += ' and '; + } + else if (i === arr.length - 2 && arr.length > 2) { + s += ', and '; + } + else if (i < arr.length - 1) { + s += ', '; + } + } + return s; +} +function isNodeLike(val) { + return (typeof val === 'object' && + val !== null && + !Array.isArray(val) && + 'type' in val && + typeof val.type === 'string'); +} +function isSameIdentifier(a, b) { + return ((a.type === 'Identifier' || a.type === 'JSXIdentifier') && + a.type === b.type && + a.name === b.name && + !!a.range && + !!b.range && + a.range[0] === b.range[0] && + a.range[1] === b.range[1]); +} +function isAncestorNodeOf(a, b) { + return (!!a.range && + !!b.range && + a.range[0] <= b.range[0] && + a.range[1] >= b.range[1]); +} +function isUseEffectEventIdentifier$1(node) { + { + return node.type === 'Identifier' && node.name === 'useEffectEvent'; + } +} +function getUnknownDependenciesMessage(reactiveHookName) { + return (`React Hook ${reactiveHookName} received a function whose dependencies ` + + `are unknown. Pass an inline function instead.`); +} + +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; +} + +var invariant_1; +var hasRequiredInvariant; + +function requireInvariant () { + if (hasRequiredInvariant) return invariant_1; + hasRequiredInvariant = 1; + + var invariant = function(condition, format, a, b, c, d, e, f) { + + if (!condition) { + var error; + if (format === undefined) { + error = new Error( + 'Minified exception occurred; use the non-minified dev environment ' + + 'for the full error message and additional helpful warnings.' + ); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error( + format.replace(/%s/g, function() { return args[argIndex++]; }) + ); + error.name = 'Invariant Violation'; + } + + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; + } + }; + + invariant_1 = invariant; + return invariant_1; +} + +var invariantExports = requireInvariant(); +var invariant = /*@__PURE__*/getDefaultExportFromCjs(invariantExports); + +var lib$3 = {}; + +var isReactComponent = {}; + +var buildMatchMemberExpression = {}; + +var matchesPattern = {}; + +var generated$3 = {}; + +var shallowEqual = {}; + +var hasRequiredShallowEqual; + +function requireShallowEqual () { + if (hasRequiredShallowEqual) return shallowEqual; + hasRequiredShallowEqual = 1; + + Object.defineProperty(shallowEqual, "__esModule", { + value: true + }); + shallowEqual.default = shallowEqual$1; + function shallowEqual$1(actual, expected) { + const keys = Object.keys(expected); + for (const key of keys) { + if (actual[key] !== expected[key]) { + return false; + } + } + return true; + } + + + return shallowEqual; +} + +var deprecationWarning = {}; + +var hasRequiredDeprecationWarning; + +function requireDeprecationWarning () { + if (hasRequiredDeprecationWarning) return deprecationWarning; + hasRequiredDeprecationWarning = 1; + + Object.defineProperty(deprecationWarning, "__esModule", { + value: true + }); + deprecationWarning.default = deprecationWarning$1; + const warnings = new Set(); + function deprecationWarning$1(oldName, newName, prefix = "") { + if (warnings.has(oldName)) return; + warnings.add(oldName); + const { + internal, + trace + } = captureShortStackTrace(1, 2); + if (internal) { + return; + } + console.warn(`${prefix}\`${oldName}\` has been deprecated, please migrate to \`${newName}\`\n${trace}`); + } + function captureShortStackTrace(skip, length) { + const { + stackTraceLimit, + prepareStackTrace + } = Error; + let stackTrace; + Error.stackTraceLimit = 1 + skip + length; + Error.prepareStackTrace = function (err, stack) { + stackTrace = stack; + }; + Error.stackTraceLimit = stackTraceLimit; + Error.prepareStackTrace = prepareStackTrace; + if (!stackTrace) return { + internal: false, + trace: "" + }; + const shortStackTrace = stackTrace.slice(1 + skip, 1 + skip + length); + return { + internal: /[\\/]@babel[\\/]/.test(shortStackTrace[1].getFileName()), + trace: shortStackTrace.map(frame => ` at ${frame}`).join("\n") + }; + } + + + return deprecationWarning; +} + +var hasRequiredGenerated$3; + +function requireGenerated$3 () { + if (hasRequiredGenerated$3) return generated$3; + hasRequiredGenerated$3 = 1; + + Object.defineProperty(generated$3, "__esModule", { + value: true + }); + generated$3.isAccessor = isAccessor; + generated$3.isAnyTypeAnnotation = isAnyTypeAnnotation; + generated$3.isArgumentPlaceholder = isArgumentPlaceholder; + generated$3.isArrayExpression = isArrayExpression; + generated$3.isArrayPattern = isArrayPattern; + generated$3.isArrayTypeAnnotation = isArrayTypeAnnotation; + generated$3.isArrowFunctionExpression = isArrowFunctionExpression; + generated$3.isAssignmentExpression = isAssignmentExpression; + generated$3.isAssignmentPattern = isAssignmentPattern; + generated$3.isAwaitExpression = isAwaitExpression; + generated$3.isBigIntLiteral = isBigIntLiteral; + generated$3.isBinary = isBinary; + generated$3.isBinaryExpression = isBinaryExpression; + generated$3.isBindExpression = isBindExpression; + generated$3.isBlock = isBlock; + generated$3.isBlockParent = isBlockParent; + generated$3.isBlockStatement = isBlockStatement; + generated$3.isBooleanLiteral = isBooleanLiteral; + generated$3.isBooleanLiteralTypeAnnotation = isBooleanLiteralTypeAnnotation; + generated$3.isBooleanTypeAnnotation = isBooleanTypeAnnotation; + generated$3.isBreakStatement = isBreakStatement; + generated$3.isCallExpression = isCallExpression; + generated$3.isCatchClause = isCatchClause; + generated$3.isClass = isClass; + generated$3.isClassAccessorProperty = isClassAccessorProperty; + generated$3.isClassBody = isClassBody; + generated$3.isClassDeclaration = isClassDeclaration; + generated$3.isClassExpression = isClassExpression; + generated$3.isClassImplements = isClassImplements; + generated$3.isClassMethod = isClassMethod; + generated$3.isClassPrivateMethod = isClassPrivateMethod; + generated$3.isClassPrivateProperty = isClassPrivateProperty; + generated$3.isClassProperty = isClassProperty; + generated$3.isCompletionStatement = isCompletionStatement; + generated$3.isConditional = isConditional; + generated$3.isConditionalExpression = isConditionalExpression; + generated$3.isContinueStatement = isContinueStatement; + generated$3.isDebuggerStatement = isDebuggerStatement; + generated$3.isDecimalLiteral = isDecimalLiteral; + generated$3.isDeclaration = isDeclaration; + generated$3.isDeclareClass = isDeclareClass; + generated$3.isDeclareExportAllDeclaration = isDeclareExportAllDeclaration; + generated$3.isDeclareExportDeclaration = isDeclareExportDeclaration; + generated$3.isDeclareFunction = isDeclareFunction; + generated$3.isDeclareInterface = isDeclareInterface; + generated$3.isDeclareModule = isDeclareModule; + generated$3.isDeclareModuleExports = isDeclareModuleExports; + generated$3.isDeclareOpaqueType = isDeclareOpaqueType; + generated$3.isDeclareTypeAlias = isDeclareTypeAlias; + generated$3.isDeclareVariable = isDeclareVariable; + generated$3.isDeclaredPredicate = isDeclaredPredicate; + generated$3.isDecorator = isDecorator; + generated$3.isDirective = isDirective; + generated$3.isDirectiveLiteral = isDirectiveLiteral; + generated$3.isDoExpression = isDoExpression; + generated$3.isDoWhileStatement = isDoWhileStatement; + generated$3.isEmptyStatement = isEmptyStatement; + generated$3.isEmptyTypeAnnotation = isEmptyTypeAnnotation; + generated$3.isEnumBody = isEnumBody; + generated$3.isEnumBooleanBody = isEnumBooleanBody; + generated$3.isEnumBooleanMember = isEnumBooleanMember; + generated$3.isEnumDeclaration = isEnumDeclaration; + generated$3.isEnumDefaultedMember = isEnumDefaultedMember; + generated$3.isEnumMember = isEnumMember; + generated$3.isEnumNumberBody = isEnumNumberBody; + generated$3.isEnumNumberMember = isEnumNumberMember; + generated$3.isEnumStringBody = isEnumStringBody; + generated$3.isEnumStringMember = isEnumStringMember; + generated$3.isEnumSymbolBody = isEnumSymbolBody; + generated$3.isExistsTypeAnnotation = isExistsTypeAnnotation; + generated$3.isExportAllDeclaration = isExportAllDeclaration; + generated$3.isExportDeclaration = isExportDeclaration; + generated$3.isExportDefaultDeclaration = isExportDefaultDeclaration; + generated$3.isExportDefaultSpecifier = isExportDefaultSpecifier; + generated$3.isExportNamedDeclaration = isExportNamedDeclaration; + generated$3.isExportNamespaceSpecifier = isExportNamespaceSpecifier; + generated$3.isExportSpecifier = isExportSpecifier; + generated$3.isExpression = isExpression; + generated$3.isExpressionStatement = isExpressionStatement; + generated$3.isExpressionWrapper = isExpressionWrapper; + generated$3.isFile = isFile; + generated$3.isFlow = isFlow; + generated$3.isFlowBaseAnnotation = isFlowBaseAnnotation; + generated$3.isFlowDeclaration = isFlowDeclaration; + generated$3.isFlowPredicate = isFlowPredicate; + generated$3.isFlowType = isFlowType; + generated$3.isFor = isFor; + generated$3.isForInStatement = isForInStatement; + generated$3.isForOfStatement = isForOfStatement; + generated$3.isForStatement = isForStatement; + generated$3.isForXStatement = isForXStatement; + generated$3.isFunction = isFunction; + generated$3.isFunctionDeclaration = isFunctionDeclaration; + generated$3.isFunctionExpression = isFunctionExpression; + generated$3.isFunctionParent = isFunctionParent; + generated$3.isFunctionTypeAnnotation = isFunctionTypeAnnotation; + generated$3.isFunctionTypeParam = isFunctionTypeParam; + generated$3.isGenericTypeAnnotation = isGenericTypeAnnotation; + generated$3.isIdentifier = isIdentifier; + generated$3.isIfStatement = isIfStatement; + generated$3.isImmutable = isImmutable; + generated$3.isImport = isImport; + generated$3.isImportAttribute = isImportAttribute; + generated$3.isImportDeclaration = isImportDeclaration; + generated$3.isImportDefaultSpecifier = isImportDefaultSpecifier; + generated$3.isImportExpression = isImportExpression; + generated$3.isImportNamespaceSpecifier = isImportNamespaceSpecifier; + generated$3.isImportOrExportDeclaration = isImportOrExportDeclaration; + generated$3.isImportSpecifier = isImportSpecifier; + generated$3.isIndexedAccessType = isIndexedAccessType; + generated$3.isInferredPredicate = isInferredPredicate; + generated$3.isInterfaceDeclaration = isInterfaceDeclaration; + generated$3.isInterfaceExtends = isInterfaceExtends; + generated$3.isInterfaceTypeAnnotation = isInterfaceTypeAnnotation; + generated$3.isInterpreterDirective = isInterpreterDirective; + generated$3.isIntersectionTypeAnnotation = isIntersectionTypeAnnotation; + generated$3.isJSX = isJSX; + generated$3.isJSXAttribute = isJSXAttribute; + generated$3.isJSXClosingElement = isJSXClosingElement; + generated$3.isJSXClosingFragment = isJSXClosingFragment; + generated$3.isJSXElement = isJSXElement; + generated$3.isJSXEmptyExpression = isJSXEmptyExpression; + generated$3.isJSXExpressionContainer = isJSXExpressionContainer; + generated$3.isJSXFragment = isJSXFragment; + generated$3.isJSXIdentifier = isJSXIdentifier; + generated$3.isJSXMemberExpression = isJSXMemberExpression; + generated$3.isJSXNamespacedName = isJSXNamespacedName; + generated$3.isJSXOpeningElement = isJSXOpeningElement; + generated$3.isJSXOpeningFragment = isJSXOpeningFragment; + generated$3.isJSXSpreadAttribute = isJSXSpreadAttribute; + generated$3.isJSXSpreadChild = isJSXSpreadChild; + generated$3.isJSXText = isJSXText; + generated$3.isLVal = isLVal; + generated$3.isLabeledStatement = isLabeledStatement; + generated$3.isLiteral = isLiteral; + generated$3.isLogicalExpression = isLogicalExpression; + generated$3.isLoop = isLoop; + generated$3.isMemberExpression = isMemberExpression; + generated$3.isMetaProperty = isMetaProperty; + generated$3.isMethod = isMethod; + generated$3.isMiscellaneous = isMiscellaneous; + generated$3.isMixedTypeAnnotation = isMixedTypeAnnotation; + generated$3.isModuleDeclaration = isModuleDeclaration; + generated$3.isModuleExpression = isModuleExpression; + generated$3.isModuleSpecifier = isModuleSpecifier; + generated$3.isNewExpression = isNewExpression; + generated$3.isNoop = isNoop; + generated$3.isNullLiteral = isNullLiteral; + generated$3.isNullLiteralTypeAnnotation = isNullLiteralTypeAnnotation; + generated$3.isNullableTypeAnnotation = isNullableTypeAnnotation; + generated$3.isNumberLiteral = isNumberLiteral; + generated$3.isNumberLiteralTypeAnnotation = isNumberLiteralTypeAnnotation; + generated$3.isNumberTypeAnnotation = isNumberTypeAnnotation; + generated$3.isNumericLiteral = isNumericLiteral; + generated$3.isObjectExpression = isObjectExpression; + generated$3.isObjectMember = isObjectMember; + generated$3.isObjectMethod = isObjectMethod; + generated$3.isObjectPattern = isObjectPattern; + generated$3.isObjectProperty = isObjectProperty; + generated$3.isObjectTypeAnnotation = isObjectTypeAnnotation; + generated$3.isObjectTypeCallProperty = isObjectTypeCallProperty; + generated$3.isObjectTypeIndexer = isObjectTypeIndexer; + generated$3.isObjectTypeInternalSlot = isObjectTypeInternalSlot; + generated$3.isObjectTypeProperty = isObjectTypeProperty; + generated$3.isObjectTypeSpreadProperty = isObjectTypeSpreadProperty; + generated$3.isOpaqueType = isOpaqueType; + generated$3.isOptionalCallExpression = isOptionalCallExpression; + generated$3.isOptionalIndexedAccessType = isOptionalIndexedAccessType; + generated$3.isOptionalMemberExpression = isOptionalMemberExpression; + generated$3.isParenthesizedExpression = isParenthesizedExpression; + generated$3.isPattern = isPattern; + generated$3.isPatternLike = isPatternLike; + generated$3.isPipelineBareFunction = isPipelineBareFunction; + generated$3.isPipelinePrimaryTopicReference = isPipelinePrimaryTopicReference; + generated$3.isPipelineTopicExpression = isPipelineTopicExpression; + generated$3.isPlaceholder = isPlaceholder; + generated$3.isPrivate = isPrivate; + generated$3.isPrivateName = isPrivateName; + generated$3.isProgram = isProgram; + generated$3.isProperty = isProperty; + generated$3.isPureish = isPureish; + generated$3.isQualifiedTypeIdentifier = isQualifiedTypeIdentifier; + generated$3.isRecordExpression = isRecordExpression; + generated$3.isRegExpLiteral = isRegExpLiteral; + generated$3.isRegexLiteral = isRegexLiteral; + generated$3.isRestElement = isRestElement; + generated$3.isRestProperty = isRestProperty; + generated$3.isReturnStatement = isReturnStatement; + generated$3.isScopable = isScopable; + generated$3.isSequenceExpression = isSequenceExpression; + generated$3.isSpreadElement = isSpreadElement; + generated$3.isSpreadProperty = isSpreadProperty; + generated$3.isStandardized = isStandardized; + generated$3.isStatement = isStatement; + generated$3.isStaticBlock = isStaticBlock; + generated$3.isStringLiteral = isStringLiteral; + generated$3.isStringLiteralTypeAnnotation = isStringLiteralTypeAnnotation; + generated$3.isStringTypeAnnotation = isStringTypeAnnotation; + generated$3.isSuper = isSuper; + generated$3.isSwitchCase = isSwitchCase; + generated$3.isSwitchStatement = isSwitchStatement; + generated$3.isSymbolTypeAnnotation = isSymbolTypeAnnotation; + generated$3.isTSAnyKeyword = isTSAnyKeyword; + generated$3.isTSArrayType = isTSArrayType; + generated$3.isTSAsExpression = isTSAsExpression; + generated$3.isTSBaseType = isTSBaseType; + generated$3.isTSBigIntKeyword = isTSBigIntKeyword; + generated$3.isTSBooleanKeyword = isTSBooleanKeyword; + generated$3.isTSCallSignatureDeclaration = isTSCallSignatureDeclaration; + generated$3.isTSConditionalType = isTSConditionalType; + generated$3.isTSConstructSignatureDeclaration = isTSConstructSignatureDeclaration; + generated$3.isTSConstructorType = isTSConstructorType; + generated$3.isTSDeclareFunction = isTSDeclareFunction; + generated$3.isTSDeclareMethod = isTSDeclareMethod; + generated$3.isTSEntityName = isTSEntityName; + generated$3.isTSEnumDeclaration = isTSEnumDeclaration; + generated$3.isTSEnumMember = isTSEnumMember; + generated$3.isTSExportAssignment = isTSExportAssignment; + generated$3.isTSExpressionWithTypeArguments = isTSExpressionWithTypeArguments; + generated$3.isTSExternalModuleReference = isTSExternalModuleReference; + generated$3.isTSFunctionType = isTSFunctionType; + generated$3.isTSImportEqualsDeclaration = isTSImportEqualsDeclaration; + generated$3.isTSImportType = isTSImportType; + generated$3.isTSIndexSignature = isTSIndexSignature; + generated$3.isTSIndexedAccessType = isTSIndexedAccessType; + generated$3.isTSInferType = isTSInferType; + generated$3.isTSInstantiationExpression = isTSInstantiationExpression; + generated$3.isTSInterfaceBody = isTSInterfaceBody; + generated$3.isTSInterfaceDeclaration = isTSInterfaceDeclaration; + generated$3.isTSIntersectionType = isTSIntersectionType; + generated$3.isTSIntrinsicKeyword = isTSIntrinsicKeyword; + generated$3.isTSLiteralType = isTSLiteralType; + generated$3.isTSMappedType = isTSMappedType; + generated$3.isTSMethodSignature = isTSMethodSignature; + generated$3.isTSModuleBlock = isTSModuleBlock; + generated$3.isTSModuleDeclaration = isTSModuleDeclaration; + generated$3.isTSNamedTupleMember = isTSNamedTupleMember; + generated$3.isTSNamespaceExportDeclaration = isTSNamespaceExportDeclaration; + generated$3.isTSNeverKeyword = isTSNeverKeyword; + generated$3.isTSNonNullExpression = isTSNonNullExpression; + generated$3.isTSNullKeyword = isTSNullKeyword; + generated$3.isTSNumberKeyword = isTSNumberKeyword; + generated$3.isTSObjectKeyword = isTSObjectKeyword; + generated$3.isTSOptionalType = isTSOptionalType; + generated$3.isTSParameterProperty = isTSParameterProperty; + generated$3.isTSParenthesizedType = isTSParenthesizedType; + generated$3.isTSPropertySignature = isTSPropertySignature; + generated$3.isTSQualifiedName = isTSQualifiedName; + generated$3.isTSRestType = isTSRestType; + generated$3.isTSSatisfiesExpression = isTSSatisfiesExpression; + generated$3.isTSStringKeyword = isTSStringKeyword; + generated$3.isTSSymbolKeyword = isTSSymbolKeyword; + generated$3.isTSThisType = isTSThisType; + generated$3.isTSTupleType = isTSTupleType; + generated$3.isTSType = isTSType; + generated$3.isTSTypeAliasDeclaration = isTSTypeAliasDeclaration; + generated$3.isTSTypeAnnotation = isTSTypeAnnotation; + generated$3.isTSTypeAssertion = isTSTypeAssertion; + generated$3.isTSTypeElement = isTSTypeElement; + generated$3.isTSTypeLiteral = isTSTypeLiteral; + generated$3.isTSTypeOperator = isTSTypeOperator; + generated$3.isTSTypeParameter = isTSTypeParameter; + generated$3.isTSTypeParameterDeclaration = isTSTypeParameterDeclaration; + generated$3.isTSTypeParameterInstantiation = isTSTypeParameterInstantiation; + generated$3.isTSTypePredicate = isTSTypePredicate; + generated$3.isTSTypeQuery = isTSTypeQuery; + generated$3.isTSTypeReference = isTSTypeReference; + generated$3.isTSUndefinedKeyword = isTSUndefinedKeyword; + generated$3.isTSUnionType = isTSUnionType; + generated$3.isTSUnknownKeyword = isTSUnknownKeyword; + generated$3.isTSVoidKeyword = isTSVoidKeyword; + generated$3.isTaggedTemplateExpression = isTaggedTemplateExpression; + generated$3.isTemplateElement = isTemplateElement; + generated$3.isTemplateLiteral = isTemplateLiteral; + generated$3.isTerminatorless = isTerminatorless; + generated$3.isThisExpression = isThisExpression; + generated$3.isThisTypeAnnotation = isThisTypeAnnotation; + generated$3.isThrowStatement = isThrowStatement; + generated$3.isTopicReference = isTopicReference; + generated$3.isTryStatement = isTryStatement; + generated$3.isTupleExpression = isTupleExpression; + generated$3.isTupleTypeAnnotation = isTupleTypeAnnotation; + generated$3.isTypeAlias = isTypeAlias; + generated$3.isTypeAnnotation = isTypeAnnotation; + generated$3.isTypeCastExpression = isTypeCastExpression; + generated$3.isTypeParameter = isTypeParameter; + generated$3.isTypeParameterDeclaration = isTypeParameterDeclaration; + generated$3.isTypeParameterInstantiation = isTypeParameterInstantiation; + generated$3.isTypeScript = isTypeScript; + generated$3.isTypeofTypeAnnotation = isTypeofTypeAnnotation; + generated$3.isUnaryExpression = isUnaryExpression; + generated$3.isUnaryLike = isUnaryLike; + generated$3.isUnionTypeAnnotation = isUnionTypeAnnotation; + generated$3.isUpdateExpression = isUpdateExpression; + generated$3.isUserWhitespacable = isUserWhitespacable; + generated$3.isV8IntrinsicIdentifier = isV8IntrinsicIdentifier; + generated$3.isVariableDeclaration = isVariableDeclaration; + generated$3.isVariableDeclarator = isVariableDeclarator; + generated$3.isVariance = isVariance; + generated$3.isVoidTypeAnnotation = isVoidTypeAnnotation; + generated$3.isWhile = isWhile; + generated$3.isWhileStatement = isWhileStatement; + generated$3.isWithStatement = isWithStatement; + generated$3.isYieldExpression = isYieldExpression; + var _shallowEqual = requireShallowEqual(); + var _deprecationWarning = requireDeprecationWarning(); + function isArrayExpression(node, opts) { + if (!node) return false; + if (node.type !== "ArrayExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAssignmentExpression(node, opts) { + if (!node) return false; + if (node.type !== "AssignmentExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBinaryExpression(node, opts) { + if (!node) return false; + if (node.type !== "BinaryExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterpreterDirective(node, opts) { + if (!node) return false; + if (node.type !== "InterpreterDirective") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDirective(node, opts) { + if (!node) return false; + if (node.type !== "Directive") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDirectiveLiteral(node, opts) { + if (!node) return false; + if (node.type !== "DirectiveLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlockStatement(node, opts) { + if (!node) return false; + if (node.type !== "BlockStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBreakStatement(node, opts) { + if (!node) return false; + if (node.type !== "BreakStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCallExpression(node, opts) { + if (!node) return false; + if (node.type !== "CallExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCatchClause(node, opts) { + if (!node) return false; + if (node.type !== "CatchClause") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isConditionalExpression(node, opts) { + if (!node) return false; + if (node.type !== "ConditionalExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isContinueStatement(node, opts) { + if (!node) return false; + if (node.type !== "ContinueStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDebuggerStatement(node, opts) { + if (!node) return false; + if (node.type !== "DebuggerStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDoWhileStatement(node, opts) { + if (!node) return false; + if (node.type !== "DoWhileStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEmptyStatement(node, opts) { + if (!node) return false; + if (node.type !== "EmptyStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpressionStatement(node, opts) { + if (!node) return false; + if (node.type !== "ExpressionStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFile(node, opts) { + if (!node) return false; + if (node.type !== "File") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForInStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForInStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "FunctionDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionExpression(node, opts) { + if (!node) return false; + if (node.type !== "FunctionExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "Identifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIfStatement(node, opts) { + if (!node) return false; + if (node.type !== "IfStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLabeledStatement(node, opts) { + if (!node) return false; + if (node.type !== "LabeledStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringLiteral(node, opts) { + if (!node) return false; + if (node.type !== "StringLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumericLiteral(node, opts) { + if (!node) return false; + if (node.type !== "NumericLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullLiteral(node, opts) { + if (!node) return false; + if (node.type !== "NullLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanLiteral(node, opts) { + if (!node) return false; + if (node.type !== "BooleanLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRegExpLiteral(node, opts) { + if (!node) return false; + if (node.type !== "RegExpLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLogicalExpression(node, opts) { + if (!node) return false; + if (node.type !== "LogicalExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "MemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNewExpression(node, opts) { + if (!node) return false; + if (node.type !== "NewExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isProgram(node, opts) { + if (!node) return false; + if (node.type !== "Program") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectExpression(node, opts) { + if (!node) return false; + if (node.type !== "ObjectExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectMethod(node, opts) { + if (!node) return false; + if (node.type !== "ObjectMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRestElement(node, opts) { + if (!node) return false; + if (node.type !== "RestElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isReturnStatement(node, opts) { + if (!node) return false; + if (node.type !== "ReturnStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSequenceExpression(node, opts) { + if (!node) return false; + if (node.type !== "SequenceExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isParenthesizedExpression(node, opts) { + if (!node) return false; + if (node.type !== "ParenthesizedExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSwitchCase(node, opts) { + if (!node) return false; + if (node.type !== "SwitchCase") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSwitchStatement(node, opts) { + if (!node) return false; + if (node.type !== "SwitchStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThisExpression(node, opts) { + if (!node) return false; + if (node.type !== "ThisExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThrowStatement(node, opts) { + if (!node) return false; + if (node.type !== "ThrowStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTryStatement(node, opts) { + if (!node) return false; + if (node.type !== "TryStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnaryExpression(node, opts) { + if (!node) return false; + if (node.type !== "UnaryExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUpdateExpression(node, opts) { + if (!node) return false; + if (node.type !== "UpdateExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariableDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "VariableDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariableDeclarator(node, opts) { + if (!node) return false; + if (node.type !== "VariableDeclarator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWhileStatement(node, opts) { + if (!node) return false; + if (node.type !== "WhileStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWithStatement(node, opts) { + if (!node) return false; + if (node.type !== "WithStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAssignmentPattern(node, opts) { + if (!node) return false; + if (node.type !== "AssignmentPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrayPattern(node, opts) { + if (!node) return false; + if (node.type !== "ArrayPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrowFunctionExpression(node, opts) { + if (!node) return false; + if (node.type !== "ArrowFunctionExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassBody(node, opts) { + if (!node) return false; + if (node.type !== "ClassBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassExpression(node, opts) { + if (!node) return false; + if (node.type !== "ClassExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ClassDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportAllDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportAllDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDefaultDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportDefaultDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportNamedDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ExportNamedDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForOfStatement(node, opts) { + if (!node) return false; + if (node.type !== "ForOfStatement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "ImportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportDefaultSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportDefaultSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportNamespaceSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportNamespaceSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ImportSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportExpression(node, opts) { + if (!node) return false; + if (node.type !== "ImportExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMetaProperty(node, opts) { + if (!node) return false; + if (node.type !== "MetaProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassMethod(node, opts) { + if (!node) return false; + if (node.type !== "ClassMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectPattern(node, opts) { + if (!node) return false; + if (node.type !== "ObjectPattern") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSpreadElement(node, opts) { + if (!node) return false; + if (node.type !== "SpreadElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSuper(node, opts) { + if (!node) return false; + if (node.type !== "Super") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTaggedTemplateExpression(node, opts) { + if (!node) return false; + if (node.type !== "TaggedTemplateExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTemplateElement(node, opts) { + if (!node) return false; + if (node.type !== "TemplateElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTemplateLiteral(node, opts) { + if (!node) return false; + if (node.type !== "TemplateLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isYieldExpression(node, opts) { + if (!node) return false; + if (node.type !== "YieldExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAwaitExpression(node, opts) { + if (!node) return false; + if (node.type !== "AwaitExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImport(node, opts) { + if (!node) return false; + if (node.type !== "Import") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBigIntLiteral(node, opts) { + if (!node) return false; + if (node.type !== "BigIntLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportNamespaceSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportNamespaceSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "OptionalMemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalCallExpression(node, opts) { + if (!node) return false; + if (node.type !== "OptionalCallExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassAccessorProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassAccessorProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassPrivateProperty(node, opts) { + if (!node) return false; + if (node.type !== "ClassPrivateProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassPrivateMethod(node, opts) { + if (!node) return false; + if (node.type !== "ClassPrivateMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPrivateName(node, opts) { + if (!node) return false; + if (node.type !== "PrivateName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStaticBlock(node, opts) { + if (!node) return false; + if (node.type !== "StaticBlock") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAnyTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "AnyTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArrayTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ArrayTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "BooleanTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBooleanLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "BooleanLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NullLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClassImplements(node, opts) { + if (!node) return false; + if (node.type !== "ClassImplements") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareClass(node, opts) { + if (!node) return false; + if (node.type !== "DeclareClass") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareFunction(node, opts) { + if (!node) return false; + if (node.type !== "DeclareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareInterface(node, opts) { + if (!node) return false; + if (node.type !== "DeclareInterface") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareModule(node, opts) { + if (!node) return false; + if (node.type !== "DeclareModule") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareModuleExports(node, opts) { + if (!node) return false; + if (node.type !== "DeclareModuleExports") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareTypeAlias(node, opts) { + if (!node) return false; + if (node.type !== "DeclareTypeAlias") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareOpaqueType(node, opts) { + if (!node) return false; + if (node.type !== "DeclareOpaqueType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareVariable(node, opts) { + if (!node) return false; + if (node.type !== "DeclareVariable") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareExportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "DeclareExportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclareExportAllDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "DeclareExportAllDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclaredPredicate(node, opts) { + if (!node) return false; + if (node.type !== "DeclaredPredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExistsTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ExistsTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "FunctionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionTypeParam(node, opts) { + if (!node) return false; + if (node.type !== "FunctionTypeParam") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isGenericTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "GenericTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInferredPredicate(node, opts) { + if (!node) return false; + if (node.type !== "InferredPredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceExtends(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceExtends") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isInterfaceTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "InterfaceTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIntersectionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "IntersectionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMixedTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "MixedTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEmptyTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "EmptyTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNullableTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NullableTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NumberLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "NumberTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeInternalSlot(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeInternalSlot") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeCallProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeCallProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeIndexer(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeIndexer") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectTypeSpreadProperty(node, opts) { + if (!node) return false; + if (node.type !== "ObjectTypeSpreadProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOpaqueType(node, opts) { + if (!node) return false; + if (node.type !== "OpaqueType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isQualifiedTypeIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "QualifiedTypeIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringLiteralTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "StringLiteralTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStringTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "StringTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSymbolTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "SymbolTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isThisTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "ThisTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTupleTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TupleTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeofTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TypeofTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeAlias(node, opts) { + if (!node) return false; + if (node.type !== "TypeAlias") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeCastExpression(node, opts) { + if (!node) return false; + if (node.type !== "TypeCastExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameter(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameter") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameterDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameterDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeParameterInstantiation(node, opts) { + if (!node) return false; + if (node.type !== "TypeParameterInstantiation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnionTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "UnionTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVariance(node, opts) { + if (!node) return false; + if (node.type !== "Variance") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isVoidTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "VoidTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "EnumDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBooleanBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumBooleanBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumNumberBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumNumberBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumStringBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumStringBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumSymbolBody(node, opts) { + if (!node) return false; + if (node.type !== "EnumSymbolBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBooleanMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumBooleanMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumNumberMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumNumberMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumStringMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumStringMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumDefaultedMember(node, opts) { + if (!node) return false; + if (node.type !== "EnumDefaultedMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "IndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isOptionalIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "OptionalIndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXAttribute(node, opts) { + if (!node) return false; + if (node.type !== "JSXAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXClosingElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXClosingElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXEmptyExpression(node, opts) { + if (!node) return false; + if (node.type !== "JSXEmptyExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXExpressionContainer(node, opts) { + if (!node) return false; + if (node.type !== "JSXExpressionContainer") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXSpreadChild(node, opts) { + if (!node) return false; + if (node.type !== "JSXSpreadChild") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "JSXIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXMemberExpression(node, opts) { + if (!node) return false; + if (node.type !== "JSXMemberExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXNamespacedName(node, opts) { + if (!node) return false; + if (node.type !== "JSXNamespacedName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXOpeningElement(node, opts) { + if (!node) return false; + if (node.type !== "JSXOpeningElement") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXSpreadAttribute(node, opts) { + if (!node) return false; + if (node.type !== "JSXSpreadAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXText(node, opts) { + if (!node) return false; + if (node.type !== "JSXText") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXOpeningFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXOpeningFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSXClosingFragment(node, opts) { + if (!node) return false; + if (node.type !== "JSXClosingFragment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNoop(node, opts) { + if (!node) return false; + if (node.type !== "Noop") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPlaceholder(node, opts) { + if (!node) return false; + if (node.type !== "Placeholder") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isV8IntrinsicIdentifier(node, opts) { + if (!node) return false; + if (node.type !== "V8IntrinsicIdentifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isArgumentPlaceholder(node, opts) { + if (!node) return false; + if (node.type !== "ArgumentPlaceholder") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBindExpression(node, opts) { + if (!node) return false; + if (node.type !== "BindExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportAttribute(node, opts) { + if (!node) return false; + if (node.type !== "ImportAttribute") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDecorator(node, opts) { + if (!node) return false; + if (node.type !== "Decorator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDoExpression(node, opts) { + if (!node) return false; + if (node.type !== "DoExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDefaultSpecifier(node, opts) { + if (!node) return false; + if (node.type !== "ExportDefaultSpecifier") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRecordExpression(node, opts) { + if (!node) return false; + if (node.type !== "RecordExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTupleExpression(node, opts) { + if (!node) return false; + if (node.type !== "TupleExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDecimalLiteral(node, opts) { + if (!node) return false; + if (node.type !== "DecimalLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleExpression(node, opts) { + if (!node) return false; + if (node.type !== "ModuleExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTopicReference(node, opts) { + if (!node) return false; + if (node.type !== "TopicReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelineTopicExpression(node, opts) { + if (!node) return false; + if (node.type !== "PipelineTopicExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelineBareFunction(node, opts) { + if (!node) return false; + if (node.type !== "PipelineBareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPipelinePrimaryTopicReference(node, opts) { + if (!node) return false; + if (node.type !== "PipelinePrimaryTopicReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSParameterProperty(node, opts) { + if (!node) return false; + if (node.type !== "TSParameterProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSDeclareFunction(node, opts) { + if (!node) return false; + if (node.type !== "TSDeclareFunction") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSDeclareMethod(node, opts) { + if (!node) return false; + if (node.type !== "TSDeclareMethod") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSQualifiedName(node, opts) { + if (!node) return false; + if (node.type !== "TSQualifiedName") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSCallSignatureDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSCallSignatureDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConstructSignatureDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSConstructSignatureDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSPropertySignature(node, opts) { + if (!node) return false; + if (node.type !== "TSPropertySignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSMethodSignature(node, opts) { + if (!node) return false; + if (node.type !== "TSMethodSignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIndexSignature(node, opts) { + if (!node) return false; + if (node.type !== "TSIndexSignature") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSAnyKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSAnyKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBooleanKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSBooleanKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBigIntKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSBigIntKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIntrinsicKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSIntrinsicKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNeverKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNeverKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNullKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNullKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNumberKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSNumberKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSObjectKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSObjectKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSStringKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSStringKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSSymbolKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSSymbolKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUndefinedKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSUndefinedKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUnknownKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSUnknownKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSVoidKeyword(node, opts) { + if (!node) return false; + if (node.type !== "TSVoidKeyword") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSThisType(node, opts) { + if (!node) return false; + if (node.type !== "TSThisType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSFunctionType(node, opts) { + if (!node) return false; + if (node.type !== "TSFunctionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConstructorType(node, opts) { + if (!node) return false; + if (node.type !== "TSConstructorType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeReference(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypePredicate(node, opts) { + if (!node) return false; + if (node.type !== "TSTypePredicate") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeQuery(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeQuery") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeLiteral(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSArrayType(node, opts) { + if (!node) return false; + if (node.type !== "TSArrayType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTupleType(node, opts) { + if (!node) return false; + if (node.type !== "TSTupleType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSOptionalType(node, opts) { + if (!node) return false; + if (node.type !== "TSOptionalType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSRestType(node, opts) { + if (!node) return false; + if (node.type !== "TSRestType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNamedTupleMember(node, opts) { + if (!node) return false; + if (node.type !== "TSNamedTupleMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSUnionType(node, opts) { + if (!node) return false; + if (node.type !== "TSUnionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIntersectionType(node, opts) { + if (!node) return false; + if (node.type !== "TSIntersectionType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSConditionalType(node, opts) { + if (!node) return false; + if (node.type !== "TSConditionalType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInferType(node, opts) { + if (!node) return false; + if (node.type !== "TSInferType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSParenthesizedType(node, opts) { + if (!node) return false; + if (node.type !== "TSParenthesizedType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeOperator(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeOperator") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSIndexedAccessType(node, opts) { + if (!node) return false; + if (node.type !== "TSIndexedAccessType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSMappedType(node, opts) { + if (!node) return false; + if (node.type !== "TSMappedType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSLiteralType(node, opts) { + if (!node) return false; + if (node.type !== "TSLiteralType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExpressionWithTypeArguments(node, opts) { + if (!node) return false; + if (node.type !== "TSExpressionWithTypeArguments") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInterfaceDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSInterfaceDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInterfaceBody(node, opts) { + if (!node) return false; + if (node.type !== "TSInterfaceBody") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAliasDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAliasDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSInstantiationExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSInstantiationExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSAsExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSAsExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSSatisfiesExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSSatisfiesExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAssertion(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAssertion") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEnumDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSEnumDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEnumMember(node, opts) { + if (!node) return false; + if (node.type !== "TSEnumMember") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSModuleDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSModuleDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSModuleBlock(node, opts) { + if (!node) return false; + if (node.type !== "TSModuleBlock") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSImportType(node, opts) { + if (!node) return false; + if (node.type !== "TSImportType") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSImportEqualsDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSImportEqualsDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExternalModuleReference(node, opts) { + if (!node) return false; + if (node.type !== "TSExternalModuleReference") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNonNullExpression(node, opts) { + if (!node) return false; + if (node.type !== "TSNonNullExpression") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSExportAssignment(node, opts) { + if (!node) return false; + if (node.type !== "TSExportAssignment") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSNamespaceExportDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSNamespaceExportDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeAnnotation(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeAnnotation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameterInstantiation(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameterInstantiation") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameterDeclaration(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameterDeclaration") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeParameter(node, opts) { + if (!node) return false; + if (node.type !== "TSTypeParameter") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStandardized(node, opts) { + if (!node) return false; + switch (node.type) { + case "ArrayExpression": + case "AssignmentExpression": + case "BinaryExpression": + case "InterpreterDirective": + case "Directive": + case "DirectiveLiteral": + case "BlockStatement": + case "BreakStatement": + case "CallExpression": + case "CatchClause": + case "ConditionalExpression": + case "ContinueStatement": + case "DebuggerStatement": + case "DoWhileStatement": + case "EmptyStatement": + case "ExpressionStatement": + case "File": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Identifier": + case "IfStatement": + case "LabeledStatement": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "LogicalExpression": + case "MemberExpression": + case "NewExpression": + case "Program": + case "ObjectExpression": + case "ObjectMethod": + case "ObjectProperty": + case "RestElement": + case "ReturnStatement": + case "SequenceExpression": + case "ParenthesizedExpression": + case "SwitchCase": + case "SwitchStatement": + case "ThisExpression": + case "ThrowStatement": + case "TryStatement": + case "UnaryExpression": + case "UpdateExpression": + case "VariableDeclaration": + case "VariableDeclarator": + case "WhileStatement": + case "WithStatement": + case "AssignmentPattern": + case "ArrayPattern": + case "ArrowFunctionExpression": + case "ClassBody": + case "ClassExpression": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ExportSpecifier": + case "ForOfStatement": + case "ImportDeclaration": + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + case "ImportExpression": + case "MetaProperty": + case "ClassMethod": + case "ObjectPattern": + case "SpreadElement": + case "Super": + case "TaggedTemplateExpression": + case "TemplateElement": + case "TemplateLiteral": + case "YieldExpression": + case "AwaitExpression": + case "Import": + case "BigIntLiteral": + case "ExportNamespaceSpecifier": + case "OptionalMemberExpression": + case "OptionalCallExpression": + case "ClassProperty": + case "ClassAccessorProperty": + case "ClassPrivateProperty": + case "ClassPrivateMethod": + case "PrivateName": + case "StaticBlock": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Identifier": + case "StringLiteral": + case "BlockStatement": + case "ClassBody": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpression(node, opts) { + if (!node) return false; + switch (node.type) { + case "ArrayExpression": + case "AssignmentExpression": + case "BinaryExpression": + case "CallExpression": + case "ConditionalExpression": + case "FunctionExpression": + case "Identifier": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "LogicalExpression": + case "MemberExpression": + case "NewExpression": + case "ObjectExpression": + case "SequenceExpression": + case "ParenthesizedExpression": + case "ThisExpression": + case "UnaryExpression": + case "UpdateExpression": + case "ArrowFunctionExpression": + case "ClassExpression": + case "ImportExpression": + case "MetaProperty": + case "Super": + case "TaggedTemplateExpression": + case "TemplateLiteral": + case "YieldExpression": + case "AwaitExpression": + case "Import": + case "BigIntLiteral": + case "OptionalMemberExpression": + case "OptionalCallExpression": + case "TypeCastExpression": + case "JSXElement": + case "JSXFragment": + case "BindExpression": + case "DoExpression": + case "RecordExpression": + case "TupleExpression": + case "DecimalLiteral": + case "ModuleExpression": + case "TopicReference": + case "PipelineTopicExpression": + case "PipelineBareFunction": + case "PipelinePrimaryTopicReference": + case "TSInstantiationExpression": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Expression": + case "Identifier": + case "StringLiteral": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBinary(node, opts) { + if (!node) return false; + switch (node.type) { + case "BinaryExpression": + case "LogicalExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isScopable(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "CatchClause": + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Program": + case "ObjectMethod": + case "SwitchStatement": + case "WhileStatement": + case "ArrowFunctionExpression": + case "ClassExpression": + case "ClassDeclaration": + case "ForOfStatement": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlockParent(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "CatchClause": + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "FunctionExpression": + case "Program": + case "ObjectMethod": + case "SwitchStatement": + case "WhileStatement": + case "ArrowFunctionExpression": + case "ForOfStatement": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isBlock(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "Program": + case "TSModuleBlock": + break; + case "Placeholder": + if (node.expectedNode === "BlockStatement") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "BlockStatement": + case "BreakStatement": + case "ContinueStatement": + case "DebuggerStatement": + case "DoWhileStatement": + case "EmptyStatement": + case "ExpressionStatement": + case "ForInStatement": + case "ForStatement": + case "FunctionDeclaration": + case "IfStatement": + case "LabeledStatement": + case "ReturnStatement": + case "SwitchStatement": + case "ThrowStatement": + case "TryStatement": + case "VariableDeclaration": + case "WhileStatement": + case "WithStatement": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ForOfStatement": + case "ImportDeclaration": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + case "EnumDeclaration": + case "TSDeclareFunction": + case "TSInterfaceDeclaration": + case "TSTypeAliasDeclaration": + case "TSEnumDeclaration": + case "TSModuleDeclaration": + case "TSImportEqualsDeclaration": + case "TSExportAssignment": + case "TSNamespaceExportDeclaration": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Statement": + case "Declaration": + case "BlockStatement": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTerminatorless(node, opts) { + if (!node) return false; + switch (node.type) { + case "BreakStatement": + case "ContinueStatement": + case "ReturnStatement": + case "ThrowStatement": + case "YieldExpression": + case "AwaitExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isCompletionStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "BreakStatement": + case "ContinueStatement": + case "ReturnStatement": + case "ThrowStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isConditional(node, opts) { + if (!node) return false; + switch (node.type) { + case "ConditionalExpression": + case "IfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLoop(node, opts) { + if (!node) return false; + switch (node.type) { + case "DoWhileStatement": + case "ForInStatement": + case "ForStatement": + case "WhileStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isWhile(node, opts) { + if (!node) return false; + switch (node.type) { + case "DoWhileStatement": + case "WhileStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExpressionWrapper(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExpressionStatement": + case "ParenthesizedExpression": + case "TypeCastExpression": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFor(node, opts) { + if (!node) return false; + switch (node.type) { + case "ForInStatement": + case "ForStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isForXStatement(node, opts) { + if (!node) return false; + switch (node.type) { + case "ForInStatement": + case "ForOfStatement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunction(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "ObjectMethod": + case "ArrowFunctionExpression": + case "ClassMethod": + case "ClassPrivateMethod": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFunctionParent(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "ObjectMethod": + case "ArrowFunctionExpression": + case "ClassMethod": + case "ClassPrivateMethod": + case "StaticBlock": + case "TSModuleBlock": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPureish(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "FunctionExpression": + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "ArrowFunctionExpression": + case "BigIntLiteral": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "FunctionDeclaration": + case "VariableDeclaration": + case "ClassDeclaration": + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ImportDeclaration": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + case "EnumDeclaration": + case "TSDeclareFunction": + case "TSInterfaceDeclaration": + case "TSTypeAliasDeclaration": + case "TSEnumDeclaration": + case "TSModuleDeclaration": + break; + case "Placeholder": + if (node.expectedNode === "Declaration") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPatternLike(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "RestElement": + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Pattern": + case "Identifier": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLVal(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "MemberExpression": + case "RestElement": + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + case "TSParameterProperty": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSNonNullExpression": + break; + case "Placeholder": + switch (node.expectedNode) { + case "Pattern": + case "Identifier": + break; + default: + return false; + } + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSEntityName(node, opts) { + if (!node) return false; + switch (node.type) { + case "Identifier": + case "TSQualifiedName": + break; + case "Placeholder": + if (node.expectedNode === "Identifier") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isLiteral(node, opts) { + if (!node) return false; + switch (node.type) { + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "RegExpLiteral": + case "TemplateLiteral": + case "BigIntLiteral": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImmutable(node, opts) { + if (!node) return false; + switch (node.type) { + case "StringLiteral": + case "NumericLiteral": + case "NullLiteral": + case "BooleanLiteral": + case "BigIntLiteral": + case "JSXAttribute": + case "JSXClosingElement": + case "JSXElement": + case "JSXExpressionContainer": + case "JSXSpreadChild": + case "JSXOpeningElement": + case "JSXText": + case "JSXFragment": + case "JSXOpeningFragment": + case "JSXClosingFragment": + case "DecimalLiteral": + break; + case "Placeholder": + if (node.expectedNode === "StringLiteral") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUserWhitespacable(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ObjectProperty": + case "ObjectTypeInternalSlot": + case "ObjectTypeCallProperty": + case "ObjectTypeIndexer": + case "ObjectTypeProperty": + case "ObjectTypeSpreadProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMethod(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ClassMethod": + case "ClassPrivateMethod": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isObjectMember(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectMethod": + case "ObjectProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isProperty(node, opts) { + if (!node) return false; + switch (node.type) { + case "ObjectProperty": + case "ClassProperty": + case "ClassAccessorProperty": + case "ClassPrivateProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isUnaryLike(node, opts) { + if (!node) return false; + switch (node.type) { + case "UnaryExpression": + case "SpreadElement": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPattern(node, opts) { + if (!node) return false; + switch (node.type) { + case "AssignmentPattern": + case "ArrayPattern": + case "ObjectPattern": + break; + case "Placeholder": + if (node.expectedNode === "Pattern") break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isClass(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassExpression": + case "ClassDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isImportOrExportDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + case "ImportDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isExportDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportAllDeclaration": + case "ExportDefaultDeclaration": + case "ExportNamedDeclaration": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleSpecifier(node, opts) { + if (!node) return false; + switch (node.type) { + case "ExportSpecifier": + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + case "ExportNamespaceSpecifier": + case "ExportDefaultSpecifier": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isAccessor(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassAccessorProperty": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isPrivate(node, opts) { + if (!node) return false; + switch (node.type) { + case "ClassPrivateProperty": + case "ClassPrivateMethod": + case "PrivateName": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlow(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "ArrayTypeAnnotation": + case "BooleanTypeAnnotation": + case "BooleanLiteralTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "ClassImplements": + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "DeclaredPredicate": + case "ExistsTypeAnnotation": + case "FunctionTypeAnnotation": + case "FunctionTypeParam": + case "GenericTypeAnnotation": + case "InferredPredicate": + case "InterfaceExtends": + case "InterfaceDeclaration": + case "InterfaceTypeAnnotation": + case "IntersectionTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NullableTypeAnnotation": + case "NumberLiteralTypeAnnotation": + case "NumberTypeAnnotation": + case "ObjectTypeAnnotation": + case "ObjectTypeInternalSlot": + case "ObjectTypeCallProperty": + case "ObjectTypeIndexer": + case "ObjectTypeProperty": + case "ObjectTypeSpreadProperty": + case "OpaqueType": + case "QualifiedTypeIdentifier": + case "StringLiteralTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "TupleTypeAnnotation": + case "TypeofTypeAnnotation": + case "TypeAlias": + case "TypeAnnotation": + case "TypeCastExpression": + case "TypeParameter": + case "TypeParameterDeclaration": + case "TypeParameterInstantiation": + case "UnionTypeAnnotation": + case "Variance": + case "VoidTypeAnnotation": + case "EnumDeclaration": + case "EnumBooleanBody": + case "EnumNumberBody": + case "EnumStringBody": + case "EnumSymbolBody": + case "EnumBooleanMember": + case "EnumNumberMember": + case "EnumStringMember": + case "EnumDefaultedMember": + case "IndexedAccessType": + case "OptionalIndexedAccessType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowType(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "ArrayTypeAnnotation": + case "BooleanTypeAnnotation": + case "BooleanLiteralTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "ExistsTypeAnnotation": + case "FunctionTypeAnnotation": + case "GenericTypeAnnotation": + case "InterfaceTypeAnnotation": + case "IntersectionTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NullableTypeAnnotation": + case "NumberLiteralTypeAnnotation": + case "NumberTypeAnnotation": + case "ObjectTypeAnnotation": + case "StringLiteralTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "TupleTypeAnnotation": + case "TypeofTypeAnnotation": + case "UnionTypeAnnotation": + case "VoidTypeAnnotation": + case "IndexedAccessType": + case "OptionalIndexedAccessType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowBaseAnnotation(node, opts) { + if (!node) return false; + switch (node.type) { + case "AnyTypeAnnotation": + case "BooleanTypeAnnotation": + case "NullLiteralTypeAnnotation": + case "MixedTypeAnnotation": + case "EmptyTypeAnnotation": + case "NumberTypeAnnotation": + case "StringTypeAnnotation": + case "SymbolTypeAnnotation": + case "ThisTypeAnnotation": + case "VoidTypeAnnotation": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowDeclaration(node, opts) { + if (!node) return false; + switch (node.type) { + case "DeclareClass": + case "DeclareFunction": + case "DeclareInterface": + case "DeclareModule": + case "DeclareModuleExports": + case "DeclareTypeAlias": + case "DeclareOpaqueType": + case "DeclareVariable": + case "DeclareExportDeclaration": + case "DeclareExportAllDeclaration": + case "InterfaceDeclaration": + case "OpaqueType": + case "TypeAlias": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isFlowPredicate(node, opts) { + if (!node) return false; + switch (node.type) { + case "DeclaredPredicate": + case "InferredPredicate": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumBody(node, opts) { + if (!node) return false; + switch (node.type) { + case "EnumBooleanBody": + case "EnumNumberBody": + case "EnumStringBody": + case "EnumSymbolBody": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isEnumMember(node, opts) { + if (!node) return false; + switch (node.type) { + case "EnumBooleanMember": + case "EnumNumberMember": + case "EnumStringMember": + case "EnumDefaultedMember": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isJSX(node, opts) { + if (!node) return false; + switch (node.type) { + case "JSXAttribute": + case "JSXClosingElement": + case "JSXElement": + case "JSXEmptyExpression": + case "JSXExpressionContainer": + case "JSXSpreadChild": + case "JSXIdentifier": + case "JSXMemberExpression": + case "JSXNamespacedName": + case "JSXOpeningElement": + case "JSXSpreadAttribute": + case "JSXText": + case "JSXFragment": + case "JSXOpeningFragment": + case "JSXClosingFragment": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isMiscellaneous(node, opts) { + if (!node) return false; + switch (node.type) { + case "Noop": + case "Placeholder": + case "V8IntrinsicIdentifier": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTypeScript(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSParameterProperty": + case "TSDeclareFunction": + case "TSDeclareMethod": + case "TSQualifiedName": + case "TSCallSignatureDeclaration": + case "TSConstructSignatureDeclaration": + case "TSPropertySignature": + case "TSMethodSignature": + case "TSIndexSignature": + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSFunctionType": + case "TSConstructorType": + case "TSTypeReference": + case "TSTypePredicate": + case "TSTypeQuery": + case "TSTypeLiteral": + case "TSArrayType": + case "TSTupleType": + case "TSOptionalType": + case "TSRestType": + case "TSNamedTupleMember": + case "TSUnionType": + case "TSIntersectionType": + case "TSConditionalType": + case "TSInferType": + case "TSParenthesizedType": + case "TSTypeOperator": + case "TSIndexedAccessType": + case "TSMappedType": + case "TSLiteralType": + case "TSExpressionWithTypeArguments": + case "TSInterfaceDeclaration": + case "TSInterfaceBody": + case "TSTypeAliasDeclaration": + case "TSInstantiationExpression": + case "TSAsExpression": + case "TSSatisfiesExpression": + case "TSTypeAssertion": + case "TSEnumDeclaration": + case "TSEnumMember": + case "TSModuleDeclaration": + case "TSModuleBlock": + case "TSImportType": + case "TSImportEqualsDeclaration": + case "TSExternalModuleReference": + case "TSNonNullExpression": + case "TSExportAssignment": + case "TSNamespaceExportDeclaration": + case "TSTypeAnnotation": + case "TSTypeParameterInstantiation": + case "TSTypeParameterDeclaration": + case "TSTypeParameter": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSTypeElement(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSCallSignatureDeclaration": + case "TSConstructSignatureDeclaration": + case "TSPropertySignature": + case "TSMethodSignature": + case "TSIndexSignature": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSType(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSFunctionType": + case "TSConstructorType": + case "TSTypeReference": + case "TSTypePredicate": + case "TSTypeQuery": + case "TSTypeLiteral": + case "TSArrayType": + case "TSTupleType": + case "TSOptionalType": + case "TSRestType": + case "TSUnionType": + case "TSIntersectionType": + case "TSConditionalType": + case "TSInferType": + case "TSParenthesizedType": + case "TSTypeOperator": + case "TSIndexedAccessType": + case "TSMappedType": + case "TSLiteralType": + case "TSExpressionWithTypeArguments": + case "TSImportType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isTSBaseType(node, opts) { + if (!node) return false; + switch (node.type) { + case "TSAnyKeyword": + case "TSBooleanKeyword": + case "TSBigIntKeyword": + case "TSIntrinsicKeyword": + case "TSNeverKeyword": + case "TSNullKeyword": + case "TSNumberKeyword": + case "TSObjectKeyword": + case "TSStringKeyword": + case "TSSymbolKeyword": + case "TSUndefinedKeyword": + case "TSUnknownKeyword": + case "TSVoidKeyword": + case "TSThisType": + case "TSLiteralType": + break; + default: + return false; + } + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isNumberLiteral(node, opts) { + (0, _deprecationWarning.default)("isNumberLiteral", "isNumericLiteral"); + if (!node) return false; + if (node.type !== "NumberLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRegexLiteral(node, opts) { + (0, _deprecationWarning.default)("isRegexLiteral", "isRegExpLiteral"); + if (!node) return false; + if (node.type !== "RegexLiteral") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isRestProperty(node, opts) { + (0, _deprecationWarning.default)("isRestProperty", "isRestElement"); + if (!node) return false; + if (node.type !== "RestProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isSpreadProperty(node, opts) { + (0, _deprecationWarning.default)("isSpreadProperty", "isSpreadElement"); + if (!node) return false; + if (node.type !== "SpreadProperty") return false; + return opts == null || (0, _shallowEqual.default)(node, opts); + } + function isModuleDeclaration(node, opts) { + (0, _deprecationWarning.default)("isModuleDeclaration", "isImportOrExportDeclaration"); + return isImportOrExportDeclaration(node, opts); + } + + + return generated$3; +} + +var hasRequiredMatchesPattern; + +function requireMatchesPattern () { + if (hasRequiredMatchesPattern) return matchesPattern; + hasRequiredMatchesPattern = 1; + + Object.defineProperty(matchesPattern, "__esModule", { + value: true + }); + matchesPattern.default = matchesPattern$1; + var _index = requireGenerated$3(); + function matchesPattern$1(member, match, allowPartial) { + if (!(0, _index.isMemberExpression)(member)) return false; + const parts = Array.isArray(match) ? match : match.split("."); + const nodes = []; + let node; + for (node = member; (0, _index.isMemberExpression)(node); node = node.object) { + nodes.push(node.property); + } + nodes.push(node); + if (nodes.length < parts.length) return false; + if (!allowPartial && nodes.length > parts.length) return false; + for (let i = 0, j = nodes.length - 1; i < parts.length; i++, j--) { + const node = nodes[j]; + let value; + if ((0, _index.isIdentifier)(node)) { + value = node.name; + } else if ((0, _index.isStringLiteral)(node)) { + value = node.value; + } else if ((0, _index.isThisExpression)(node)) { + value = "this"; + } else { + return false; + } + if (parts[i] !== value) return false; + } + return true; + } + + + return matchesPattern; +} + +var hasRequiredBuildMatchMemberExpression; + +function requireBuildMatchMemberExpression () { + if (hasRequiredBuildMatchMemberExpression) return buildMatchMemberExpression; + hasRequiredBuildMatchMemberExpression = 1; + + Object.defineProperty(buildMatchMemberExpression, "__esModule", { + value: true + }); + buildMatchMemberExpression.default = buildMatchMemberExpression$1; + var _matchesPattern = requireMatchesPattern(); + function buildMatchMemberExpression$1(match, allowPartial) { + const parts = match.split("."); + return member => (0, _matchesPattern.default)(member, parts, allowPartial); + } + + + return buildMatchMemberExpression; +} + +var hasRequiredIsReactComponent; + +function requireIsReactComponent () { + if (hasRequiredIsReactComponent) return isReactComponent; + hasRequiredIsReactComponent = 1; + + Object.defineProperty(isReactComponent, "__esModule", { + value: true + }); + isReactComponent.default = void 0; + var _buildMatchMemberExpression = requireBuildMatchMemberExpression(); + const isReactComponent$1 = (0, _buildMatchMemberExpression.default)("React.Component"); + isReactComponent.default = isReactComponent$1; + + + return isReactComponent; +} + +var isCompatTag = {}; + +var hasRequiredIsCompatTag; + +function requireIsCompatTag () { + if (hasRequiredIsCompatTag) return isCompatTag; + hasRequiredIsCompatTag = 1; + + Object.defineProperty(isCompatTag, "__esModule", { + value: true + }); + isCompatTag.default = isCompatTag$1; + function isCompatTag$1(tagName) { + return !!tagName && /^[a-z]/.test(tagName); + } + + + return isCompatTag; +} + +var buildChildren = {}; + +var cleanJSXElementLiteralChild = {}; + +var generated$2 = {}; + +var validate$1 = {}; + +var definitions = {}; + +var core = {}; + +var is = {}; + +var isType = {}; + +var hasRequiredIsType; + +function requireIsType () { + if (hasRequiredIsType) return isType; + hasRequiredIsType = 1; + + Object.defineProperty(isType, "__esModule", { + value: true + }); + isType.default = isType$1; + var _index = requireDefinitions(); + function isType$1(nodeType, targetType) { + if (nodeType === targetType) return true; + if (nodeType == null) return false; + if (_index.ALIAS_KEYS[targetType]) return false; + const aliases = _index.FLIPPED_ALIAS_KEYS[targetType]; + if (aliases) { + if (aliases[0] === nodeType) return true; + for (const alias of aliases) { + if (nodeType === alias) return true; + } + } + return false; + } + + + return isType; +} + +var isPlaceholderType = {}; + +var hasRequiredIsPlaceholderType; + +function requireIsPlaceholderType () { + if (hasRequiredIsPlaceholderType) return isPlaceholderType; + hasRequiredIsPlaceholderType = 1; + + Object.defineProperty(isPlaceholderType, "__esModule", { + value: true + }); + isPlaceholderType.default = isPlaceholderType$1; + var _index = requireDefinitions(); + function isPlaceholderType$1(placeholderType, targetType) { + if (placeholderType === targetType) return true; + const aliases = _index.PLACEHOLDERS_ALIAS[placeholderType]; + if (aliases) { + for (const alias of aliases) { + if (targetType === alias) return true; + } + } + return false; + } + + + return isPlaceholderType; +} + +var hasRequiredIs; + +function requireIs () { + if (hasRequiredIs) return is; + hasRequiredIs = 1; + + Object.defineProperty(is, "__esModule", { + value: true + }); + is.default = is$1; + var _shallowEqual = requireShallowEqual(); + var _isType = requireIsType(); + var _isPlaceholderType = requireIsPlaceholderType(); + var _index = requireDefinitions(); + function is$1(type, node, opts) { + if (!node) return false; + const matches = (0, _isType.default)(node.type, type); + if (!matches) { + if (!opts && node.type === "Placeholder" && type in _index.FLIPPED_ALIAS_KEYS) { + return (0, _isPlaceholderType.default)(node.expectedNode, type); + } + return false; + } + if (opts === undefined) { + return true; + } else { + return (0, _shallowEqual.default)(node, opts); + } + } + + + return is; +} + +var isValidIdentifier = {}; + +var lib$2 = {}; + +var identifier = {}; + +var hasRequiredIdentifier; + +function requireIdentifier () { + if (hasRequiredIdentifier) return identifier; + hasRequiredIdentifier = 1; + + Object.defineProperty(identifier, "__esModule", { + value: true + }); + identifier.isIdentifierChar = isIdentifierChar; + identifier.isIdentifierName = isIdentifierName; + identifier.isIdentifierStart = isIdentifierStart; + let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; + let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65"; + const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); + const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); + nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; + const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191]; + const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239]; + function isInAstralSet(code, set) { + let pos = 0x10000; + for (let i = 0, length = set.length; i < length; i += 2) { + pos += set[i]; + if (pos > code) return false; + pos += set[i + 1]; + if (pos >= code) return true; + } + return false; + } + function isIdentifierStart(code) { + if (code < 65) return code === 36; + if (code <= 90) return true; + if (code < 97) return code === 95; + if (code <= 122) return true; + if (code <= 0xffff) { + return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)); + } + return isInAstralSet(code, astralIdentifierStartCodes); + } + function isIdentifierChar(code) { + if (code < 48) return code === 36; + if (code < 58) return true; + if (code < 65) return false; + if (code <= 90) return true; + if (code < 97) return code === 95; + if (code <= 122) return true; + if (code <= 0xffff) { + return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)); + } + return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes); + } + function isIdentifierName(name) { + let isFirst = true; + for (let i = 0; i < name.length; i++) { + let cp = name.charCodeAt(i); + if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) { + const trail = name.charCodeAt(++i); + if ((trail & 0xfc00) === 0xdc00) { + cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff); + } + } + if (isFirst) { + isFirst = false; + if (!isIdentifierStart(cp)) { + return false; + } + } else if (!isIdentifierChar(cp)) { + return false; + } + } + return !isFirst; + } + + + return identifier; +} + +var keyword = {}; + +var hasRequiredKeyword; + +function requireKeyword () { + if (hasRequiredKeyword) return keyword; + hasRequiredKeyword = 1; + + Object.defineProperty(keyword, "__esModule", { + value: true + }); + keyword.isKeyword = isKeyword; + keyword.isReservedWord = isReservedWord; + keyword.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord; + keyword.isStrictBindReservedWord = isStrictBindReservedWord; + keyword.isStrictReservedWord = isStrictReservedWord; + const reservedWords = { + keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"], + strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"], + strictBind: ["eval", "arguments"] + }; + const keywords = new Set(reservedWords.keyword); + const reservedWordsStrictSet = new Set(reservedWords.strict); + const reservedWordsStrictBindSet = new Set(reservedWords.strictBind); + function isReservedWord(word, inModule) { + return inModule && word === "await" || word === "enum"; + } + function isStrictReservedWord(word, inModule) { + return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word); + } + function isStrictBindOnlyReservedWord(word) { + return reservedWordsStrictBindSet.has(word); + } + function isStrictBindReservedWord(word, inModule) { + return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word); + } + function isKeyword(word) { + return keywords.has(word); + } + + + return keyword; +} + +var hasRequiredLib$3; + +function requireLib$3 () { + if (hasRequiredLib$3) return lib$2; + hasRequiredLib$3 = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "isIdentifierChar", { + enumerable: true, + get: function () { + return _identifier.isIdentifierChar; + } + }); + Object.defineProperty(exports, "isIdentifierName", { + enumerable: true, + get: function () { + return _identifier.isIdentifierName; + } + }); + Object.defineProperty(exports, "isIdentifierStart", { + enumerable: true, + get: function () { + return _identifier.isIdentifierStart; + } + }); + Object.defineProperty(exports, "isKeyword", { + enumerable: true, + get: function () { + return _keyword.isKeyword; + } + }); + Object.defineProperty(exports, "isReservedWord", { + enumerable: true, + get: function () { + return _keyword.isReservedWord; + } + }); + Object.defineProperty(exports, "isStrictBindOnlyReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictBindOnlyReservedWord; + } + }); + Object.defineProperty(exports, "isStrictBindReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictBindReservedWord; + } + }); + Object.defineProperty(exports, "isStrictReservedWord", { + enumerable: true, + get: function () { + return _keyword.isStrictReservedWord; + } + }); + var _identifier = requireIdentifier(); + var _keyword = requireKeyword(); + + +} (lib$2)); + return lib$2; +} + +var hasRequiredIsValidIdentifier; + +function requireIsValidIdentifier () { + if (hasRequiredIsValidIdentifier) return isValidIdentifier; + hasRequiredIsValidIdentifier = 1; + + Object.defineProperty(isValidIdentifier, "__esModule", { + value: true + }); + isValidIdentifier.default = isValidIdentifier$1; + var _helperValidatorIdentifier = requireLib$3(); + function isValidIdentifier$1(name, reserved = true) { + if (typeof name !== "string") return false; + if (reserved) { + if ((0, _helperValidatorIdentifier.isKeyword)(name) || (0, _helperValidatorIdentifier.isStrictReservedWord)(name, true)) { + return false; + } + } + return (0, _helperValidatorIdentifier.isIdentifierName)(name); + } + + + return isValidIdentifier; +} + +var lib$1 = {}; + +var hasRequiredLib$2; + +function requireLib$2 () { + if (hasRequiredLib$2) return lib$1; + hasRequiredLib$2 = 1; + + Object.defineProperty(lib$1, "__esModule", { + value: true + }); + lib$1.readCodePoint = readCodePoint; + lib$1.readInt = readInt; + lib$1.readStringContents = readStringContents; + var _isDigit = function isDigit(code) { + return code >= 48 && code <= 57; + }; + const forbiddenNumericSeparatorSiblings = { + decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]), + hex: new Set([46, 88, 95, 120]) + }; + const isAllowedNumericSeparatorSibling = { + bin: ch => ch === 48 || ch === 49, + oct: ch => ch >= 48 && ch <= 55, + dec: ch => ch >= 48 && ch <= 57, + hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102 + }; + function readStringContents(type, input, pos, lineStart, curLine, errors) { + const initialPos = pos; + const initialLineStart = lineStart; + const initialCurLine = curLine; + let out = ""; + let firstInvalidLoc = null; + let chunkStart = pos; + const { + length + } = input; + for (;;) { + if (pos >= length) { + errors.unterminated(initialPos, initialLineStart, initialCurLine); + out += input.slice(chunkStart, pos); + break; + } + const ch = input.charCodeAt(pos); + if (isStringEnd(type, ch, input, pos)) { + out += input.slice(chunkStart, pos); + break; + } + if (ch === 92) { + out += input.slice(chunkStart, pos); + const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors); + if (res.ch === null && !firstInvalidLoc) { + firstInvalidLoc = { + pos, + lineStart, + curLine + }; + } else { + out += res.ch; + } + ({ + pos, + lineStart, + curLine + } = res); + chunkStart = pos; + } else if (ch === 8232 || ch === 8233) { + ++pos; + ++curLine; + lineStart = pos; + } else if (ch === 10 || ch === 13) { + if (type === "template") { + out += input.slice(chunkStart, pos) + "\n"; + ++pos; + if (ch === 13 && input.charCodeAt(pos) === 10) { + ++pos; + } + ++curLine; + chunkStart = lineStart = pos; + } else { + errors.unterminated(initialPos, initialLineStart, initialCurLine); + } + } else { + ++pos; + } + } + return { + pos, + str: out, + firstInvalidLoc, + lineStart, + curLine, + containsInvalid: !!firstInvalidLoc + }; + } + function isStringEnd(type, ch, input, pos) { + if (type === "template") { + return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123; + } + return ch === (type === "double" ? 34 : 39); + } + function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) { + const throwOnInvalid = !inTemplate; + pos++; + const res = ch => ({ + pos, + ch, + lineStart, + curLine + }); + const ch = input.charCodeAt(pos++); + switch (ch) { + case 110: + return res("\n"); + case 114: + return res("\r"); + case 120: + { + let code; + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors)); + return res(code === null ? null : String.fromCharCode(code)); + } + case 117: + { + let code; + ({ + code, + pos + } = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors)); + return res(code === null ? null : String.fromCodePoint(code)); + } + case 116: + return res("\t"); + case 98: + return res("\b"); + case 118: + return res("\u000b"); + case 102: + return res("\f"); + case 13: + if (input.charCodeAt(pos) === 10) { + ++pos; + } + case 10: + lineStart = pos; + ++curLine; + case 8232: + case 8233: + return res(""); + case 56: + case 57: + if (inTemplate) { + return res(null); + } else { + errors.strictNumericEscape(pos - 1, lineStart, curLine); + } + default: + if (ch >= 48 && ch <= 55) { + const startPos = pos - 1; + const match = /^[0-7]+/.exec(input.slice(startPos, pos + 2)); + let octalStr = match[0]; + let octal = parseInt(octalStr, 8); + if (octal > 255) { + octalStr = octalStr.slice(0, -1); + octal = parseInt(octalStr, 8); + } + pos += octalStr.length - 1; + const next = input.charCodeAt(pos); + if (octalStr !== "0" || next === 56 || next === 57) { + if (inTemplate) { + return res(null); + } else { + errors.strictNumericEscape(startPos, lineStart, curLine); + } + } + return res(String.fromCharCode(octal)); + } + return res(String.fromCharCode(ch)); + } + } + function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) { + const initialPos = pos; + let n; + ({ + n, + pos + } = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid)); + if (n === null) { + if (throwOnInvalid) { + errors.invalidEscapeSequence(initialPos, lineStart, curLine); + } else { + pos = initialPos - 1; + } + } + return { + code: n, + pos + }; + } + function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) { + const start = pos; + const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct; + const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin; + let invalid = false; + let total = 0; + for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) { + const code = input.charCodeAt(pos); + let val; + if (code === 95 && allowNumSeparator !== "bail") { + const prev = input.charCodeAt(pos - 1); + const next = input.charCodeAt(pos + 1); + if (!allowNumSeparator) { + if (bailOnError) return { + n: null, + pos + }; + errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine); + } else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) { + if (bailOnError) return { + n: null, + pos + }; + errors.unexpectedNumericSeparator(pos, lineStart, curLine); + } + ++pos; + continue; + } + if (code >= 97) { + val = code - 97 + 10; + } else if (code >= 65) { + val = code - 65 + 10; + } else if (_isDigit(code)) { + val = code - 48; + } else { + val = Infinity; + } + if (val >= radix) { + if (val <= 9 && bailOnError) { + return { + n: null, + pos + }; + } else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) { + val = 0; + } else if (forceLen) { + val = 0; + invalid = true; + } else { + break; + } + } + ++pos; + total = total * radix + val; + } + if (pos === start || len != null && pos - start !== len || invalid) { + return { + n: null, + pos + }; + } + return { + n: total, + pos + }; + } + function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) { + const ch = input.charCodeAt(pos); + let code; + if (ch === 123) { + ++pos; + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors)); + ++pos; + if (code !== null && code > 0x10ffff) { + if (throwOnInvalid) { + errors.invalidCodePoint(pos, lineStart, curLine); + } else { + return { + code: null, + pos + }; + } + } + } else { + ({ + code, + pos + } = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors)); + } + return { + code, + pos + }; + } + + + return lib$1; +} + +var constants = {}; + +var hasRequiredConstants; + +function requireConstants () { + if (hasRequiredConstants) return constants; + hasRequiredConstants = 1; + + Object.defineProperty(constants, "__esModule", { + value: true + }); + constants.UPDATE_OPERATORS = constants.UNARY_OPERATORS = constants.STRING_UNARY_OPERATORS = constants.STATEMENT_OR_BLOCK_KEYS = constants.NUMBER_UNARY_OPERATORS = constants.NUMBER_BINARY_OPERATORS = constants.NOT_LOCAL_BINDING = constants.LOGICAL_OPERATORS = constants.INHERIT_KEYS = constants.FOR_INIT_KEYS = constants.FLATTENABLE_KEYS = constants.EQUALITY_BINARY_OPERATORS = constants.COMPARISON_BINARY_OPERATORS = constants.COMMENT_KEYS = constants.BOOLEAN_UNARY_OPERATORS = constants.BOOLEAN_NUMBER_BINARY_OPERATORS = constants.BOOLEAN_BINARY_OPERATORS = constants.BLOCK_SCOPED_SYMBOL = constants.BINARY_OPERATORS = constants.ASSIGNMENT_OPERATORS = void 0; + constants.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; + constants.FLATTENABLE_KEYS = ["body", "expressions"]; + constants.FOR_INIT_KEYS = ["left", "init"]; + constants.COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"]; + const LOGICAL_OPERATORS = constants.LOGICAL_OPERATORS = ["||", "&&", "??"]; + constants.UPDATE_OPERATORS = ["++", "--"]; + const BOOLEAN_NUMBER_BINARY_OPERATORS = constants.BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="]; + const EQUALITY_BINARY_OPERATORS = constants.EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="]; + const COMPARISON_BINARY_OPERATORS = constants.COMPARISON_BINARY_OPERATORS = [...EQUALITY_BINARY_OPERATORS, "in", "instanceof"]; + const BOOLEAN_BINARY_OPERATORS = constants.BOOLEAN_BINARY_OPERATORS = [...COMPARISON_BINARY_OPERATORS, ...BOOLEAN_NUMBER_BINARY_OPERATORS]; + const NUMBER_BINARY_OPERATORS = constants.NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"]; + constants.BINARY_OPERATORS = ["+", ...NUMBER_BINARY_OPERATORS, ...BOOLEAN_BINARY_OPERATORS, "|>"]; + constants.ASSIGNMENT_OPERATORS = ["=", "+=", ...NUMBER_BINARY_OPERATORS.map(op => op + "="), ...LOGICAL_OPERATORS.map(op => op + "=")]; + const BOOLEAN_UNARY_OPERATORS = constants.BOOLEAN_UNARY_OPERATORS = ["delete", "!"]; + const NUMBER_UNARY_OPERATORS = constants.NUMBER_UNARY_OPERATORS = ["+", "-", "~"]; + const STRING_UNARY_OPERATORS = constants.STRING_UNARY_OPERATORS = ["typeof"]; + constants.UNARY_OPERATORS = ["void", "throw", ...BOOLEAN_UNARY_OPERATORS, ...NUMBER_UNARY_OPERATORS, ...STRING_UNARY_OPERATORS]; + constants.INHERIT_KEYS = { + optional: ["typeAnnotation", "typeParameters", "returnType"], + force: ["start", "loc", "end"] + }; + constants.BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped"); + constants.NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding"); + + + return constants; +} + +var utils = {}; + +var hasRequiredUtils; + +function requireUtils () { + if (hasRequiredUtils) return utils; + hasRequiredUtils = 1; + + Object.defineProperty(utils, "__esModule", { + value: true + }); + utils.VISITOR_KEYS = utils.NODE_PARENT_VALIDATIONS = utils.NODE_FIELDS = utils.FLIPPED_ALIAS_KEYS = utils.DEPRECATED_KEYS = utils.BUILDER_KEYS = utils.ALIAS_KEYS = void 0; + utils.arrayOf = arrayOf; + utils.arrayOfType = arrayOfType; + utils.assertEach = assertEach; + utils.assertNodeOrValueType = assertNodeOrValueType; + utils.assertNodeType = assertNodeType; + utils.assertOneOf = assertOneOf; + utils.assertOptionalChainStart = assertOptionalChainStart; + utils.assertShape = assertShape; + utils.assertValueType = assertValueType; + utils.chain = chain; + utils.default = defineType; + utils.defineAliasedType = defineAliasedType; + utils.validate = validate; + utils.validateArrayOfType = validateArrayOfType; + utils.validateOptional = validateOptional; + utils.validateOptionalType = validateOptionalType; + utils.validateType = validateType; + var _is = requireIs(); + var _validate = requireValidate(); + const VISITOR_KEYS = utils.VISITOR_KEYS = {}; + const ALIAS_KEYS = utils.ALIAS_KEYS = {}; + const FLIPPED_ALIAS_KEYS = utils.FLIPPED_ALIAS_KEYS = {}; + const NODE_FIELDS = utils.NODE_FIELDS = {}; + const BUILDER_KEYS = utils.BUILDER_KEYS = {}; + const DEPRECATED_KEYS = utils.DEPRECATED_KEYS = {}; + const NODE_PARENT_VALIDATIONS = utils.NODE_PARENT_VALIDATIONS = {}; + function getType(val) { + if (Array.isArray(val)) { + return "array"; + } else if (val === null) { + return "null"; + } else { + return typeof val; + } + } + function validate(validate) { + return { + validate + }; + } + function validateType(...typeNames) { + return validate(assertNodeType(...typeNames)); + } + function validateOptional(validate) { + return { + validate, + optional: true + }; + } + function validateOptionalType(...typeNames) { + return { + validate: assertNodeType(...typeNames), + optional: true + }; + } + function arrayOf(elementType) { + return chain(assertValueType("array"), assertEach(elementType)); + } + function arrayOfType(...typeNames) { + return arrayOf(assertNodeType(...typeNames)); + } + function validateArrayOfType(...typeNames) { + return validate(arrayOfType(...typeNames)); + } + function assertEach(callback) { + const childValidator = process.env.BABEL_TYPES_8_BREAKING ? _validate.validateChild : () => {}; + function validator(node, key, val) { + if (!Array.isArray(val)) return; + for (let i = 0; i < val.length; i++) { + const subkey = `${key}[${i}]`; + const v = val[i]; + callback(node, subkey, v); + childValidator(node, subkey, v); + } + } + validator.each = callback; + return validator; + } + function assertOneOf(...values) { + function validate(node, key, val) { + if (!values.includes(val)) { + throw new TypeError(`Property ${key} expected value to be one of ${JSON.stringify(values)} but got ${JSON.stringify(val)}`); + } + } + validate.oneOf = values; + return validate; + } + function assertNodeType(...types) { + function validate(node, key, val) { + for (const type of types) { + if ((0, _is.default)(type, val)) { + (0, _validate.validateChild)(node, key, val); + return; + } + } + throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`); + } + validate.oneOfNodeTypes = types; + return validate; + } + function assertNodeOrValueType(...types) { + function validate(node, key, val) { + for (const type of types) { + if (getType(val) === type || (0, _is.default)(type, val)) { + (0, _validate.validateChild)(node, key, val); + return; + } + } + throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val == null ? void 0 : val.type)}`); + } + validate.oneOfNodeOrValueTypes = types; + return validate; + } + function assertValueType(type) { + function validate(node, key, val) { + const valid = getType(val) === type; + if (!valid) { + throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); + } + } + validate.type = type; + return validate; + } + function assertShape(shape) { + function validate(node, key, val) { + const errors = []; + for (const property of Object.keys(shape)) { + try { + (0, _validate.validateField)(node, property, val[property], shape[property]); + } catch (error) { + if (error instanceof TypeError) { + errors.push(error.message); + continue; + } + throw error; + } + } + if (errors.length) { + throw new TypeError(`Property ${key} of ${node.type} expected to have the following:\n${errors.join("\n")}`); + } + } + validate.shapeOf = shape; + return validate; + } + function assertOptionalChainStart() { + function validate(node) { + var _current; + let current = node; + while (node) { + const { + type + } = current; + if (type === "OptionalCallExpression") { + if (current.optional) return; + current = current.callee; + continue; + } + if (type === "OptionalMemberExpression") { + if (current.optional) return; + current = current.object; + continue; + } + break; + } + throw new TypeError(`Non-optional ${node.type} must chain from an optional OptionalMemberExpression or OptionalCallExpression. Found chain from ${(_current = current) == null ? void 0 : _current.type}`); + } + return validate; + } + function chain(...fns) { + function validate(...args) { + for (const fn of fns) { + fn(...args); + } + } + validate.chainOf = fns; + if (fns.length >= 2 && "type" in fns[0] && fns[0].type === "array" && !("each" in fns[1])) { + throw new Error(`An assertValueType("array") validator can only be followed by an assertEach(...) validator.`); + } + return validate; + } + const validTypeOpts = new Set(["aliases", "builder", "deprecatedAlias", "fields", "inherits", "visitor", "validate"]); + const validFieldKeys = new Set(["default", "optional", "deprecated", "validate"]); + const store = {}; + function defineAliasedType(...aliases) { + return (type, opts = {}) => { + let defined = opts.aliases; + if (!defined) { + var _store$opts$inherits$, _defined; + if (opts.inherits) defined = (_store$opts$inherits$ = store[opts.inherits].aliases) == null ? void 0 : _store$opts$inherits$.slice(); + (_defined = defined) != null ? _defined : defined = []; + opts.aliases = defined; + } + const additional = aliases.filter(a => !defined.includes(a)); + defined.unshift(...additional); + defineType(type, opts); + }; + } + function defineType(type, opts = {}) { + const inherits = opts.inherits && store[opts.inherits] || {}; + let fields = opts.fields; + if (!fields) { + fields = {}; + if (inherits.fields) { + const keys = Object.getOwnPropertyNames(inherits.fields); + for (const key of keys) { + const field = inherits.fields[key]; + const def = field.default; + if (Array.isArray(def) ? def.length > 0 : def && typeof def === "object") { + throw new Error("field defaults can only be primitives or empty arrays currently"); + } + fields[key] = { + default: Array.isArray(def) ? [] : def, + optional: field.optional, + deprecated: field.deprecated, + validate: field.validate + }; + } + } + } + const visitor = opts.visitor || inherits.visitor || []; + const aliases = opts.aliases || inherits.aliases || []; + const builder = opts.builder || inherits.builder || opts.visitor || []; + for (const k of Object.keys(opts)) { + if (!validTypeOpts.has(k)) { + throw new Error(`Unknown type option "${k}" on ${type}`); + } + } + if (opts.deprecatedAlias) { + DEPRECATED_KEYS[opts.deprecatedAlias] = type; + } + for (const key of visitor.concat(builder)) { + fields[key] = fields[key] || {}; + } + for (const key of Object.keys(fields)) { + const field = fields[key]; + if (field.default !== undefined && !builder.includes(key)) { + field.optional = true; + } + if (field.default === undefined) { + field.default = null; + } else if (!field.validate && field.default != null) { + field.validate = assertValueType(getType(field.default)); + } + for (const k of Object.keys(field)) { + if (!validFieldKeys.has(k)) { + throw new Error(`Unknown field key "${k}" on ${type}.${key}`); + } + } + } + VISITOR_KEYS[type] = opts.visitor = visitor; + BUILDER_KEYS[type] = opts.builder = builder; + NODE_FIELDS[type] = opts.fields = fields; + ALIAS_KEYS[type] = opts.aliases = aliases; + aliases.forEach(alias => { + FLIPPED_ALIAS_KEYS[alias] = FLIPPED_ALIAS_KEYS[alias] || []; + FLIPPED_ALIAS_KEYS[alias].push(type); + }); + if (opts.validate) { + NODE_PARENT_VALIDATIONS[type] = opts.validate; + } + store[type] = opts; + } + + + return utils; +} + +var hasRequiredCore; + +function requireCore () { + if (hasRequiredCore) return core; + hasRequiredCore = 1; + + Object.defineProperty(core, "__esModule", { + value: true + }); + core.patternLikeCommon = core.importAttributes = core.functionTypeAnnotationCommon = core.functionDeclarationCommon = core.functionCommon = core.classMethodOrPropertyCommon = core.classMethodOrDeclareMethodCommon = void 0; + var _is = requireIs(); + var _isValidIdentifier = requireIsValidIdentifier(); + var _helperValidatorIdentifier = requireLib$3(); + var _helperStringParser = requireLib$2(); + var _index = requireConstants(); + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("Standardized"); + defineType("ArrayExpression", { + fields: { + elements: { + validate: (0, _utils.arrayOf)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement")), + default: !process.env.BABEL_TYPES_8_BREAKING ? [] : undefined + } + }, + visitor: ["elements"], + aliases: ["Expression"] + }); + defineType("AssignmentExpression", { + fields: { + operator: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("string") : Object.assign(function () { + const identifier = (0, _utils.assertOneOf)(..._index.ASSIGNMENT_OPERATORS); + const pattern = (0, _utils.assertOneOf)("="); + return function (node, key, val) { + const validator = (0, _is.default)("Pattern", node.left) ? pattern : identifier; + validator(node, key, val); + }; + }(), { + type: "string" + }) + }, + left: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal", "OptionalMemberExpression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression", "OptionalMemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + builder: ["operator", "left", "right"], + visitor: ["left", "right"], + aliases: ["Expression"] + }); + defineType("BinaryExpression", { + builder: ["operator", "left", "right"], + fields: { + operator: { + validate: (0, _utils.assertOneOf)(..._index.BINARY_OPERATORS) + }, + left: { + validate: function () { + const expression = (0, _utils.assertNodeType)("Expression"); + const inOp = (0, _utils.assertNodeType)("Expression", "PrivateName"); + const validator = Object.assign(function (node, key, val) { + const validator = node.operator === "in" ? inOp : expression; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "PrivateName"] + }); + return validator; + }() + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + visitor: ["left", "right"], + aliases: ["Binary", "Expression"] + }); + defineType("InterpreterDirective", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("Directive", { + visitor: ["value"], + fields: { + value: { + validate: (0, _utils.assertNodeType)("DirectiveLiteral") + } + } + }); + defineType("DirectiveLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("BlockStatement", { + builder: ["body", "directives"], + visitor: ["directives", "body"], + fields: { + directives: { + validate: (0, _utils.arrayOfType)("Directive"), + default: [] + }, + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "Block", "Statement"] + }); + defineType("BreakStatement", { + visitor: ["label"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }, + aliases: ["Statement", "Terminatorless", "CompletionStatement"] + }); + defineType("CallExpression", { + visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + builder: ["callee", "arguments"], + aliases: ["Expression"], + fields: Object.assign({ + callee: { + validate: (0, _utils.assertNodeType)("Expression", "Super", "V8IntrinsicIdentifier") + }, + arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder") + }, !process.env.BABEL_TYPES_8_BREAKING ? { + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + } : {}, { + typeArguments: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"), + optional: true + } + }) + }); + defineType("CatchClause", { + visitor: ["param", "body"], + fields: { + param: { + validate: (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }, + aliases: ["Scopable", "BlockParent"] + }); + defineType("ConditionalExpression", { + visitor: ["test", "consequent", "alternate"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + consequent: { + validate: (0, _utils.assertNodeType)("Expression") + }, + alternate: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression", "Conditional"] + }); + defineType("ContinueStatement", { + visitor: ["label"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }, + aliases: ["Statement", "Terminatorless", "CompletionStatement"] + }); + defineType("DebuggerStatement", { + aliases: ["Statement"] + }); + defineType("DoWhileStatement", { + builder: ["test", "body"], + visitor: ["body", "test"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + }, + aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"] + }); + defineType("EmptyStatement", { + aliases: ["Statement"] + }); + defineType("ExpressionStatement", { + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Statement", "ExpressionWrapper"] + }); + defineType("File", { + builder: ["program", "comments", "tokens"], + visitor: ["program"], + fields: { + program: { + validate: (0, _utils.assertNodeType)("Program") + }, + comments: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? Object.assign(() => {}, { + each: { + oneOfNodeTypes: ["CommentBlock", "CommentLine"] + } + }) : (0, _utils.assertEach)((0, _utils.assertNodeType)("CommentBlock", "CommentLine")), + optional: true + }, + tokens: { + validate: (0, _utils.assertEach)(Object.assign(() => {}, { + type: "any" + })), + optional: true + } + } + }); + defineType("ForInStatement", { + visitor: ["left", "right", "body"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], + fields: { + left: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("VariableDeclaration", "LVal") : (0, _utils.assertNodeType)("VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("ForStatement", { + visitor: ["init", "test", "update", "body"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"], + fields: { + init: { + validate: (0, _utils.assertNodeType)("VariableDeclaration", "Expression"), + optional: true + }, + test: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + update: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + const functionCommon = () => ({ + params: (0, _utils.validateArrayOfType)("Identifier", "Pattern", "RestElement"), + generator: { + default: false + }, + async: { + default: false + } + }); + core.functionCommon = functionCommon; + const functionTypeAnnotationCommon = () => ({ + returnType: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + } + }); + core.functionTypeAnnotationCommon = functionTypeAnnotationCommon; + const functionDeclarationCommon = () => Object.assign({}, functionCommon(), { + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + } + }); + core.functionDeclarationCommon = functionDeclarationCommon; + defineType("FunctionDeclaration", { + builder: ["id", "params", "body", "generator", "async"], + visitor: ["id", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, functionDeclarationCommon(), functionTypeAnnotationCommon(), { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }), + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pureish", "Declaration"], + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const identifier = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if (!(0, _is.default)("ExportDefaultDeclaration", parent)) { + identifier(node, "id", node.id); + } + }; + }() + }); + defineType("FunctionExpression", { + inherits: "FunctionDeclaration", + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }) + }); + const patternLikeCommon = () => ({ + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }); + core.patternLikeCommon = patternLikeCommon; + defineType("Identifier", { + builder: ["name"], + visitor: ["typeAnnotation", "decorators"], + aliases: ["Expression", "PatternLike", "LVal", "TSEntityName"], + fields: Object.assign({}, patternLikeCommon(), { + name: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) { + if (!(0, _isValidIdentifier.default)(val, false)) { + throw new TypeError(`"${val}" is not a valid identifier name`); + } + }, { + type: "string" + })) : (0, _utils.assertValueType)("string") + } + }), + validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key, node) { + const match = /\.(\w+)$/.exec(key); + if (!match) return; + const [, parentKey] = match; + const nonComp = { + computed: false + }; + if (parentKey === "property") { + if ((0, _is.default)("MemberExpression", parent, nonComp)) return; + if ((0, _is.default)("OptionalMemberExpression", parent, nonComp)) return; + } else if (parentKey === "key") { + if ((0, _is.default)("Property", parent, nonComp)) return; + if ((0, _is.default)("Method", parent, nonComp)) return; + } else if (parentKey === "exported") { + if ((0, _is.default)("ExportSpecifier", parent)) return; + } else if (parentKey === "imported") { + if ((0, _is.default)("ImportSpecifier", parent, { + imported: node + })) return; + } else if (parentKey === "meta") { + if ((0, _is.default)("MetaProperty", parent, { + meta: node + })) return; + } + if (((0, _helperValidatorIdentifier.isKeyword)(node.name) || (0, _helperValidatorIdentifier.isReservedWord)(node.name, false)) && node.name !== "this") { + throw new TypeError(`"${node.name}" is not a valid identifier`); + } + } : undefined + }); + defineType("IfStatement", { + visitor: ["test", "consequent", "alternate"], + aliases: ["Statement", "Conditional"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + consequent: { + validate: (0, _utils.assertNodeType)("Statement") + }, + alternate: { + optional: true, + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("LabeledStatement", { + visitor: ["label", "body"], + aliases: ["Statement"], + fields: { + label: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("StringLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("NumericLiteral", { + builder: ["value"], + deprecatedAlias: "NumberLiteral", + fields: { + value: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("number"), Object.assign(function (node, key, val) { + }, { + type: "number" + })) + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("NullLiteral", { + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("BooleanLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("boolean") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("RegExpLiteral", { + builder: ["pattern", "flags"], + deprecatedAlias: "RegexLiteral", + aliases: ["Expression", "Pureish", "Literal"], + fields: { + pattern: { + validate: (0, _utils.assertValueType)("string") + }, + flags: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) { + const invalid = /[^gimsuy]/.exec(val); + if (invalid) { + throw new TypeError(`"${invalid[0]}" is not a valid RegExp flag`); + } + }, { + type: "string" + })) : (0, _utils.assertValueType)("string"), + default: "" + } + } + }); + defineType("LogicalExpression", { + builder: ["operator", "left", "right"], + visitor: ["left", "right"], + aliases: ["Binary", "Expression"], + fields: { + operator: { + validate: (0, _utils.assertOneOf)(..._index.LOGICAL_OPERATORS) + }, + left: { + validate: (0, _utils.assertNodeType)("Expression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("MemberExpression", { + builder: ["object", "property", "computed", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["optional"] : [])], + visitor: ["object", "property"], + aliases: ["Expression", "LVal"], + fields: Object.assign({ + object: { + validate: (0, _utils.assertNodeType)("Expression", "Super") + }, + property: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + validator.oneOfNodeTypes = ["Expression", "Identifier", "PrivateName"]; + return validator; + }() + }, + computed: { + default: false + } + }, !process.env.BABEL_TYPES_8_BREAKING ? { + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + } : {}) + }); + defineType("NewExpression", { + inherits: "CallExpression" + }); + defineType("Program", { + visitor: ["directives", "body"], + builder: ["body", "directives", "sourceType", "interpreter"], + fields: { + sourceType: { + validate: (0, _utils.assertOneOf)("script", "module"), + default: "script" + }, + interpreter: { + validate: (0, _utils.assertNodeType)("InterpreterDirective"), + default: null, + optional: true + }, + directives: { + validate: (0, _utils.arrayOfType)("Directive"), + default: [] + }, + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "Block"] + }); + defineType("ObjectExpression", { + visitor: ["properties"], + aliases: ["Expression"], + fields: { + properties: (0, _utils.validateArrayOfType)("ObjectMethod", "ObjectProperty", "SpreadElement") + } + }); + defineType("ObjectMethod", { + builder: ["kind", "key", "params", "body", "computed", "generator", "async"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + kind: Object.assign({ + validate: (0, _utils.assertOneOf)("method", "get", "set") + }, !process.env.BABEL_TYPES_8_BREAKING ? { + default: "method" + } : {}), + computed: { + default: false + }, + key: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + validator.oneOfNodeTypes = ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"]; + return validator; + }() + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }), + aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"] + }); + defineType("ObjectProperty", { + builder: ["key", "value", "computed", "shorthand", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["decorators"] : [])], + fields: { + computed: { + default: false + }, + key: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = Object.assign(function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName"] + }); + return validator; + }() + }, + value: { + validate: (0, _utils.assertNodeType)("Expression", "PatternLike") + }, + shorthand: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, shorthand) { + if (!shorthand) return; + if (node.computed) { + throw new TypeError("Property shorthand of ObjectProperty cannot be true if computed is true"); + } + if (!(0, _is.default)("Identifier", node.key)) { + throw new TypeError("Property shorthand of ObjectProperty cannot be true if key is not an Identifier"); + } + }, { + type: "boolean" + })) : (0, _utils.assertValueType)("boolean"), + default: false + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }, + visitor: ["key", "value", "decorators"], + aliases: ["UserWhitespacable", "Property", "ObjectMember"], + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const pattern = (0, _utils.assertNodeType)("Identifier", "Pattern", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion"); + const expression = (0, _utils.assertNodeType)("Expression"); + return function (parent, key, node) { + const validator = (0, _is.default)("ObjectPattern", parent) ? pattern : expression; + validator(node, "value", node.value); + }; + }() + }); + defineType("RestElement", { + visitor: ["argument", "typeAnnotation"], + builder: ["argument"], + aliases: ["LVal", "PatternLike"], + deprecatedAlias: "RestProperty", + fields: Object.assign({}, patternLikeCommon(), { + argument: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + } + }), + validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key) { + const match = /(\w+)\[(\d+)\]/.exec(key); + if (!match) throw new Error("Internal Babel error: malformed key."); + const [, listKey, index] = match; + if (parent[listKey].length > +index + 1) { + throw new TypeError(`RestElement must be last element of ${listKey}`); + } + } : undefined + }); + defineType("ReturnStatement", { + visitor: ["argument"], + aliases: ["Statement", "Terminatorless", "CompletionStatement"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("SequenceExpression", { + visitor: ["expressions"], + fields: { + expressions: (0, _utils.validateArrayOfType)("Expression") + }, + aliases: ["Expression"] + }); + defineType("ParenthesizedExpression", { + visitor: ["expression"], + aliases: ["Expression", "ExpressionWrapper"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("SwitchCase", { + visitor: ["test", "consequent"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + consequent: (0, _utils.validateArrayOfType)("Statement") + } + }); + defineType("SwitchStatement", { + visitor: ["discriminant", "cases"], + aliases: ["Statement", "BlockParent", "Scopable"], + fields: { + discriminant: { + validate: (0, _utils.assertNodeType)("Expression") + }, + cases: (0, _utils.validateArrayOfType)("SwitchCase") + } + }); + defineType("ThisExpression", { + aliases: ["Expression"] + }); + defineType("ThrowStatement", { + visitor: ["argument"], + aliases: ["Statement", "Terminatorless", "CompletionStatement"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("TryStatement", { + visitor: ["block", "handler", "finalizer"], + aliases: ["Statement"], + fields: { + block: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("BlockStatement"), Object.assign(function (node) { + if (!node.handler && !node.finalizer) { + throw new TypeError("TryStatement expects either a handler or finalizer, or both"); + } + }, { + oneOfNodeTypes: ["BlockStatement"] + })) : (0, _utils.assertNodeType)("BlockStatement") + }, + handler: { + optional: true, + validate: (0, _utils.assertNodeType)("CatchClause") + }, + finalizer: { + optional: true, + validate: (0, _utils.assertNodeType)("BlockStatement") + } + } + }); + defineType("UnaryExpression", { + builder: ["operator", "argument", "prefix"], + fields: { + prefix: { + default: true + }, + argument: { + validate: (0, _utils.assertNodeType)("Expression") + }, + operator: { + validate: (0, _utils.assertOneOf)(..._index.UNARY_OPERATORS) + } + }, + visitor: ["argument"], + aliases: ["UnaryLike", "Expression"] + }); + defineType("UpdateExpression", { + builder: ["operator", "argument", "prefix"], + fields: { + prefix: { + default: false + }, + argument: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("Expression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression") + }, + operator: { + validate: (0, _utils.assertOneOf)(..._index.UPDATE_OPERATORS) + } + }, + visitor: ["argument"], + aliases: ["Expression"] + }); + defineType("VariableDeclaration", { + builder: ["kind", "declarations"], + visitor: ["declarations"], + aliases: ["Statement", "Declaration"], + fields: { + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + kind: { + validate: (0, _utils.assertOneOf)("var", "let", "const", "using", "await using") + }, + declarations: (0, _utils.validateArrayOfType)("VariableDeclarator") + }, + validate: process.env.BABEL_TYPES_8_BREAKING ? (() => { + const withoutInit = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if ((0, _is.default)("ForXStatement", parent, { + left: node + })) { + if (node.declarations.length !== 1) { + throw new TypeError(`Exactly one VariableDeclarator is required in the VariableDeclaration of a ${parent.type}`); + } + } else { + node.declarations.forEach(decl => { + if (!decl.init) withoutInit(decl, "id", decl.id); + }); + } + }; + })() : undefined + }); + defineType("VariableDeclarator", { + visitor: ["id", "init"], + fields: { + id: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern") + }, + definite: { + optional: true, + validate: (0, _utils.assertValueType)("boolean") + }, + init: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("WhileStatement", { + visitor: ["test", "body"], + aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"], + fields: { + test: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("WithStatement", { + visitor: ["object", "body"], + aliases: ["Statement"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + } + } + }); + defineType("AssignmentPattern", { + visitor: ["left", "right", "decorators"], + builder: ["left", "right"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + left: { + validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression") + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }) + }); + defineType("ArrayPattern", { + visitor: ["elements", "typeAnnotation"], + builder: ["elements"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + elements: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "PatternLike", "LVal"))) + } + }) + }); + defineType("ArrowFunctionExpression", { + builder: ["params", "body", "async"], + visitor: ["typeParameters", "params", "returnType", "body"], + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], + fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), { + expression: { + validate: (0, _utils.assertValueType)("boolean") + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement", "Expression") + }, + predicate: { + validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"), + optional: true + } + }) + }); + defineType("ClassBody", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("ClassMethod", "ClassPrivateMethod", "ClassProperty", "ClassPrivateProperty", "ClassAccessorProperty", "TSDeclareMethod", "TSIndexSignature", "StaticBlock") + } + }); + defineType("ClassExpression", { + builder: ["id", "superClass", "body", "decorators"], + visitor: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "mixins", "implements", "body"], + aliases: ["Scopable", "Class", "Expression"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("ClassBody") + }, + superClass: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + }, + superTypeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + }, + implements: { + validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + mixins: { + validate: (0, _utils.assertNodeType)("InterfaceExtends"), + optional: true + } + } + }); + defineType("ClassDeclaration", { + inherits: "ClassExpression", + aliases: ["Scopable", "Class", "Statement", "Declaration"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"), + optional: true + }, + body: { + validate: (0, _utils.assertNodeType)("ClassBody") + }, + superClass: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + }, + superTypeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + }, + implements: { + validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + mixins: { + validate: (0, _utils.assertNodeType)("InterfaceExtends"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + abstract: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + }, + validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () { + const identifier = (0, _utils.assertNodeType)("Identifier"); + return function (parent, key, node) { + if (!(0, _is.default)("ExportDefaultDeclaration", parent)) { + identifier(node, "id", node.id); + } + }; + }() + }); + const importAttributes = core.importAttributes = { + attributes: { + optional: true, + validate: (0, _utils.arrayOfType)("ImportAttribute") + }, + assertions: { + deprecated: true, + optional: true, + validate: (0, _utils.arrayOfType)("ImportAttribute") + } + }; + defineType("ExportAllDeclaration", { + builder: ["source"], + visitor: ["source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: Object.assign({ + source: { + validate: (0, _utils.assertNodeType)("StringLiteral") + }, + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }, importAttributes) + }); + defineType("ExportDefaultDeclaration", { + visitor: ["declaration"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: { + declaration: (0, _utils.validateType)("TSDeclareFunction", "FunctionDeclaration", "ClassDeclaration", "Expression"), + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("value")) + } + }); + defineType("ExportNamedDeclaration", { + builder: ["declaration", "specifiers", "source"], + visitor: process.env ? ["declaration", "specifiers", "source", "attributes"] : ["declaration", "specifiers", "source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"], + fields: Object.assign({ + declaration: { + optional: true, + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Declaration"), Object.assign(function (node, key, val) { + if (val && node.specifiers.length) { + throw new TypeError("Only declaration or specifiers is allowed on ExportNamedDeclaration"); + } + if (val && node.source) { + throw new TypeError("Cannot export a declaration from a source"); + } + }, { + oneOfNodeTypes: ["Declaration"] + })) : (0, _utils.assertNodeType)("Declaration") + } + }, importAttributes, { + specifiers: { + default: [], + validate: (0, _utils.arrayOf)(function () { + const sourced = (0, _utils.assertNodeType)("ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier"); + const sourceless = (0, _utils.assertNodeType)("ExportSpecifier"); + if (!process.env.BABEL_TYPES_8_BREAKING) return sourced; + return Object.assign(function (node, key, val) { + const validator = node.source ? sourced : sourceless; + validator(node, key, val); + }, { + oneOfNodeTypes: ["ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier"] + }); + }()) + }, + source: { + validate: (0, _utils.assertNodeType)("StringLiteral"), + optional: true + }, + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }) + }); + defineType("ExportSpecifier", { + visitor: ["local", "exported"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + exported: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + exportKind: { + validate: (0, _utils.assertOneOf)("type", "value"), + optional: true + } + } + }); + defineType("ForOfStatement", { + visitor: ["left", "right", "body"], + builder: ["left", "right", "body", "await"], + aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], + fields: { + left: { + validate: function () { + if (!process.env.BABEL_TYPES_8_BREAKING) { + return (0, _utils.assertNodeType)("VariableDeclaration", "LVal"); + } + const declaration = (0, _utils.assertNodeType)("VariableDeclaration"); + const lval = (0, _utils.assertNodeType)("Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression"); + return Object.assign(function (node, key, val) { + if ((0, _is.default)("VariableDeclaration", val)) { + declaration(node, key, val); + } else { + lval(node, key, val); + } + }, { + oneOfNodeTypes: ["VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression"] + }); + }() + }, + right: { + validate: (0, _utils.assertNodeType)("Expression") + }, + body: { + validate: (0, _utils.assertNodeType)("Statement") + }, + await: { + default: false + } + } + }); + defineType("ImportDeclaration", { + builder: ["specifiers", "source"], + visitor: ["specifiers", "source", "attributes", "assertions"], + aliases: ["Statement", "Declaration", "ImportOrExportDeclaration"], + fields: Object.assign({}, importAttributes, { + module: { + optional: true, + validate: (0, _utils.assertValueType)("boolean") + }, + phase: { + default: null, + validate: (0, _utils.assertOneOf)("source", "defer") + }, + specifiers: (0, _utils.validateArrayOfType)("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier"), + source: { + validate: (0, _utils.assertNodeType)("StringLiteral") + }, + importKind: { + validate: (0, _utils.assertOneOf)("type", "typeof", "value"), + optional: true + } + }) + }); + defineType("ImportDefaultSpecifier", { + visitor: ["local"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("ImportNamespaceSpecifier", { + visitor: ["local"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("ImportSpecifier", { + visitor: ["imported", "local"], + builder: ["local", "imported"], + aliases: ["ModuleSpecifier"], + fields: { + local: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + imported: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + importKind: { + validate: (0, _utils.assertOneOf)("type", "typeof", "value"), + optional: true + } + } + }); + defineType("ImportExpression", { + visitor: ["source", "options"], + aliases: ["Expression"], + fields: { + phase: { + default: null, + validate: (0, _utils.assertOneOf)("source", "defer") + }, + source: { + validate: (0, _utils.assertNodeType)("Expression") + }, + options: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("MetaProperty", { + visitor: ["meta", "property"], + aliases: ["Expression"], + fields: { + meta: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Identifier"), Object.assign(function (node, key, val) { + let property; + switch (val.name) { + case "function": + property = "sent"; + break; + case "new": + property = "target"; + break; + case "import": + property = "meta"; + break; + } + if (!(0, _is.default)("Identifier", node.property, { + name: property + })) { + throw new TypeError("Unrecognised MetaProperty"); + } + }, { + oneOfNodeTypes: ["Identifier"] + })) : (0, _utils.assertNodeType)("Identifier") + }, + property: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + const classMethodOrPropertyCommon = () => ({ + abstract: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + accessibility: { + validate: (0, _utils.assertOneOf)("public", "private", "protected"), + optional: true + }, + static: { + default: false + }, + override: { + default: false + }, + computed: { + default: false + }, + optional: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + key: { + validate: (0, _utils.chain)(function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"); + const computed = (0, _utils.assertNodeType)("Expression"); + return function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression")) + } + }); + core.classMethodOrPropertyCommon = classMethodOrPropertyCommon; + const classMethodOrDeclareMethodCommon = () => Object.assign({}, functionCommon(), classMethodOrPropertyCommon(), { + params: (0, _utils.validateArrayOfType)("Identifier", "Pattern", "RestElement", "TSParameterProperty"), + kind: { + validate: (0, _utils.assertOneOf)("get", "set", "method", "constructor"), + default: "method" + }, + access: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("public", "private", "protected")), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + }); + core.classMethodOrDeclareMethodCommon = classMethodOrDeclareMethodCommon; + defineType("ClassMethod", { + aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"], + builder: ["kind", "key", "params", "body", "computed", "static", "generator", "async"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }) + }); + defineType("ObjectPattern", { + visitor: ["properties", "typeAnnotation", "decorators"], + builder: ["properties"], + aliases: ["Pattern", "PatternLike", "LVal"], + fields: Object.assign({}, patternLikeCommon(), { + properties: (0, _utils.validateArrayOfType)("RestElement", "ObjectProperty") + }) + }); + defineType("SpreadElement", { + visitor: ["argument"], + aliases: ["UnaryLike"], + deprecatedAlias: "SpreadProperty", + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("Super", { + aliases: ["Expression"] + }); + defineType("TaggedTemplateExpression", { + visitor: ["tag", "typeParameters", "quasi"], + builder: ["tag", "quasi"], + aliases: ["Expression"], + fields: { + tag: { + validate: (0, _utils.assertNodeType)("Expression") + }, + quasi: { + validate: (0, _utils.assertNodeType)("TemplateLiteral") + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("TemplateElement", { + builder: ["value", "tail"], + fields: { + value: { + validate: (0, _utils.chain)((0, _utils.assertShape)({ + raw: { + validate: (0, _utils.assertValueType)("string") + }, + cooked: { + validate: (0, _utils.assertValueType)("string"), + optional: true + } + }), function templateElementCookedValidator(node) { + const raw = node.value.raw; + let unterminatedCalled = false; + const error = () => { + throw new Error("Internal @babel/types error."); + }; + const { + str, + firstInvalidLoc + } = (0, _helperStringParser.readStringContents)("template", raw, 0, 0, 0, { + unterminated() { + unterminatedCalled = true; + }, + strictNumericEscape: error, + invalidEscapeSequence: error, + numericSeparatorInEscapeSequence: error, + unexpectedNumericSeparator: error, + invalidDigit: error, + invalidCodePoint: error + }); + if (!unterminatedCalled) throw new Error("Invalid raw"); + node.value.cooked = firstInvalidLoc ? null : str; + }) + }, + tail: { + default: false + } + } + }); + defineType("TemplateLiteral", { + visitor: ["quasis", "expressions"], + aliases: ["Expression", "Literal"], + fields: { + quasis: (0, _utils.validateArrayOfType)("TemplateElement"), + expressions: { + validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "TSType")), function (node, key, val) { + if (node.quasis.length !== val.length + 1) { + throw new TypeError(`Number of ${node.type} quasis should be exactly one more than the number of expressions.\nExpected ${val.length + 1} quasis but got ${node.quasis.length}`); + } + }) + } + } + }); + defineType("YieldExpression", { + builder: ["argument", "delegate"], + visitor: ["argument"], + aliases: ["Expression", "Terminatorless"], + fields: { + delegate: { + validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, val) { + if (val && !node.argument) { + throw new TypeError("Property delegate of YieldExpression cannot be true if there is no argument"); + } + }, { + type: "boolean" + })) : (0, _utils.assertValueType)("boolean"), + default: false + }, + argument: { + optional: true, + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("AwaitExpression", { + builder: ["argument"], + visitor: ["argument"], + aliases: ["Expression", "Terminatorless"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("Import", { + aliases: ["Expression"] + }); + defineType("BigIntLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + defineType("ExportNamespaceSpecifier", { + visitor: ["exported"], + aliases: ["ModuleSpecifier"], + fields: { + exported: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("OptionalMemberExpression", { + builder: ["object", "property", "computed", "optional"], + visitor: ["object", "property"], + aliases: ["Expression"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + property: { + validate: function () { + const normal = (0, _utils.assertNodeType)("Identifier"); + const computed = (0, _utils.assertNodeType)("Expression"); + const validator = Object.assign(function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }, { + oneOfNodeTypes: ["Expression", "Identifier"] + }); + return validator; + }() + }, + computed: { + default: false + }, + optional: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)()) + } + } + }); + defineType("OptionalCallExpression", { + visitor: ["callee", "arguments", "typeParameters", "typeArguments"], + builder: ["callee", "arguments", "optional"], + aliases: ["Expression"], + fields: { + callee: { + validate: (0, _utils.assertNodeType)("Expression") + }, + arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder"), + optional: { + validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)()) + }, + typeArguments: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("ClassProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"], + aliases: ["Property"], + fields: Object.assign({}, classMethodOrPropertyCommon(), { + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + }) + }); + defineType("ClassAccessorProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"], + aliases: ["Property", "Accessor"], + fields: Object.assign({}, classMethodOrPropertyCommon(), { + key: { + validate: (0, _utils.chain)(function () { + const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "PrivateName"); + const computed = (0, _utils.assertNodeType)("Expression"); + return function (node, key, val) { + const validator = node.computed ? computed : normal; + validator(node, key, val); + }; + }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression", "PrivateName")) + }, + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + declare: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + }) + }); + defineType("ClassPrivateProperty", { + visitor: ["decorators", "key", "typeAnnotation", "value"], + builder: ["key", "value", "decorators", "static"], + aliases: ["Property", "Private"], + fields: { + key: { + validate: (0, _utils.assertNodeType)("PrivateName") + }, + value: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + }, + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + }, + static: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + definite: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + variance: { + validate: (0, _utils.assertNodeType)("Variance"), + optional: true + } + } + }); + defineType("ClassPrivateMethod", { + builder: ["kind", "key", "params", "body", "static"], + visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"], + aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method", "Private"], + fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), { + kind: { + validate: (0, _utils.assertOneOf)("get", "set", "method"), + default: "method" + }, + key: { + validate: (0, _utils.assertNodeType)("PrivateName") + }, + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + } + }) + }); + defineType("PrivateName", { + visitor: ["id"], + aliases: ["Private"], + fields: { + id: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + defineType("StaticBlock", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("Statement") + }, + aliases: ["Scopable", "BlockParent", "FunctionParent"] + }); + + + return core; +} + +var flow$1 = {}; + +var hasRequiredFlow$1; + +function requireFlow$1 () { + if (hasRequiredFlow$1) return flow$1; + hasRequiredFlow$1 = 1; + + var _core = requireCore(); + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("Flow"); + const defineInterfaceishType = name => { + const isDeclareClass = name === "DeclareClass"; + defineType(name, { + builder: ["id", "typeParameters", "extends", "body"], + visitor: ["id", "typeParameters", "extends", ...(isDeclareClass ? ["mixins", "implements"] : []), "body"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")) + }, isDeclareClass ? { + mixins: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")), + implements: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ClassImplements")) + } : {}, { + body: (0, _utils.validateType)("ObjectTypeAnnotation") + }) + }); + }; + defineType("AnyTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ArrayTypeAnnotation", { + visitor: ["elementType"], + aliases: ["FlowType"], + fields: { + elementType: (0, _utils.validateType)("FlowType") + } + }); + defineType("BooleanTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("BooleanLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("NullLiteralTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ClassImplements", { + visitor: ["id", "typeParameters"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineInterfaceishType("DeclareClass"); + defineType("DeclareFunction", { + visitor: ["id"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + predicate: (0, _utils.validateOptionalType)("DeclaredPredicate") + } + }); + defineInterfaceishType("DeclareInterface"); + defineType("DeclareModule", { + builder: ["id", "body", "kind"], + visitor: ["id", "body"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + body: (0, _utils.validateType)("BlockStatement"), + kind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("CommonJS", "ES")) + } + }); + defineType("DeclareModuleExports", { + visitor: ["typeAnnotation"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + typeAnnotation: (0, _utils.validateType)("TypeAnnotation") + } + }); + defineType("DeclareTypeAlias", { + visitor: ["id", "typeParameters", "right"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + right: (0, _utils.validateType)("FlowType") + } + }); + defineType("DeclareOpaqueType", { + visitor: ["id", "typeParameters", "supertype"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + supertype: (0, _utils.validateOptionalType)("FlowType"), + impltype: (0, _utils.validateOptionalType)("FlowType") + } + }); + defineType("DeclareVariable", { + visitor: ["id"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("DeclareExportDeclaration", { + visitor: ["declaration", "specifiers", "source", "attributes"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + declaration: (0, _utils.validateOptionalType)("Flow"), + specifiers: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ExportSpecifier", "ExportNamespaceSpecifier")), + source: (0, _utils.validateOptionalType)("StringLiteral"), + default: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + }, _core.importAttributes) + }); + defineType("DeclareExportAllDeclaration", { + visitor: ["source", "attributes"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: Object.assign({ + source: (0, _utils.validateType)("StringLiteral"), + exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value")) + }, _core.importAttributes) + }); + defineType("DeclaredPredicate", { + visitor: ["value"], + aliases: ["FlowPredicate"], + fields: { + value: (0, _utils.validateType)("Flow") + } + }); + defineType("ExistsTypeAnnotation", { + aliases: ["FlowType"] + }); + defineType("FunctionTypeAnnotation", { + visitor: ["typeParameters", "params", "rest", "returnType"], + aliases: ["FlowType"], + fields: { + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + params: (0, _utils.validateArrayOfType)("FunctionTypeParam"), + rest: (0, _utils.validateOptionalType)("FunctionTypeParam"), + this: (0, _utils.validateOptionalType)("FunctionTypeParam"), + returnType: (0, _utils.validateType)("FlowType") + } + }); + defineType("FunctionTypeParam", { + visitor: ["name", "typeAnnotation"], + fields: { + name: (0, _utils.validateOptionalType)("Identifier"), + typeAnnotation: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("GenericTypeAnnotation", { + visitor: ["id", "typeParameters"], + aliases: ["FlowType"], + fields: { + id: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineType("InferredPredicate", { + aliases: ["FlowPredicate"] + }); + defineType("InterfaceExtends", { + visitor: ["id", "typeParameters"], + fields: { + id: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation") + } + }); + defineInterfaceishType("InterfaceDeclaration"); + defineType("InterfaceTypeAnnotation", { + visitor: ["extends", "body"], + aliases: ["FlowType"], + fields: { + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")), + body: (0, _utils.validateType)("ObjectTypeAnnotation") + } + }); + defineType("IntersectionTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("MixedTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("EmptyTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("NullableTypeAnnotation", { + visitor: ["typeAnnotation"], + aliases: ["FlowType"], + fields: { + typeAnnotation: (0, _utils.validateType)("FlowType") + } + }); + defineType("NumberLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("number")) + } + }); + defineType("NumberTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ObjectTypeAnnotation", { + visitor: ["properties", "indexers", "callProperties", "internalSlots"], + aliases: ["FlowType"], + builder: ["properties", "indexers", "callProperties", "internalSlots", "exact"], + fields: { + properties: (0, _utils.validate)((0, _utils.arrayOfType)("ObjectTypeProperty", "ObjectTypeSpreadProperty")), + indexers: { + validate: (0, _utils.arrayOfType)("ObjectTypeIndexer"), + optional: true, + default: [] + }, + callProperties: { + validate: (0, _utils.arrayOfType)("ObjectTypeCallProperty"), + optional: true, + default: [] + }, + internalSlots: { + validate: (0, _utils.arrayOfType)("ObjectTypeInternalSlot"), + optional: true, + default: [] + }, + exact: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + }, + inexact: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeInternalSlot", { + visitor: ["id", "value"], + builder: ["id", "value", "optional", "static", "method"], + aliases: ["UserWhitespacable"], + fields: { + id: (0, _utils.validateType)("Identifier"), + value: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + method: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeCallProperty", { + visitor: ["value"], + aliases: ["UserWhitespacable"], + fields: { + value: (0, _utils.validateType)("FlowType"), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeIndexer", { + visitor: ["variance", "id", "key", "value"], + builder: ["id", "key", "value", "variance"], + aliases: ["UserWhitespacable"], + fields: { + id: (0, _utils.validateOptionalType)("Identifier"), + key: (0, _utils.validateType)("FlowType"), + value: (0, _utils.validateType)("FlowType"), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + variance: (0, _utils.validateOptionalType)("Variance") + } + }); + defineType("ObjectTypeProperty", { + visitor: ["key", "value", "variance"], + aliases: ["UserWhitespacable"], + fields: { + key: (0, _utils.validateType)("Identifier", "StringLiteral"), + value: (0, _utils.validateType)("FlowType"), + kind: (0, _utils.validate)((0, _utils.assertOneOf)("init", "get", "set")), + static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + proto: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + variance: (0, _utils.validateOptionalType)("Variance"), + method: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("ObjectTypeSpreadProperty", { + visitor: ["argument"], + aliases: ["UserWhitespacable"], + fields: { + argument: (0, _utils.validateType)("FlowType") + } + }); + defineType("OpaqueType", { + visitor: ["id", "typeParameters", "supertype", "impltype"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + supertype: (0, _utils.validateOptionalType)("FlowType"), + impltype: (0, _utils.validateType)("FlowType") + } + }); + defineType("QualifiedTypeIdentifier", { + visitor: ["qualification", "id"], + builder: ["id", "qualification"], + fields: { + id: (0, _utils.validateType)("Identifier"), + qualification: (0, _utils.validateType)("Identifier", "QualifiedTypeIdentifier") + } + }); + defineType("StringLiteralTypeAnnotation", { + builder: ["value"], + aliases: ["FlowType"], + fields: { + value: (0, _utils.validate)((0, _utils.assertValueType)("string")) + } + }); + defineType("StringTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("SymbolTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("ThisTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("TupleTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("TypeofTypeAnnotation", { + visitor: ["argument"], + aliases: ["FlowType"], + fields: { + argument: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeAlias", { + visitor: ["id", "typeParameters", "right"], + aliases: ["FlowDeclaration", "Statement", "Declaration"], + fields: { + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"), + right: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeAnnotation", { + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("FlowType") + } + }); + defineType("TypeCastExpression", { + visitor: ["expression", "typeAnnotation"], + aliases: ["ExpressionWrapper", "Expression"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeAnnotation: (0, _utils.validateType)("TypeAnnotation") + } + }); + defineType("TypeParameter", { + visitor: ["bound", "default", "variance"], + fields: { + name: (0, _utils.validate)((0, _utils.assertValueType)("string")), + bound: (0, _utils.validateOptionalType)("TypeAnnotation"), + default: (0, _utils.validateOptionalType)("FlowType"), + variance: (0, _utils.validateOptionalType)("Variance") + } + }); + defineType("TypeParameterDeclaration", { + visitor: ["params"], + fields: { + params: (0, _utils.validate)((0, _utils.arrayOfType)("TypeParameter")) + } + }); + defineType("TypeParameterInstantiation", { + visitor: ["params"], + fields: { + params: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("UnionTypeAnnotation", { + visitor: ["types"], + aliases: ["FlowType"], + fields: { + types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType")) + } + }); + defineType("Variance", { + builder: ["kind"], + fields: { + kind: (0, _utils.validate)((0, _utils.assertOneOf)("minus", "plus")) + } + }); + defineType("VoidTypeAnnotation", { + aliases: ["FlowType", "FlowBaseAnnotation"] + }); + defineType("EnumDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "body"], + fields: { + id: (0, _utils.validateType)("Identifier"), + body: (0, _utils.validateType)("EnumBooleanBody", "EnumNumberBody", "EnumStringBody", "EnumSymbolBody") + } + }); + defineType("EnumBooleanBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumBooleanMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumNumberBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumNumberMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumStringBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")), + members: (0, _utils.validateArrayOfType)("EnumStringMember", "EnumDefaultedMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumSymbolBody", { + aliases: ["EnumBody"], + visitor: ["members"], + fields: { + members: (0, _utils.validateArrayOfType)("EnumDefaultedMember"), + hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + defineType("EnumBooleanMember", { + aliases: ["EnumMember"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("BooleanLiteral") + } + }); + defineType("EnumNumberMember", { + aliases: ["EnumMember"], + visitor: ["id", "init"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("NumericLiteral") + } + }); + defineType("EnumStringMember", { + aliases: ["EnumMember"], + visitor: ["id", "init"], + fields: { + id: (0, _utils.validateType)("Identifier"), + init: (0, _utils.validateType)("StringLiteral") + } + }); + defineType("EnumDefaultedMember", { + aliases: ["EnumMember"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("IndexedAccessType", { + visitor: ["objectType", "indexType"], + aliases: ["FlowType"], + fields: { + objectType: (0, _utils.validateType)("FlowType"), + indexType: (0, _utils.validateType)("FlowType") + } + }); + defineType("OptionalIndexedAccessType", { + visitor: ["objectType", "indexType"], + aliases: ["FlowType"], + fields: { + objectType: (0, _utils.validateType)("FlowType"), + indexType: (0, _utils.validateType)("FlowType"), + optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")) + } + }); + + + return flow$1; +} + +var jsx$1 = {}; + +var hasRequiredJsx$1; + +function requireJsx$1 () { + if (hasRequiredJsx$1) return jsx$1; + hasRequiredJsx$1 = 1; + + var _utils = requireUtils(); + const defineType = (0, _utils.defineAliasedType)("JSX"); + defineType("JSXAttribute", { + visitor: ["name", "value"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXNamespacedName") + }, + value: { + optional: true, + validate: (0, _utils.assertNodeType)("JSXElement", "JSXFragment", "StringLiteral", "JSXExpressionContainer") + } + } + }); + defineType("JSXClosingElement", { + visitor: ["name"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression", "JSXNamespacedName") + } + } + }); + defineType("JSXElement", { + builder: ["openingElement", "closingElement", "children", "selfClosing"], + visitor: ["openingElement", "children", "closingElement"], + aliases: ["Immutable", "Expression"], + fields: Object.assign({ + openingElement: { + validate: (0, _utils.assertNodeType)("JSXOpeningElement") + }, + closingElement: { + optional: true, + validate: (0, _utils.assertNodeType)("JSXClosingElement") + }, + children: (0, _utils.validateArrayOfType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment") + }, { + selfClosing: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + } + }) + }); + defineType("JSXEmptyExpression", {}); + defineType("JSXExpressionContainer", { + visitor: ["expression"], + aliases: ["Immutable"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression", "JSXEmptyExpression") + } + } + }); + defineType("JSXSpreadChild", { + visitor: ["expression"], + aliases: ["Immutable"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("JSXIdentifier", { + builder: ["name"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("JSXMemberExpression", { + visitor: ["object", "property"], + fields: { + object: { + validate: (0, _utils.assertNodeType)("JSXMemberExpression", "JSXIdentifier") + }, + property: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + } + } + }); + defineType("JSXNamespacedName", { + visitor: ["namespace", "name"], + fields: { + namespace: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + }, + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier") + } + } + }); + defineType("JSXOpeningElement", { + builder: ["name", "attributes", "selfClosing"], + visitor: ["name", "attributes"], + aliases: ["Immutable"], + fields: { + name: { + validate: (0, _utils.assertNodeType)("JSXIdentifier", "JSXMemberExpression", "JSXNamespacedName") + }, + selfClosing: { + default: false + }, + attributes: (0, _utils.validateArrayOfType)("JSXAttribute", "JSXSpreadAttribute"), + typeParameters: { + validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"), + optional: true + } + } + }); + defineType("JSXSpreadAttribute", { + visitor: ["argument"], + fields: { + argument: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + defineType("JSXText", { + aliases: ["Immutable"], + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + defineType("JSXFragment", { + builder: ["openingFragment", "closingFragment", "children"], + visitor: ["openingFragment", "children", "closingFragment"], + aliases: ["Immutable", "Expression"], + fields: { + openingFragment: { + validate: (0, _utils.assertNodeType)("JSXOpeningFragment") + }, + closingFragment: { + validate: (0, _utils.assertNodeType)("JSXClosingFragment") + }, + children: (0, _utils.validateArrayOfType)("JSXText", "JSXExpressionContainer", "JSXSpreadChild", "JSXElement", "JSXFragment") + } + }); + defineType("JSXOpeningFragment", { + aliases: ["Immutable"] + }); + defineType("JSXClosingFragment", { + aliases: ["Immutable"] + }); + + + return jsx$1; +} + +var misc = {}; + +var placeholders = {}; + +var hasRequiredPlaceholders; + +function requirePlaceholders () { + if (hasRequiredPlaceholders) return placeholders; + hasRequiredPlaceholders = 1; + + Object.defineProperty(placeholders, "__esModule", { + value: true + }); + placeholders.PLACEHOLDERS_FLIPPED_ALIAS = placeholders.PLACEHOLDERS_ALIAS = placeholders.PLACEHOLDERS = void 0; + var _utils = requireUtils(); + const PLACEHOLDERS = placeholders.PLACEHOLDERS = ["Identifier", "StringLiteral", "Expression", "Statement", "Declaration", "BlockStatement", "ClassBody", "Pattern"]; + const PLACEHOLDERS_ALIAS = placeholders.PLACEHOLDERS_ALIAS = { + Declaration: ["Statement"], + Pattern: ["PatternLike", "LVal"] + }; + for (const type of PLACEHOLDERS) { + const alias = _utils.ALIAS_KEYS[type]; + if (alias != null && alias.length) PLACEHOLDERS_ALIAS[type] = alias; + } + const PLACEHOLDERS_FLIPPED_ALIAS = placeholders.PLACEHOLDERS_FLIPPED_ALIAS = {}; + Object.keys(PLACEHOLDERS_ALIAS).forEach(type => { + PLACEHOLDERS_ALIAS[type].forEach(alias => { + if (!hasOwnProperty.call(PLACEHOLDERS_FLIPPED_ALIAS, alias)) { + PLACEHOLDERS_FLIPPED_ALIAS[alias] = []; + } + PLACEHOLDERS_FLIPPED_ALIAS[alias].push(type); + }); + }); + + + return placeholders; +} + +var hasRequiredMisc; + +function requireMisc () { + if (hasRequiredMisc) return misc; + hasRequiredMisc = 1; + + var _utils = requireUtils(); + var _placeholders = requirePlaceholders(); + var _core = requireCore(); + const defineType = (0, _utils.defineAliasedType)("Miscellaneous"); + { + defineType("Noop", { + visitor: [] + }); + } + defineType("Placeholder", { + visitor: [], + builder: ["expectedNode", "name"], + fields: Object.assign({ + name: { + validate: (0, _utils.assertNodeType)("Identifier") + }, + expectedNode: { + validate: (0, _utils.assertOneOf)(..._placeholders.PLACEHOLDERS) + } + }, (0, _core.patternLikeCommon)()) + }); + defineType("V8IntrinsicIdentifier", { + builder: ["name"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + } + } + }); + + + return misc; +} + +var experimental = {}; + +var hasRequiredExperimental; + +function requireExperimental () { + if (hasRequiredExperimental) return experimental; + hasRequiredExperimental = 1; + + var _utils = requireUtils(); + (0, _utils.default)("ArgumentPlaceholder", {}); + (0, _utils.default)("BindExpression", { + visitor: ["object", "callee"], + aliases: ["Expression"], + fields: !process.env.BABEL_TYPES_8_BREAKING ? { + object: { + validate: Object.assign(() => {}, { + oneOfNodeTypes: ["Expression"] + }) + }, + callee: { + validate: Object.assign(() => {}, { + oneOfNodeTypes: ["Expression"] + }) + } + } : { + object: { + validate: (0, _utils.assertNodeType)("Expression") + }, + callee: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + (0, _utils.default)("ImportAttribute", { + visitor: ["key", "value"], + fields: { + key: { + validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral") + }, + value: { + validate: (0, _utils.assertNodeType)("StringLiteral") + } + } + }); + (0, _utils.default)("Decorator", { + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + } + }); + (0, _utils.default)("DoExpression", { + visitor: ["body"], + builder: ["body", "async"], + aliases: ["Expression"], + fields: { + body: { + validate: (0, _utils.assertNodeType)("BlockStatement") + }, + async: { + validate: (0, _utils.assertValueType)("boolean"), + default: false + } + } + }); + (0, _utils.default)("ExportDefaultSpecifier", { + visitor: ["exported"], + aliases: ["ModuleSpecifier"], + fields: { + exported: { + validate: (0, _utils.assertNodeType)("Identifier") + } + } + }); + (0, _utils.default)("RecordExpression", { + visitor: ["properties"], + aliases: ["Expression"], + fields: { + properties: (0, _utils.validateArrayOfType)("ObjectProperty", "SpreadElement") + } + }); + (0, _utils.default)("TupleExpression", { + fields: { + elements: { + validate: (0, _utils.arrayOfType)("Expression", "SpreadElement"), + default: [] + } + }, + visitor: ["elements"], + aliases: ["Expression"] + }); + { + (0, _utils.default)("DecimalLiteral", { + builder: ["value"], + fields: { + value: { + validate: (0, _utils.assertValueType)("string") + } + }, + aliases: ["Expression", "Pureish", "Literal", "Immutable"] + }); + } + (0, _utils.default)("ModuleExpression", { + visitor: ["body"], + fields: { + body: { + validate: (0, _utils.assertNodeType)("Program") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("TopicReference", { + aliases: ["Expression"] + }); + (0, _utils.default)("PipelineTopicExpression", { + builder: ["expression"], + visitor: ["expression"], + fields: { + expression: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("PipelineBareFunction", { + builder: ["callee"], + visitor: ["callee"], + fields: { + callee: { + validate: (0, _utils.assertNodeType)("Expression") + } + }, + aliases: ["Expression"] + }); + (0, _utils.default)("PipelinePrimaryTopicReference", { + aliases: ["Expression"] + }); + + + return experimental; +} + +var typescript$1 = {}; + +var hasRequiredTypescript$1; + +function requireTypescript$1 () { + if (hasRequiredTypescript$1) return typescript$1; + hasRequiredTypescript$1 = 1; + + var _utils = requireUtils(); + var _core = requireCore(); + var _is = requireIs(); + const defineType = (0, _utils.defineAliasedType)("TypeScript"); + const bool = (0, _utils.assertValueType)("boolean"); + const tSFunctionTypeAnnotationCommon = () => ({ + returnType: { + validate: (0, _utils.assertNodeType)("TSTypeAnnotation", "Noop"), + optional: true + }, + typeParameters: { + validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration", "Noop"), + optional: true + } + }); + defineType("TSParameterProperty", { + aliases: ["LVal"], + visitor: ["parameter"], + fields: { + accessibility: { + validate: (0, _utils.assertOneOf)("public", "private", "protected"), + optional: true + }, + readonly: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + parameter: { + validate: (0, _utils.assertNodeType)("Identifier", "AssignmentPattern") + }, + override: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + decorators: { + validate: (0, _utils.arrayOfType)("Decorator"), + optional: true + } + } + }); + defineType("TSDeclareFunction", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "params", "returnType"], + fields: Object.assign({}, (0, _core.functionDeclarationCommon)(), tSFunctionTypeAnnotationCommon()) + }); + defineType("TSDeclareMethod", { + visitor: ["decorators", "key", "typeParameters", "params", "returnType"], + fields: Object.assign({}, (0, _core.classMethodOrDeclareMethodCommon)(), tSFunctionTypeAnnotationCommon()) + }); + defineType("TSQualifiedName", { + aliases: ["TSEntityName"], + visitor: ["left", "right"], + fields: { + left: (0, _utils.validateType)("TSEntityName"), + right: (0, _utils.validateType)("Identifier") + } + }); + const signatureDeclarationCommon = () => ({ + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + ["parameters"]: (0, _utils.validateArrayOfType)("ArrayPattern", "Identifier", "ObjectPattern", "RestElement"), + ["typeAnnotation"]: (0, _utils.validateOptionalType)("TSTypeAnnotation") + }); + const callConstructSignatureDeclaration = { + aliases: ["TSTypeElement"], + visitor: ["typeParameters", "parameters", "typeAnnotation"], + fields: signatureDeclarationCommon() + }; + defineType("TSCallSignatureDeclaration", callConstructSignatureDeclaration); + defineType("TSConstructSignatureDeclaration", callConstructSignatureDeclaration); + const namedTypeElementCommon = () => ({ + key: (0, _utils.validateType)("Expression"), + computed: { + default: false + }, + optional: (0, _utils.validateOptional)(bool) + }); + defineType("TSPropertySignature", { + aliases: ["TSTypeElement"], + visitor: ["key", "typeAnnotation"], + fields: Object.assign({}, namedTypeElementCommon(), { + readonly: (0, _utils.validateOptional)(bool), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"), + kind: { + validate: (0, _utils.assertOneOf)("get", "set") + } + }) + }); + defineType("TSMethodSignature", { + aliases: ["TSTypeElement"], + visitor: ["key", "typeParameters", "parameters", "typeAnnotation"], + fields: Object.assign({}, signatureDeclarationCommon(), namedTypeElementCommon(), { + kind: { + validate: (0, _utils.assertOneOf)("method", "get", "set") + } + }) + }); + defineType("TSIndexSignature", { + aliases: ["TSTypeElement"], + visitor: ["parameters", "typeAnnotation"], + fields: { + readonly: (0, _utils.validateOptional)(bool), + static: (0, _utils.validateOptional)(bool), + parameters: (0, _utils.validateArrayOfType)("Identifier"), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation") + } + }); + const tsKeywordTypes = ["TSAnyKeyword", "TSBooleanKeyword", "TSBigIntKeyword", "TSIntrinsicKeyword", "TSNeverKeyword", "TSNullKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSUndefinedKeyword", "TSUnknownKeyword", "TSVoidKeyword"]; + for (const type of tsKeywordTypes) { + defineType(type, { + aliases: ["TSType", "TSBaseType"], + visitor: [], + fields: {} + }); + } + defineType("TSThisType", { + aliases: ["TSType", "TSBaseType"], + visitor: [], + fields: {} + }); + const fnOrCtrBase = { + aliases: ["TSType"], + visitor: ["typeParameters", "parameters", "typeAnnotation"] + }; + defineType("TSFunctionType", Object.assign({}, fnOrCtrBase, { + fields: signatureDeclarationCommon() + })); + defineType("TSConstructorType", Object.assign({}, fnOrCtrBase, { + fields: Object.assign({}, signatureDeclarationCommon(), { + abstract: (0, _utils.validateOptional)(bool) + }) + })); + defineType("TSTypeReference", { + aliases: ["TSType"], + visitor: ["typeName", "typeParameters"], + fields: { + typeName: (0, _utils.validateType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + defineType("TSTypePredicate", { + aliases: ["TSType"], + visitor: ["parameterName", "typeAnnotation"], + builder: ["parameterName", "typeAnnotation", "asserts"], + fields: { + parameterName: (0, _utils.validateType)("Identifier", "TSThisType"), + typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"), + asserts: (0, _utils.validateOptional)(bool) + } + }); + defineType("TSTypeQuery", { + aliases: ["TSType"], + visitor: ["exprName", "typeParameters"], + fields: { + exprName: (0, _utils.validateType)("TSEntityName", "TSImportType"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + defineType("TSTypeLiteral", { + aliases: ["TSType"], + visitor: ["members"], + fields: { + members: (0, _utils.validateArrayOfType)("TSTypeElement") + } + }); + defineType("TSArrayType", { + aliases: ["TSType"], + visitor: ["elementType"], + fields: { + elementType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSTupleType", { + aliases: ["TSType"], + visitor: ["elementTypes"], + fields: { + elementTypes: (0, _utils.validateArrayOfType)("TSType", "TSNamedTupleMember") + } + }); + defineType("TSOptionalType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSRestType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSNamedTupleMember", { + visitor: ["label", "elementType"], + builder: ["label", "elementType", "optional"], + fields: { + label: (0, _utils.validateType)("Identifier"), + optional: { + validate: bool, + default: false + }, + elementType: (0, _utils.validateType)("TSType") + } + }); + const unionOrIntersection = { + aliases: ["TSType"], + visitor: ["types"], + fields: { + types: (0, _utils.validateArrayOfType)("TSType") + } + }; + defineType("TSUnionType", unionOrIntersection); + defineType("TSIntersectionType", unionOrIntersection); + defineType("TSConditionalType", { + aliases: ["TSType"], + visitor: ["checkType", "extendsType", "trueType", "falseType"], + fields: { + checkType: (0, _utils.validateType)("TSType"), + extendsType: (0, _utils.validateType)("TSType"), + trueType: (0, _utils.validateType)("TSType"), + falseType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSInferType", { + aliases: ["TSType"], + visitor: ["typeParameter"], + fields: { + typeParameter: (0, _utils.validateType)("TSTypeParameter") + } + }); + defineType("TSParenthesizedType", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSTypeOperator", { + aliases: ["TSType"], + visitor: ["typeAnnotation"], + fields: { + operator: (0, _utils.validate)((0, _utils.assertValueType)("string")), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSIndexedAccessType", { + aliases: ["TSType"], + visitor: ["objectType", "indexType"], + fields: { + objectType: (0, _utils.validateType)("TSType"), + indexType: (0, _utils.validateType)("TSType") + } + }); + defineType("TSMappedType", { + aliases: ["TSType"], + visitor: ["typeParameter", "nameType", "typeAnnotation"], + builder: ["typeParameter", "typeAnnotation", "nameType"], + fields: Object.assign({}, { + typeParameter: (0, _utils.validateType)("TSTypeParameter") + }, { + readonly: (0, _utils.validateOptional)((0, _utils.assertOneOf)(true, false, "+", "-")), + optional: (0, _utils.validateOptional)((0, _utils.assertOneOf)(true, false, "+", "-")), + typeAnnotation: (0, _utils.validateOptionalType)("TSType"), + nameType: (0, _utils.validateOptionalType)("TSType") + }) + }); + defineType("TSLiteralType", { + aliases: ["TSType", "TSBaseType"], + visitor: ["literal"], + fields: { + literal: { + validate: function () { + const unaryExpression = (0, _utils.assertNodeType)("NumericLiteral", "BigIntLiteral"); + const unaryOperator = (0, _utils.assertOneOf)("-"); + const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral"); + function validator(parent, key, node) { + if ((0, _is.default)("UnaryExpression", node)) { + unaryOperator(node, "operator", node.operator); + unaryExpression(node, "argument", node.argument); + } else { + literal(parent, key, node); + } + } + validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "TemplateLiteral", "UnaryExpression"]; + return validator; + }() + } + } + }); + const expressionWithTypeArguments = { + aliases: ["TSType"], + visitor: ["expression", "typeParameters"], + fields: { + expression: (0, _utils.validateType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }; + { + defineType("TSExpressionWithTypeArguments", expressionWithTypeArguments); + } + defineType("TSInterfaceDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "extends", "body"], + fields: { + declare: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("TSExpressionWithTypeArguments")), + body: (0, _utils.validateType)("TSInterfaceBody") + } + }); + defineType("TSInterfaceBody", { + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("TSTypeElement") + } + }); + defineType("TSTypeAliasDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "typeParameters", "typeAnnotation"], + fields: { + declare: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }); + defineType("TSInstantiationExpression", { + aliases: ["Expression"], + visitor: ["expression", "typeParameters"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation") + } + }); + const TSTypeExpression = { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["expression", "typeAnnotation"], + fields: { + expression: (0, _utils.validateType)("Expression"), + typeAnnotation: (0, _utils.validateType)("TSType") + } + }; + defineType("TSAsExpression", TSTypeExpression); + defineType("TSSatisfiesExpression", TSTypeExpression); + defineType("TSTypeAssertion", { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["typeAnnotation", "expression"], + fields: { + typeAnnotation: (0, _utils.validateType)("TSType"), + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSEnumDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "members"], + fields: { + declare: (0, _utils.validateOptional)(bool), + const: (0, _utils.validateOptional)(bool), + id: (0, _utils.validateType)("Identifier"), + members: (0, _utils.validateArrayOfType)("TSEnumMember"), + initializer: (0, _utils.validateOptionalType)("Expression") + } + }); + defineType("TSEnumMember", { + visitor: ["id", "initializer"], + fields: { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + initializer: (0, _utils.validateOptionalType)("Expression") + } + }); + defineType("TSModuleDeclaration", { + aliases: ["Statement", "Declaration"], + visitor: ["id", "body"], + fields: Object.assign({ + kind: { + validate: (0, _utils.assertOneOf)("global", "module", "namespace") + }, + declare: (0, _utils.validateOptional)(bool) + }, { + global: (0, _utils.validateOptional)(bool) + }, { + id: (0, _utils.validateType)("Identifier", "StringLiteral"), + body: (0, _utils.validateType)("TSModuleBlock", "TSModuleDeclaration") + }) + }); + defineType("TSModuleBlock", { + aliases: ["Scopable", "Block", "BlockParent", "FunctionParent"], + visitor: ["body"], + fields: { + body: (0, _utils.validateArrayOfType)("Statement") + } + }); + defineType("TSImportType", { + aliases: ["TSType"], + visitor: ["argument", "qualifier", "typeParameters"], + fields: { + argument: (0, _utils.validateType)("StringLiteral"), + qualifier: (0, _utils.validateOptionalType)("TSEntityName"), + typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation"), + options: { + validate: (0, _utils.assertNodeType)("Expression"), + optional: true + } + } + }); + defineType("TSImportEqualsDeclaration", { + aliases: ["Statement"], + visitor: ["id", "moduleReference"], + fields: { + isExport: (0, _utils.validate)(bool), + id: (0, _utils.validateType)("Identifier"), + moduleReference: (0, _utils.validateType)("TSEntityName", "TSExternalModuleReference"), + importKind: { + validate: (0, _utils.assertOneOf)("type", "value"), + optional: true + } + } + }); + defineType("TSExternalModuleReference", { + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("StringLiteral") + } + }); + defineType("TSNonNullExpression", { + aliases: ["Expression", "LVal", "PatternLike"], + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSExportAssignment", { + aliases: ["Statement"], + visitor: ["expression"], + fields: { + expression: (0, _utils.validateType)("Expression") + } + }); + defineType("TSNamespaceExportDeclaration", { + aliases: ["Statement"], + visitor: ["id"], + fields: { + id: (0, _utils.validateType)("Identifier") + } + }); + defineType("TSTypeAnnotation", { + visitor: ["typeAnnotation"], + fields: { + typeAnnotation: { + validate: (0, _utils.assertNodeType)("TSType") + } + } + }); + defineType("TSTypeParameterInstantiation", { + visitor: ["params"], + fields: { + params: (0, _utils.validateArrayOfType)("TSType") + } + }); + defineType("TSTypeParameterDeclaration", { + visitor: ["params"], + fields: { + params: (0, _utils.validateArrayOfType)("TSTypeParameter") + } + }); + defineType("TSTypeParameter", { + builder: ["constraint", "default", "name"], + visitor: ["constraint", "default"], + fields: { + name: { + validate: (0, _utils.assertValueType)("string") + }, + in: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + out: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + const: { + validate: (0, _utils.assertValueType)("boolean"), + optional: true + }, + constraint: { + validate: (0, _utils.assertNodeType)("TSType"), + optional: true + }, + default: { + validate: (0, _utils.assertNodeType)("TSType"), + optional: true + } + } + }); + + + return typescript$1; +} + +var deprecatedAliases = {}; + +var hasRequiredDeprecatedAliases; + +function requireDeprecatedAliases () { + if (hasRequiredDeprecatedAliases) return deprecatedAliases; + hasRequiredDeprecatedAliases = 1; + + Object.defineProperty(deprecatedAliases, "__esModule", { + value: true + }); + deprecatedAliases.DEPRECATED_ALIASES = void 0; + deprecatedAliases.DEPRECATED_ALIASES = { + ModuleDeclaration: "ImportOrExportDeclaration" + }; + + + return deprecatedAliases; +} + +var hasRequiredDefinitions; + +function requireDefinitions () { + if (hasRequiredDefinitions) return definitions; + hasRequiredDefinitions = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "ALIAS_KEYS", { + enumerable: true, + get: function () { + return _utils.ALIAS_KEYS; + } + }); + Object.defineProperty(exports, "BUILDER_KEYS", { + enumerable: true, + get: function () { + return _utils.BUILDER_KEYS; + } + }); + Object.defineProperty(exports, "DEPRECATED_ALIASES", { + enumerable: true, + get: function () { + return _deprecatedAliases.DEPRECATED_ALIASES; + } + }); + Object.defineProperty(exports, "DEPRECATED_KEYS", { + enumerable: true, + get: function () { + return _utils.DEPRECATED_KEYS; + } + }); + Object.defineProperty(exports, "FLIPPED_ALIAS_KEYS", { + enumerable: true, + get: function () { + return _utils.FLIPPED_ALIAS_KEYS; + } + }); + Object.defineProperty(exports, "NODE_FIELDS", { + enumerable: true, + get: function () { + return _utils.NODE_FIELDS; + } + }); + Object.defineProperty(exports, "NODE_PARENT_VALIDATIONS", { + enumerable: true, + get: function () { + return _utils.NODE_PARENT_VALIDATIONS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_ALIAS; + } + }); + Object.defineProperty(exports, "PLACEHOLDERS_FLIPPED_ALIAS", { + enumerable: true, + get: function () { + return _placeholders.PLACEHOLDERS_FLIPPED_ALIAS; + } + }); + exports.TYPES = void 0; + Object.defineProperty(exports, "VISITOR_KEYS", { + enumerable: true, + get: function () { + return _utils.VISITOR_KEYS; + } + }); + requireCore(); + requireFlow$1(); + requireJsx$1(); + requireMisc(); + requireExperimental(); + requireTypescript$1(); + var _utils = requireUtils(); + var _placeholders = requirePlaceholders(); + var _deprecatedAliases = requireDeprecatedAliases(); + Object.keys(_deprecatedAliases.DEPRECATED_ALIASES).forEach(deprecatedAlias => { + _utils.FLIPPED_ALIAS_KEYS[deprecatedAlias] = _utils.FLIPPED_ALIAS_KEYS[_deprecatedAliases.DEPRECATED_ALIASES[deprecatedAlias]]; + }); + exports.TYPES = [].concat(Object.keys(_utils.VISITOR_KEYS), Object.keys(_utils.FLIPPED_ALIAS_KEYS), Object.keys(_utils.DEPRECATED_KEYS)); + + +} (definitions)); + return definitions; +} + +var hasRequiredValidate; + +function requireValidate () { + if (hasRequiredValidate) return validate$1; + hasRequiredValidate = 1; + + Object.defineProperty(validate$1, "__esModule", { + value: true + }); + validate$1.default = validate; + validate$1.validateChild = validateChild; + validate$1.validateField = validateField; + validate$1.validateInternal = validateInternal; + var _index = requireDefinitions(); + function validate(node, key, val) { + if (!node) return; + const fields = _index.NODE_FIELDS[node.type]; + if (!fields) return; + const field = fields[key]; + validateField(node, key, val, field); + validateChild(node, key, val); + } + function validateInternal(field, node, key, val, maybeNode) { + if (!(field != null && field.validate)) return; + if (field.optional && val == null) return; + field.validate(node, key, val); + if (maybeNode) { + var _NODE_PARENT_VALIDATI; + const type = val.type; + if (type == null) return; + (_NODE_PARENT_VALIDATI = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI.call(_index.NODE_PARENT_VALIDATIONS, node, key, val); + } + } + function validateField(node, key, val, field) { + if (!(field != null && field.validate)) return; + if (field.optional && val == null) return; + field.validate(node, key, val); + } + function validateChild(node, key, val) { + var _NODE_PARENT_VALIDATI2; + const type = val == null ? void 0 : val.type; + if (type == null) return; + (_NODE_PARENT_VALIDATI2 = _index.NODE_PARENT_VALIDATIONS[type]) == null || _NODE_PARENT_VALIDATI2.call(_index.NODE_PARENT_VALIDATIONS, node, key, val); + } + + + return validate$1; +} + +var hasRequiredGenerated$2; + +function requireGenerated$2 () { + if (hasRequiredGenerated$2) return generated$2; + hasRequiredGenerated$2 = 1; + + Object.defineProperty(generated$2, "__esModule", { + value: true + }); + generated$2.anyTypeAnnotation = anyTypeAnnotation; + generated$2.argumentPlaceholder = argumentPlaceholder; + generated$2.arrayExpression = arrayExpression; + generated$2.arrayPattern = arrayPattern; + generated$2.arrayTypeAnnotation = arrayTypeAnnotation; + generated$2.arrowFunctionExpression = arrowFunctionExpression; + generated$2.assignmentExpression = assignmentExpression; + generated$2.assignmentPattern = assignmentPattern; + generated$2.awaitExpression = awaitExpression; + generated$2.bigIntLiteral = bigIntLiteral; + generated$2.binaryExpression = binaryExpression; + generated$2.bindExpression = bindExpression; + generated$2.blockStatement = blockStatement; + generated$2.booleanLiteral = booleanLiteral; + generated$2.booleanLiteralTypeAnnotation = booleanLiteralTypeAnnotation; + generated$2.booleanTypeAnnotation = booleanTypeAnnotation; + generated$2.breakStatement = breakStatement; + generated$2.callExpression = callExpression; + generated$2.catchClause = catchClause; + generated$2.classAccessorProperty = classAccessorProperty; + generated$2.classBody = classBody; + generated$2.classDeclaration = classDeclaration; + generated$2.classExpression = classExpression; + generated$2.classImplements = classImplements; + generated$2.classMethod = classMethod; + generated$2.classPrivateMethod = classPrivateMethod; + generated$2.classPrivateProperty = classPrivateProperty; + generated$2.classProperty = classProperty; + generated$2.conditionalExpression = conditionalExpression; + generated$2.continueStatement = continueStatement; + generated$2.debuggerStatement = debuggerStatement; + generated$2.decimalLiteral = decimalLiteral; + generated$2.declareClass = declareClass; + generated$2.declareExportAllDeclaration = declareExportAllDeclaration; + generated$2.declareExportDeclaration = declareExportDeclaration; + generated$2.declareFunction = declareFunction; + generated$2.declareInterface = declareInterface; + generated$2.declareModule = declareModule; + generated$2.declareModuleExports = declareModuleExports; + generated$2.declareOpaqueType = declareOpaqueType; + generated$2.declareTypeAlias = declareTypeAlias; + generated$2.declareVariable = declareVariable; + generated$2.declaredPredicate = declaredPredicate; + generated$2.decorator = decorator; + generated$2.directive = directive; + generated$2.directiveLiteral = directiveLiteral; + generated$2.doExpression = doExpression; + generated$2.doWhileStatement = doWhileStatement; + generated$2.emptyStatement = emptyStatement; + generated$2.emptyTypeAnnotation = emptyTypeAnnotation; + generated$2.enumBooleanBody = enumBooleanBody; + generated$2.enumBooleanMember = enumBooleanMember; + generated$2.enumDeclaration = enumDeclaration; + generated$2.enumDefaultedMember = enumDefaultedMember; + generated$2.enumNumberBody = enumNumberBody; + generated$2.enumNumberMember = enumNumberMember; + generated$2.enumStringBody = enumStringBody; + generated$2.enumStringMember = enumStringMember; + generated$2.enumSymbolBody = enumSymbolBody; + generated$2.existsTypeAnnotation = existsTypeAnnotation; + generated$2.exportAllDeclaration = exportAllDeclaration; + generated$2.exportDefaultDeclaration = exportDefaultDeclaration; + generated$2.exportDefaultSpecifier = exportDefaultSpecifier; + generated$2.exportNamedDeclaration = exportNamedDeclaration; + generated$2.exportNamespaceSpecifier = exportNamespaceSpecifier; + generated$2.exportSpecifier = exportSpecifier; + generated$2.expressionStatement = expressionStatement; + generated$2.file = file; + generated$2.forInStatement = forInStatement; + generated$2.forOfStatement = forOfStatement; + generated$2.forStatement = forStatement; + generated$2.functionDeclaration = functionDeclaration; + generated$2.functionExpression = functionExpression; + generated$2.functionTypeAnnotation = functionTypeAnnotation; + generated$2.functionTypeParam = functionTypeParam; + generated$2.genericTypeAnnotation = genericTypeAnnotation; + generated$2.identifier = identifier; + generated$2.ifStatement = ifStatement; + generated$2.import = _import; + generated$2.importAttribute = importAttribute; + generated$2.importDeclaration = importDeclaration; + generated$2.importDefaultSpecifier = importDefaultSpecifier; + generated$2.importExpression = importExpression; + generated$2.importNamespaceSpecifier = importNamespaceSpecifier; + generated$2.importSpecifier = importSpecifier; + generated$2.indexedAccessType = indexedAccessType; + generated$2.inferredPredicate = inferredPredicate; + generated$2.interfaceDeclaration = interfaceDeclaration; + generated$2.interfaceExtends = interfaceExtends; + generated$2.interfaceTypeAnnotation = interfaceTypeAnnotation; + generated$2.interpreterDirective = interpreterDirective; + generated$2.intersectionTypeAnnotation = intersectionTypeAnnotation; + generated$2.jSXAttribute = generated$2.jsxAttribute = jsxAttribute; + generated$2.jSXClosingElement = generated$2.jsxClosingElement = jsxClosingElement; + generated$2.jSXClosingFragment = generated$2.jsxClosingFragment = jsxClosingFragment; + generated$2.jSXElement = generated$2.jsxElement = jsxElement; + generated$2.jSXEmptyExpression = generated$2.jsxEmptyExpression = jsxEmptyExpression; + generated$2.jSXExpressionContainer = generated$2.jsxExpressionContainer = jsxExpressionContainer; + generated$2.jSXFragment = generated$2.jsxFragment = jsxFragment; + generated$2.jSXIdentifier = generated$2.jsxIdentifier = jsxIdentifier; + generated$2.jSXMemberExpression = generated$2.jsxMemberExpression = jsxMemberExpression; + generated$2.jSXNamespacedName = generated$2.jsxNamespacedName = jsxNamespacedName; + generated$2.jSXOpeningElement = generated$2.jsxOpeningElement = jsxOpeningElement; + generated$2.jSXOpeningFragment = generated$2.jsxOpeningFragment = jsxOpeningFragment; + generated$2.jSXSpreadAttribute = generated$2.jsxSpreadAttribute = jsxSpreadAttribute; + generated$2.jSXSpreadChild = generated$2.jsxSpreadChild = jsxSpreadChild; + generated$2.jSXText = generated$2.jsxText = jsxText; + generated$2.labeledStatement = labeledStatement; + generated$2.logicalExpression = logicalExpression; + generated$2.memberExpression = memberExpression; + generated$2.metaProperty = metaProperty; + generated$2.mixedTypeAnnotation = mixedTypeAnnotation; + generated$2.moduleExpression = moduleExpression; + generated$2.newExpression = newExpression; + generated$2.noop = noop; + generated$2.nullLiteral = nullLiteral; + generated$2.nullLiteralTypeAnnotation = nullLiteralTypeAnnotation; + generated$2.nullableTypeAnnotation = nullableTypeAnnotation; + generated$2.numberLiteral = NumberLiteral; + generated$2.numberLiteralTypeAnnotation = numberLiteralTypeAnnotation; + generated$2.numberTypeAnnotation = numberTypeAnnotation; + generated$2.numericLiteral = numericLiteral; + generated$2.objectExpression = objectExpression; + generated$2.objectMethod = objectMethod; + generated$2.objectPattern = objectPattern; + generated$2.objectProperty = objectProperty; + generated$2.objectTypeAnnotation = objectTypeAnnotation; + generated$2.objectTypeCallProperty = objectTypeCallProperty; + generated$2.objectTypeIndexer = objectTypeIndexer; + generated$2.objectTypeInternalSlot = objectTypeInternalSlot; + generated$2.objectTypeProperty = objectTypeProperty; + generated$2.objectTypeSpreadProperty = objectTypeSpreadProperty; + generated$2.opaqueType = opaqueType; + generated$2.optionalCallExpression = optionalCallExpression; + generated$2.optionalIndexedAccessType = optionalIndexedAccessType; + generated$2.optionalMemberExpression = optionalMemberExpression; + generated$2.parenthesizedExpression = parenthesizedExpression; + generated$2.pipelineBareFunction = pipelineBareFunction; + generated$2.pipelinePrimaryTopicReference = pipelinePrimaryTopicReference; + generated$2.pipelineTopicExpression = pipelineTopicExpression; + generated$2.placeholder = placeholder; + generated$2.privateName = privateName; + generated$2.program = program; + generated$2.qualifiedTypeIdentifier = qualifiedTypeIdentifier; + generated$2.recordExpression = recordExpression; + generated$2.regExpLiteral = regExpLiteral; + generated$2.regexLiteral = RegexLiteral; + generated$2.restElement = restElement; + generated$2.restProperty = RestProperty; + generated$2.returnStatement = returnStatement; + generated$2.sequenceExpression = sequenceExpression; + generated$2.spreadElement = spreadElement; + generated$2.spreadProperty = SpreadProperty; + generated$2.staticBlock = staticBlock; + generated$2.stringLiteral = stringLiteral; + generated$2.stringLiteralTypeAnnotation = stringLiteralTypeAnnotation; + generated$2.stringTypeAnnotation = stringTypeAnnotation; + generated$2.super = _super; + generated$2.switchCase = switchCase; + generated$2.switchStatement = switchStatement; + generated$2.symbolTypeAnnotation = symbolTypeAnnotation; + generated$2.taggedTemplateExpression = taggedTemplateExpression; + generated$2.templateElement = templateElement; + generated$2.templateLiteral = templateLiteral; + generated$2.thisExpression = thisExpression; + generated$2.thisTypeAnnotation = thisTypeAnnotation; + generated$2.throwStatement = throwStatement; + generated$2.topicReference = topicReference; + generated$2.tryStatement = tryStatement; + generated$2.tSAnyKeyword = generated$2.tsAnyKeyword = tsAnyKeyword; + generated$2.tSArrayType = generated$2.tsArrayType = tsArrayType; + generated$2.tSAsExpression = generated$2.tsAsExpression = tsAsExpression; + generated$2.tSBigIntKeyword = generated$2.tsBigIntKeyword = tsBigIntKeyword; + generated$2.tSBooleanKeyword = generated$2.tsBooleanKeyword = tsBooleanKeyword; + generated$2.tSCallSignatureDeclaration = generated$2.tsCallSignatureDeclaration = tsCallSignatureDeclaration; + generated$2.tSConditionalType = generated$2.tsConditionalType = tsConditionalType; + generated$2.tSConstructSignatureDeclaration = generated$2.tsConstructSignatureDeclaration = tsConstructSignatureDeclaration; + generated$2.tSConstructorType = generated$2.tsConstructorType = tsConstructorType; + generated$2.tSDeclareFunction = generated$2.tsDeclareFunction = tsDeclareFunction; + generated$2.tSDeclareMethod = generated$2.tsDeclareMethod = tsDeclareMethod; + generated$2.tSEnumDeclaration = generated$2.tsEnumDeclaration = tsEnumDeclaration; + generated$2.tSEnumMember = generated$2.tsEnumMember = tsEnumMember; + generated$2.tSExportAssignment = generated$2.tsExportAssignment = tsExportAssignment; + generated$2.tSExpressionWithTypeArguments = generated$2.tsExpressionWithTypeArguments = tsExpressionWithTypeArguments; + generated$2.tSExternalModuleReference = generated$2.tsExternalModuleReference = tsExternalModuleReference; + generated$2.tSFunctionType = generated$2.tsFunctionType = tsFunctionType; + generated$2.tSImportEqualsDeclaration = generated$2.tsImportEqualsDeclaration = tsImportEqualsDeclaration; + generated$2.tSImportType = generated$2.tsImportType = tsImportType; + generated$2.tSIndexSignature = generated$2.tsIndexSignature = tsIndexSignature; + generated$2.tSIndexedAccessType = generated$2.tsIndexedAccessType = tsIndexedAccessType; + generated$2.tSInferType = generated$2.tsInferType = tsInferType; + generated$2.tSInstantiationExpression = generated$2.tsInstantiationExpression = tsInstantiationExpression; + generated$2.tSInterfaceBody = generated$2.tsInterfaceBody = tsInterfaceBody; + generated$2.tSInterfaceDeclaration = generated$2.tsInterfaceDeclaration = tsInterfaceDeclaration; + generated$2.tSIntersectionType = generated$2.tsIntersectionType = tsIntersectionType; + generated$2.tSIntrinsicKeyword = generated$2.tsIntrinsicKeyword = tsIntrinsicKeyword; + generated$2.tSLiteralType = generated$2.tsLiteralType = tsLiteralType; + generated$2.tSMappedType = generated$2.tsMappedType = tsMappedType; + generated$2.tSMethodSignature = generated$2.tsMethodSignature = tsMethodSignature; + generated$2.tSModuleBlock = generated$2.tsModuleBlock = tsModuleBlock; + generated$2.tSModuleDeclaration = generated$2.tsModuleDeclaration = tsModuleDeclaration; + generated$2.tSNamedTupleMember = generated$2.tsNamedTupleMember = tsNamedTupleMember; + generated$2.tSNamespaceExportDeclaration = generated$2.tsNamespaceExportDeclaration = tsNamespaceExportDeclaration; + generated$2.tSNeverKeyword = generated$2.tsNeverKeyword = tsNeverKeyword; + generated$2.tSNonNullExpression = generated$2.tsNonNullExpression = tsNonNullExpression; + generated$2.tSNullKeyword = generated$2.tsNullKeyword = tsNullKeyword; + generated$2.tSNumberKeyword = generated$2.tsNumberKeyword = tsNumberKeyword; + generated$2.tSObjectKeyword = generated$2.tsObjectKeyword = tsObjectKeyword; + generated$2.tSOptionalType = generated$2.tsOptionalType = tsOptionalType; + generated$2.tSParameterProperty = generated$2.tsParameterProperty = tsParameterProperty; + generated$2.tSParenthesizedType = generated$2.tsParenthesizedType = tsParenthesizedType; + generated$2.tSPropertySignature = generated$2.tsPropertySignature = tsPropertySignature; + generated$2.tSQualifiedName = generated$2.tsQualifiedName = tsQualifiedName; + generated$2.tSRestType = generated$2.tsRestType = tsRestType; + generated$2.tSSatisfiesExpression = generated$2.tsSatisfiesExpression = tsSatisfiesExpression; + generated$2.tSStringKeyword = generated$2.tsStringKeyword = tsStringKeyword; + generated$2.tSSymbolKeyword = generated$2.tsSymbolKeyword = tsSymbolKeyword; + generated$2.tSThisType = generated$2.tsThisType = tsThisType; + generated$2.tSTupleType = generated$2.tsTupleType = tsTupleType; + generated$2.tSTypeAliasDeclaration = generated$2.tsTypeAliasDeclaration = tsTypeAliasDeclaration; + generated$2.tSTypeAnnotation = generated$2.tsTypeAnnotation = tsTypeAnnotation; + generated$2.tSTypeAssertion = generated$2.tsTypeAssertion = tsTypeAssertion; + generated$2.tSTypeLiteral = generated$2.tsTypeLiteral = tsTypeLiteral; + generated$2.tSTypeOperator = generated$2.tsTypeOperator = tsTypeOperator; + generated$2.tSTypeParameter = generated$2.tsTypeParameter = tsTypeParameter; + generated$2.tSTypeParameterDeclaration = generated$2.tsTypeParameterDeclaration = tsTypeParameterDeclaration; + generated$2.tSTypeParameterInstantiation = generated$2.tsTypeParameterInstantiation = tsTypeParameterInstantiation; + generated$2.tSTypePredicate = generated$2.tsTypePredicate = tsTypePredicate; + generated$2.tSTypeQuery = generated$2.tsTypeQuery = tsTypeQuery; + generated$2.tSTypeReference = generated$2.tsTypeReference = tsTypeReference; + generated$2.tSUndefinedKeyword = generated$2.tsUndefinedKeyword = tsUndefinedKeyword; + generated$2.tSUnionType = generated$2.tsUnionType = tsUnionType; + generated$2.tSUnknownKeyword = generated$2.tsUnknownKeyword = tsUnknownKeyword; + generated$2.tSVoidKeyword = generated$2.tsVoidKeyword = tsVoidKeyword; + generated$2.tupleExpression = tupleExpression; + generated$2.tupleTypeAnnotation = tupleTypeAnnotation; + generated$2.typeAlias = typeAlias; + generated$2.typeAnnotation = typeAnnotation; + generated$2.typeCastExpression = typeCastExpression; + generated$2.typeParameter = typeParameter; + generated$2.typeParameterDeclaration = typeParameterDeclaration; + generated$2.typeParameterInstantiation = typeParameterInstantiation; + generated$2.typeofTypeAnnotation = typeofTypeAnnotation; + generated$2.unaryExpression = unaryExpression; + generated$2.unionTypeAnnotation = unionTypeAnnotation; + generated$2.updateExpression = updateExpression; + generated$2.v8IntrinsicIdentifier = v8IntrinsicIdentifier; + generated$2.variableDeclaration = variableDeclaration; + generated$2.variableDeclarator = variableDeclarator; + generated$2.variance = variance; + generated$2.voidTypeAnnotation = voidTypeAnnotation; + generated$2.whileStatement = whileStatement; + generated$2.withStatement = withStatement; + generated$2.yieldExpression = yieldExpression; + var _validate = requireValidate(); + var _deprecationWarning = requireDeprecationWarning(); + var utils = requireUtils(); + const { + validateInternal: validate + } = _validate; + const { + NODE_FIELDS + } = utils; + function arrayExpression(elements = []) { + const node = { + type: "ArrayExpression", + elements + }; + const defs = NODE_FIELDS.ArrayExpression; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function assignmentExpression(operator, left, right) { + const node = { + type: "AssignmentExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.AssignmentExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function binaryExpression(operator, left, right) { + const node = { + type: "BinaryExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.BinaryExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function interpreterDirective(value) { + const node = { + type: "InterpreterDirective", + value + }; + const defs = NODE_FIELDS.InterpreterDirective; + validate(defs.value, node, "value", value); + return node; + } + function directive(value) { + const node = { + type: "Directive", + value + }; + const defs = NODE_FIELDS.Directive; + validate(defs.value, node, "value", value, 1); + return node; + } + function directiveLiteral(value) { + const node = { + type: "DirectiveLiteral", + value + }; + const defs = NODE_FIELDS.DirectiveLiteral; + validate(defs.value, node, "value", value); + return node; + } + function blockStatement(body, directives = []) { + const node = { + type: "BlockStatement", + body, + directives + }; + const defs = NODE_FIELDS.BlockStatement; + validate(defs.body, node, "body", body, 1); + validate(defs.directives, node, "directives", directives, 1); + return node; + } + function breakStatement(label = null) { + const node = { + type: "BreakStatement", + label + }; + const defs = NODE_FIELDS.BreakStatement; + validate(defs.label, node, "label", label, 1); + return node; + } + function callExpression(callee, _arguments) { + const node = { + type: "CallExpression", + callee, + arguments: _arguments + }; + const defs = NODE_FIELDS.CallExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + return node; + } + function catchClause(param = null, body) { + const node = { + type: "CatchClause", + param, + body + }; + const defs = NODE_FIELDS.CatchClause; + validate(defs.param, node, "param", param, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function conditionalExpression(test, consequent, alternate) { + const node = { + type: "ConditionalExpression", + test, + consequent, + alternate + }; + const defs = NODE_FIELDS.ConditionalExpression; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + validate(defs.alternate, node, "alternate", alternate, 1); + return node; + } + function continueStatement(label = null) { + const node = { + type: "ContinueStatement", + label + }; + const defs = NODE_FIELDS.ContinueStatement; + validate(defs.label, node, "label", label, 1); + return node; + } + function debuggerStatement() { + return { + type: "DebuggerStatement" + }; + } + function doWhileStatement(test, body) { + const node = { + type: "DoWhileStatement", + test, + body + }; + const defs = NODE_FIELDS.DoWhileStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function emptyStatement() { + return { + type: "EmptyStatement" + }; + } + function expressionStatement(expression) { + const node = { + type: "ExpressionStatement", + expression + }; + const defs = NODE_FIELDS.ExpressionStatement; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function file(program, comments = null, tokens = null) { + const node = { + type: "File", + program, + comments, + tokens + }; + const defs = NODE_FIELDS.File; + validate(defs.program, node, "program", program, 1); + validate(defs.comments, node, "comments", comments, 1); + validate(defs.tokens, node, "tokens", tokens); + return node; + } + function forInStatement(left, right, body) { + const node = { + type: "ForInStatement", + left, + right, + body + }; + const defs = NODE_FIELDS.ForInStatement; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function forStatement(init = null, test = null, update = null, body) { + const node = { + type: "ForStatement", + init, + test, + update, + body + }; + const defs = NODE_FIELDS.ForStatement; + validate(defs.init, node, "init", init, 1); + validate(defs.test, node, "test", test, 1); + validate(defs.update, node, "update", update, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function functionDeclaration(id = null, params, body, generator = false, async = false) { + const node = { + type: "FunctionDeclaration", + id, + params, + body, + generator, + async + }; + const defs = NODE_FIELDS.FunctionDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function functionExpression(id = null, params, body, generator = false, async = false) { + const node = { + type: "FunctionExpression", + id, + params, + body, + generator, + async + }; + const defs = NODE_FIELDS.FunctionExpression; + validate(defs.id, node, "id", id, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function identifier(name) { + const node = { + type: "Identifier", + name + }; + const defs = NODE_FIELDS.Identifier; + validate(defs.name, node, "name", name); + return node; + } + function ifStatement(test, consequent, alternate = null) { + const node = { + type: "IfStatement", + test, + consequent, + alternate + }; + const defs = NODE_FIELDS.IfStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + validate(defs.alternate, node, "alternate", alternate, 1); + return node; + } + function labeledStatement(label, body) { + const node = { + type: "LabeledStatement", + label, + body + }; + const defs = NODE_FIELDS.LabeledStatement; + validate(defs.label, node, "label", label, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function stringLiteral(value) { + const node = { + type: "StringLiteral", + value + }; + const defs = NODE_FIELDS.StringLiteral; + validate(defs.value, node, "value", value); + return node; + } + function numericLiteral(value) { + const node = { + type: "NumericLiteral", + value + }; + const defs = NODE_FIELDS.NumericLiteral; + validate(defs.value, node, "value", value); + return node; + } + function nullLiteral() { + return { + type: "NullLiteral" + }; + } + function booleanLiteral(value) { + const node = { + type: "BooleanLiteral", + value + }; + const defs = NODE_FIELDS.BooleanLiteral; + validate(defs.value, node, "value", value); + return node; + } + function regExpLiteral(pattern, flags = "") { + const node = { + type: "RegExpLiteral", + pattern, + flags + }; + const defs = NODE_FIELDS.RegExpLiteral; + validate(defs.pattern, node, "pattern", pattern); + validate(defs.flags, node, "flags", flags); + return node; + } + function logicalExpression(operator, left, right) { + const node = { + type: "LogicalExpression", + operator, + left, + right + }; + const defs = NODE_FIELDS.LogicalExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function memberExpression(object, property, computed = false, optional = null) { + const node = { + type: "MemberExpression", + object, + property, + computed, + optional + }; + const defs = NODE_FIELDS.MemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.optional, node, "optional", optional); + return node; + } + function newExpression(callee, _arguments) { + const node = { + type: "NewExpression", + callee, + arguments: _arguments + }; + const defs = NODE_FIELDS.NewExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + return node; + } + function program(body, directives = [], sourceType = "script", interpreter = null) { + const node = { + type: "Program", + body, + directives, + sourceType, + interpreter + }; + const defs = NODE_FIELDS.Program; + validate(defs.body, node, "body", body, 1); + validate(defs.directives, node, "directives", directives, 1); + validate(defs.sourceType, node, "sourceType", sourceType); + validate(defs.interpreter, node, "interpreter", interpreter, 1); + return node; + } + function objectExpression(properties) { + const node = { + type: "ObjectExpression", + properties + }; + const defs = NODE_FIELDS.ObjectExpression; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function objectMethod(kind = "method", key, params, body, computed = false, generator = false, async = false) { + const node = { + type: "ObjectMethod", + kind, + key, + params, + body, + computed, + generator, + async + }; + const defs = NODE_FIELDS.ObjectMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function objectProperty(key, value, computed = false, shorthand = false, decorators = null) { + const node = { + type: "ObjectProperty", + key, + value, + computed, + shorthand, + decorators + }; + const defs = NODE_FIELDS.ObjectProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.shorthand, node, "shorthand", shorthand); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function restElement(argument) { + const node = { + type: "RestElement", + argument + }; + const defs = NODE_FIELDS.RestElement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function returnStatement(argument = null) { + const node = { + type: "ReturnStatement", + argument + }; + const defs = NODE_FIELDS.ReturnStatement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function sequenceExpression(expressions) { + const node = { + type: "SequenceExpression", + expressions + }; + const defs = NODE_FIELDS.SequenceExpression; + validate(defs.expressions, node, "expressions", expressions, 1); + return node; + } + function parenthesizedExpression(expression) { + const node = { + type: "ParenthesizedExpression", + expression + }; + const defs = NODE_FIELDS.ParenthesizedExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function switchCase(test = null, consequent) { + const node = { + type: "SwitchCase", + test, + consequent + }; + const defs = NODE_FIELDS.SwitchCase; + validate(defs.test, node, "test", test, 1); + validate(defs.consequent, node, "consequent", consequent, 1); + return node; + } + function switchStatement(discriminant, cases) { + const node = { + type: "SwitchStatement", + discriminant, + cases + }; + const defs = NODE_FIELDS.SwitchStatement; + validate(defs.discriminant, node, "discriminant", discriminant, 1); + validate(defs.cases, node, "cases", cases, 1); + return node; + } + function thisExpression() { + return { + type: "ThisExpression" + }; + } + function throwStatement(argument) { + const node = { + type: "ThrowStatement", + argument + }; + const defs = NODE_FIELDS.ThrowStatement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function tryStatement(block, handler = null, finalizer = null) { + const node = { + type: "TryStatement", + block, + handler, + finalizer + }; + const defs = NODE_FIELDS.TryStatement; + validate(defs.block, node, "block", block, 1); + validate(defs.handler, node, "handler", handler, 1); + validate(defs.finalizer, node, "finalizer", finalizer, 1); + return node; + } + function unaryExpression(operator, argument, prefix = true) { + const node = { + type: "UnaryExpression", + operator, + argument, + prefix + }; + const defs = NODE_FIELDS.UnaryExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.argument, node, "argument", argument, 1); + validate(defs.prefix, node, "prefix", prefix); + return node; + } + function updateExpression(operator, argument, prefix = false) { + const node = { + type: "UpdateExpression", + operator, + argument, + prefix + }; + const defs = NODE_FIELDS.UpdateExpression; + validate(defs.operator, node, "operator", operator); + validate(defs.argument, node, "argument", argument, 1); + validate(defs.prefix, node, "prefix", prefix); + return node; + } + function variableDeclaration(kind, declarations) { + const node = { + type: "VariableDeclaration", + kind, + declarations + }; + const defs = NODE_FIELDS.VariableDeclaration; + validate(defs.kind, node, "kind", kind); + validate(defs.declarations, node, "declarations", declarations, 1); + return node; + } + function variableDeclarator(id, init = null) { + const node = { + type: "VariableDeclarator", + id, + init + }; + const defs = NODE_FIELDS.VariableDeclarator; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function whileStatement(test, body) { + const node = { + type: "WhileStatement", + test, + body + }; + const defs = NODE_FIELDS.WhileStatement; + validate(defs.test, node, "test", test, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function withStatement(object, body) { + const node = { + type: "WithStatement", + object, + body + }; + const defs = NODE_FIELDS.WithStatement; + validate(defs.object, node, "object", object, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function assignmentPattern(left, right) { + const node = { + type: "AssignmentPattern", + left, + right + }; + const defs = NODE_FIELDS.AssignmentPattern; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function arrayPattern(elements) { + const node = { + type: "ArrayPattern", + elements + }; + const defs = NODE_FIELDS.ArrayPattern; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function arrowFunctionExpression(params, body, async = false) { + const node = { + type: "ArrowFunctionExpression", + params, + body, + async, + expression: null + }; + const defs = NODE_FIELDS.ArrowFunctionExpression; + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.async, node, "async", async); + return node; + } + function classBody(body) { + const node = { + type: "ClassBody", + body + }; + const defs = NODE_FIELDS.ClassBody; + validate(defs.body, node, "body", body, 1); + return node; + } + function classExpression(id = null, superClass = null, body, decorators = null) { + const node = { + type: "ClassExpression", + id, + superClass, + body, + decorators + }; + const defs = NODE_FIELDS.ClassExpression; + validate(defs.id, node, "id", id, 1); + validate(defs.superClass, node, "superClass", superClass, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function classDeclaration(id = null, superClass = null, body, decorators = null) { + const node = { + type: "ClassDeclaration", + id, + superClass, + body, + decorators + }; + const defs = NODE_FIELDS.ClassDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.superClass, node, "superClass", superClass, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + return node; + } + function exportAllDeclaration(source) { + const node = { + type: "ExportAllDeclaration", + source + }; + const defs = NODE_FIELDS.ExportAllDeclaration; + validate(defs.source, node, "source", source, 1); + return node; + } + function exportDefaultDeclaration(declaration) { + const node = { + type: "ExportDefaultDeclaration", + declaration + }; + const defs = NODE_FIELDS.ExportDefaultDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + return node; + } + function exportNamedDeclaration(declaration = null, specifiers = [], source = null) { + const node = { + type: "ExportNamedDeclaration", + declaration, + specifiers, + source + }; + const defs = NODE_FIELDS.ExportNamedDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + return node; + } + function exportSpecifier(local, exported) { + const node = { + type: "ExportSpecifier", + local, + exported + }; + const defs = NODE_FIELDS.ExportSpecifier; + validate(defs.local, node, "local", local, 1); + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function forOfStatement(left, right, body, _await = false) { + const node = { + type: "ForOfStatement", + left, + right, + body, + await: _await + }; + const defs = NODE_FIELDS.ForOfStatement; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.await, node, "await", _await); + return node; + } + function importDeclaration(specifiers, source) { + const node = { + type: "ImportDeclaration", + specifiers, + source + }; + const defs = NODE_FIELDS.ImportDeclaration; + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + return node; + } + function importDefaultSpecifier(local) { + const node = { + type: "ImportDefaultSpecifier", + local + }; + const defs = NODE_FIELDS.ImportDefaultSpecifier; + validate(defs.local, node, "local", local, 1); + return node; + } + function importNamespaceSpecifier(local) { + const node = { + type: "ImportNamespaceSpecifier", + local + }; + const defs = NODE_FIELDS.ImportNamespaceSpecifier; + validate(defs.local, node, "local", local, 1); + return node; + } + function importSpecifier(local, imported) { + const node = { + type: "ImportSpecifier", + local, + imported + }; + const defs = NODE_FIELDS.ImportSpecifier; + validate(defs.local, node, "local", local, 1); + validate(defs.imported, node, "imported", imported, 1); + return node; + } + function importExpression(source, options = null) { + const node = { + type: "ImportExpression", + source, + options + }; + const defs = NODE_FIELDS.ImportExpression; + validate(defs.source, node, "source", source, 1); + validate(defs.options, node, "options", options, 1); + return node; + } + function metaProperty(meta, property) { + const node = { + type: "MetaProperty", + meta, + property + }; + const defs = NODE_FIELDS.MetaProperty; + validate(defs.meta, node, "meta", meta, 1); + validate(defs.property, node, "property", property, 1); + return node; + } + function classMethod(kind = "method", key, params, body, computed = false, _static = false, generator = false, async = false) { + const node = { + type: "ClassMethod", + kind, + key, + params, + body, + computed, + static: _static, + generator, + async + }; + const defs = NODE_FIELDS.ClassMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + validate(defs.generator, node, "generator", generator); + validate(defs.async, node, "async", async); + return node; + } + function objectPattern(properties) { + const node = { + type: "ObjectPattern", + properties + }; + const defs = NODE_FIELDS.ObjectPattern; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function spreadElement(argument) { + const node = { + type: "SpreadElement", + argument + }; + const defs = NODE_FIELDS.SpreadElement; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function _super() { + return { + type: "Super" + }; + } + function taggedTemplateExpression(tag, quasi) { + const node = { + type: "TaggedTemplateExpression", + tag, + quasi + }; + const defs = NODE_FIELDS.TaggedTemplateExpression; + validate(defs.tag, node, "tag", tag, 1); + validate(defs.quasi, node, "quasi", quasi, 1); + return node; + } + function templateElement(value, tail = false) { + const node = { + type: "TemplateElement", + value, + tail + }; + const defs = NODE_FIELDS.TemplateElement; + validate(defs.value, node, "value", value); + validate(defs.tail, node, "tail", tail); + return node; + } + function templateLiteral(quasis, expressions) { + const node = { + type: "TemplateLiteral", + quasis, + expressions + }; + const defs = NODE_FIELDS.TemplateLiteral; + validate(defs.quasis, node, "quasis", quasis, 1); + validate(defs.expressions, node, "expressions", expressions, 1); + return node; + } + function yieldExpression(argument = null, delegate = false) { + const node = { + type: "YieldExpression", + argument, + delegate + }; + const defs = NODE_FIELDS.YieldExpression; + validate(defs.argument, node, "argument", argument, 1); + validate(defs.delegate, node, "delegate", delegate); + return node; + } + function awaitExpression(argument) { + const node = { + type: "AwaitExpression", + argument + }; + const defs = NODE_FIELDS.AwaitExpression; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function _import() { + return { + type: "Import" + }; + } + function bigIntLiteral(value) { + const node = { + type: "BigIntLiteral", + value + }; + const defs = NODE_FIELDS.BigIntLiteral; + validate(defs.value, node, "value", value); + return node; + } + function exportNamespaceSpecifier(exported) { + const node = { + type: "ExportNamespaceSpecifier", + exported + }; + const defs = NODE_FIELDS.ExportNamespaceSpecifier; + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function optionalMemberExpression(object, property, computed = false, optional) { + const node = { + type: "OptionalMemberExpression", + object, + property, + computed, + optional + }; + const defs = NODE_FIELDS.OptionalMemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.optional, node, "optional", optional); + return node; + } + function optionalCallExpression(callee, _arguments, optional) { + const node = { + type: "OptionalCallExpression", + callee, + arguments: _arguments, + optional + }; + const defs = NODE_FIELDS.OptionalCallExpression; + validate(defs.callee, node, "callee", callee, 1); + validate(defs.arguments, node, "arguments", _arguments, 1); + validate(defs.optional, node, "optional", optional); + return node; + } + function classProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { + const node = { + type: "ClassProperty", + key, + value, + typeAnnotation, + decorators, + computed, + static: _static + }; + const defs = NODE_FIELDS.ClassProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + return node; + } + function classAccessorProperty(key, value = null, typeAnnotation = null, decorators = null, computed = false, _static = false) { + const node = { + type: "ClassAccessorProperty", + key, + value, + typeAnnotation, + decorators, + computed, + static: _static + }; + const defs = NODE_FIELDS.ClassAccessorProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.computed, node, "computed", computed); + validate(defs.static, node, "static", _static); + return node; + } + function classPrivateProperty(key, value = null, decorators = null, _static = false) { + const node = { + type: "ClassPrivateProperty", + key, + value, + decorators, + static: _static + }; + const defs = NODE_FIELDS.ClassPrivateProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.static, node, "static", _static); + return node; + } + function classPrivateMethod(kind = "method", key, params, body, _static = false) { + const node = { + type: "ClassPrivateMethod", + kind, + key, + params, + body, + static: _static + }; + const defs = NODE_FIELDS.ClassPrivateMethod; + validate(defs.kind, node, "kind", kind); + validate(defs.key, node, "key", key, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.static, node, "static", _static); + return node; + } + function privateName(id) { + const node = { + type: "PrivateName", + id + }; + const defs = NODE_FIELDS.PrivateName; + validate(defs.id, node, "id", id, 1); + return node; + } + function staticBlock(body) { + const node = { + type: "StaticBlock", + body + }; + const defs = NODE_FIELDS.StaticBlock; + validate(defs.body, node, "body", body, 1); + return node; + } + function anyTypeAnnotation() { + return { + type: "AnyTypeAnnotation" + }; + } + function arrayTypeAnnotation(elementType) { + const node = { + type: "ArrayTypeAnnotation", + elementType + }; + const defs = NODE_FIELDS.ArrayTypeAnnotation; + validate(defs.elementType, node, "elementType", elementType, 1); + return node; + } + function booleanTypeAnnotation() { + return { + type: "BooleanTypeAnnotation" + }; + } + function booleanLiteralTypeAnnotation(value) { + const node = { + type: "BooleanLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.BooleanLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function nullLiteralTypeAnnotation() { + return { + type: "NullLiteralTypeAnnotation" + }; + } + function classImplements(id, typeParameters = null) { + const node = { + type: "ClassImplements", + id, + typeParameters + }; + const defs = NODE_FIELDS.ClassImplements; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function declareClass(id, typeParameters = null, _extends = null, body) { + const node = { + type: "DeclareClass", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.DeclareClass; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function declareFunction(id) { + const node = { + type: "DeclareFunction", + id + }; + const defs = NODE_FIELDS.DeclareFunction; + validate(defs.id, node, "id", id, 1); + return node; + } + function declareInterface(id, typeParameters = null, _extends = null, body) { + const node = { + type: "DeclareInterface", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.DeclareInterface; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function declareModule(id, body, kind = null) { + const node = { + type: "DeclareModule", + id, + body, + kind + }; + const defs = NODE_FIELDS.DeclareModule; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + validate(defs.kind, node, "kind", kind); + return node; + } + function declareModuleExports(typeAnnotation) { + const node = { + type: "DeclareModuleExports", + typeAnnotation + }; + const defs = NODE_FIELDS.DeclareModuleExports; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function declareTypeAlias(id, typeParameters = null, right) { + const node = { + type: "DeclareTypeAlias", + id, + typeParameters, + right + }; + const defs = NODE_FIELDS.DeclareTypeAlias; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function declareOpaqueType(id, typeParameters = null, supertype = null) { + const node = { + type: "DeclareOpaqueType", + id, + typeParameters, + supertype + }; + const defs = NODE_FIELDS.DeclareOpaqueType; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.supertype, node, "supertype", supertype, 1); + return node; + } + function declareVariable(id) { + const node = { + type: "DeclareVariable", + id + }; + const defs = NODE_FIELDS.DeclareVariable; + validate(defs.id, node, "id", id, 1); + return node; + } + function declareExportDeclaration(declaration = null, specifiers = null, source = null, attributes = null) { + const node = { + type: "DeclareExportDeclaration", + declaration, + specifiers, + source, + attributes + }; + const defs = NODE_FIELDS.DeclareExportDeclaration; + validate(defs.declaration, node, "declaration", declaration, 1); + validate(defs.specifiers, node, "specifiers", specifiers, 1); + validate(defs.source, node, "source", source, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + return node; + } + function declareExportAllDeclaration(source, attributes = null) { + const node = { + type: "DeclareExportAllDeclaration", + source, + attributes + }; + const defs = NODE_FIELDS.DeclareExportAllDeclaration; + validate(defs.source, node, "source", source, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + return node; + } + function declaredPredicate(value) { + const node = { + type: "DeclaredPredicate", + value + }; + const defs = NODE_FIELDS.DeclaredPredicate; + validate(defs.value, node, "value", value, 1); + return node; + } + function existsTypeAnnotation() { + return { + type: "ExistsTypeAnnotation" + }; + } + function functionTypeAnnotation(typeParameters = null, params, rest = null, returnType) { + const node = { + type: "FunctionTypeAnnotation", + typeParameters, + params, + rest, + returnType + }; + const defs = NODE_FIELDS.FunctionTypeAnnotation; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.rest, node, "rest", rest, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function functionTypeParam(name = null, typeAnnotation) { + const node = { + type: "FunctionTypeParam", + name, + typeAnnotation + }; + const defs = NODE_FIELDS.FunctionTypeParam; + validate(defs.name, node, "name", name, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function genericTypeAnnotation(id, typeParameters = null) { + const node = { + type: "GenericTypeAnnotation", + id, + typeParameters + }; + const defs = NODE_FIELDS.GenericTypeAnnotation; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function inferredPredicate() { + return { + type: "InferredPredicate" + }; + } + function interfaceExtends(id, typeParameters = null) { + const node = { + type: "InterfaceExtends", + id, + typeParameters + }; + const defs = NODE_FIELDS.InterfaceExtends; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function interfaceDeclaration(id, typeParameters = null, _extends = null, body) { + const node = { + type: "InterfaceDeclaration", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.InterfaceDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function interfaceTypeAnnotation(_extends = null, body) { + const node = { + type: "InterfaceTypeAnnotation", + extends: _extends, + body + }; + const defs = NODE_FIELDS.InterfaceTypeAnnotation; + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function intersectionTypeAnnotation(types) { + const node = { + type: "IntersectionTypeAnnotation", + types + }; + const defs = NODE_FIELDS.IntersectionTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function mixedTypeAnnotation() { + return { + type: "MixedTypeAnnotation" + }; + } + function emptyTypeAnnotation() { + return { + type: "EmptyTypeAnnotation" + }; + } + function nullableTypeAnnotation(typeAnnotation) { + const node = { + type: "NullableTypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.NullableTypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function numberLiteralTypeAnnotation(value) { + const node = { + type: "NumberLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.NumberLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function numberTypeAnnotation() { + return { + type: "NumberTypeAnnotation" + }; + } + function objectTypeAnnotation(properties, indexers = [], callProperties = [], internalSlots = [], exact = false) { + const node = { + type: "ObjectTypeAnnotation", + properties, + indexers, + callProperties, + internalSlots, + exact + }; + const defs = NODE_FIELDS.ObjectTypeAnnotation; + validate(defs.properties, node, "properties", properties, 1); + validate(defs.indexers, node, "indexers", indexers, 1); + validate(defs.callProperties, node, "callProperties", callProperties, 1); + validate(defs.internalSlots, node, "internalSlots", internalSlots, 1); + validate(defs.exact, node, "exact", exact); + return node; + } + function objectTypeInternalSlot(id, value, optional, _static, method) { + const node = { + type: "ObjectTypeInternalSlot", + id, + value, + optional, + static: _static, + method + }; + const defs = NODE_FIELDS.ObjectTypeInternalSlot; + validate(defs.id, node, "id", id, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.optional, node, "optional", optional); + validate(defs.static, node, "static", _static); + validate(defs.method, node, "method", method); + return node; + } + function objectTypeCallProperty(value) { + const node = { + type: "ObjectTypeCallProperty", + value, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeCallProperty; + validate(defs.value, node, "value", value, 1); + return node; + } + function objectTypeIndexer(id = null, key, value, variance = null) { + const node = { + type: "ObjectTypeIndexer", + id, + key, + value, + variance, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeIndexer; + validate(defs.id, node, "id", id, 1); + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function objectTypeProperty(key, value, variance = null) { + const node = { + type: "ObjectTypeProperty", + key, + value, + variance, + kind: null, + method: null, + optional: null, + proto: null, + static: null + }; + const defs = NODE_FIELDS.ObjectTypeProperty; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function objectTypeSpreadProperty(argument) { + const node = { + type: "ObjectTypeSpreadProperty", + argument + }; + const defs = NODE_FIELDS.ObjectTypeSpreadProperty; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function opaqueType(id, typeParameters = null, supertype = null, impltype) { + const node = { + type: "OpaqueType", + id, + typeParameters, + supertype, + impltype + }; + const defs = NODE_FIELDS.OpaqueType; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.supertype, node, "supertype", supertype, 1); + validate(defs.impltype, node, "impltype", impltype, 1); + return node; + } + function qualifiedTypeIdentifier(id, qualification) { + const node = { + type: "QualifiedTypeIdentifier", + id, + qualification + }; + const defs = NODE_FIELDS.QualifiedTypeIdentifier; + validate(defs.id, node, "id", id, 1); + validate(defs.qualification, node, "qualification", qualification, 1); + return node; + } + function stringLiteralTypeAnnotation(value) { + const node = { + type: "StringLiteralTypeAnnotation", + value + }; + const defs = NODE_FIELDS.StringLiteralTypeAnnotation; + validate(defs.value, node, "value", value); + return node; + } + function stringTypeAnnotation() { + return { + type: "StringTypeAnnotation" + }; + } + function symbolTypeAnnotation() { + return { + type: "SymbolTypeAnnotation" + }; + } + function thisTypeAnnotation() { + return { + type: "ThisTypeAnnotation" + }; + } + function tupleTypeAnnotation(types) { + const node = { + type: "TupleTypeAnnotation", + types + }; + const defs = NODE_FIELDS.TupleTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function typeofTypeAnnotation(argument) { + const node = { + type: "TypeofTypeAnnotation", + argument + }; + const defs = NODE_FIELDS.TypeofTypeAnnotation; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function typeAlias(id, typeParameters = null, right) { + const node = { + type: "TypeAlias", + id, + typeParameters, + right + }; + const defs = NODE_FIELDS.TypeAlias; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function typeAnnotation(typeAnnotation) { + const node = { + type: "TypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.TypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function typeCastExpression(expression, typeAnnotation) { + const node = { + type: "TypeCastExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TypeCastExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function typeParameter(bound = null, _default = null, variance = null) { + const node = { + type: "TypeParameter", + bound, + default: _default, + variance, + name: null + }; + const defs = NODE_FIELDS.TypeParameter; + validate(defs.bound, node, "bound", bound, 1); + validate(defs.default, node, "default", _default, 1); + validate(defs.variance, node, "variance", variance, 1); + return node; + } + function typeParameterDeclaration(params) { + const node = { + type: "TypeParameterDeclaration", + params + }; + const defs = NODE_FIELDS.TypeParameterDeclaration; + validate(defs.params, node, "params", params, 1); + return node; + } + function typeParameterInstantiation(params) { + const node = { + type: "TypeParameterInstantiation", + params + }; + const defs = NODE_FIELDS.TypeParameterInstantiation; + validate(defs.params, node, "params", params, 1); + return node; + } + function unionTypeAnnotation(types) { + const node = { + type: "UnionTypeAnnotation", + types + }; + const defs = NODE_FIELDS.UnionTypeAnnotation; + validate(defs.types, node, "types", types, 1); + return node; + } + function variance(kind) { + const node = { + type: "Variance", + kind + }; + const defs = NODE_FIELDS.Variance; + validate(defs.kind, node, "kind", kind); + return node; + } + function voidTypeAnnotation() { + return { + type: "VoidTypeAnnotation" + }; + } + function enumDeclaration(id, body) { + const node = { + type: "EnumDeclaration", + id, + body + }; + const defs = NODE_FIELDS.EnumDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function enumBooleanBody(members) { + const node = { + type: "EnumBooleanBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumBooleanBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumNumberBody(members) { + const node = { + type: "EnumNumberBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumNumberBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumStringBody(members) { + const node = { + type: "EnumStringBody", + members, + explicitType: null, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumStringBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumSymbolBody(members) { + const node = { + type: "EnumSymbolBody", + members, + hasUnknownMembers: null + }; + const defs = NODE_FIELDS.EnumSymbolBody; + validate(defs.members, node, "members", members, 1); + return node; + } + function enumBooleanMember(id) { + const node = { + type: "EnumBooleanMember", + id, + init: null + }; + const defs = NODE_FIELDS.EnumBooleanMember; + validate(defs.id, node, "id", id, 1); + return node; + } + function enumNumberMember(id, init) { + const node = { + type: "EnumNumberMember", + id, + init + }; + const defs = NODE_FIELDS.EnumNumberMember; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function enumStringMember(id, init) { + const node = { + type: "EnumStringMember", + id, + init + }; + const defs = NODE_FIELDS.EnumStringMember; + validate(defs.id, node, "id", id, 1); + validate(defs.init, node, "init", init, 1); + return node; + } + function enumDefaultedMember(id) { + const node = { + type: "EnumDefaultedMember", + id + }; + const defs = NODE_FIELDS.EnumDefaultedMember; + validate(defs.id, node, "id", id, 1); + return node; + } + function indexedAccessType(objectType, indexType) { + const node = { + type: "IndexedAccessType", + objectType, + indexType + }; + const defs = NODE_FIELDS.IndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function optionalIndexedAccessType(objectType, indexType) { + const node = { + type: "OptionalIndexedAccessType", + objectType, + indexType, + optional: null + }; + const defs = NODE_FIELDS.OptionalIndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function jsxAttribute(name, value = null) { + const node = { + type: "JSXAttribute", + name, + value + }; + const defs = NODE_FIELDS.JSXAttribute; + validate(defs.name, node, "name", name, 1); + validate(defs.value, node, "value", value, 1); + return node; + } + function jsxClosingElement(name) { + const node = { + type: "JSXClosingElement", + name + }; + const defs = NODE_FIELDS.JSXClosingElement; + validate(defs.name, node, "name", name, 1); + return node; + } + function jsxElement(openingElement, closingElement = null, children, selfClosing = null) { + const node = { + type: "JSXElement", + openingElement, + closingElement, + children, + selfClosing + }; + const defs = NODE_FIELDS.JSXElement; + validate(defs.openingElement, node, "openingElement", openingElement, 1); + validate(defs.closingElement, node, "closingElement", closingElement, 1); + validate(defs.children, node, "children", children, 1); + validate(defs.selfClosing, node, "selfClosing", selfClosing); + return node; + } + function jsxEmptyExpression() { + return { + type: "JSXEmptyExpression" + }; + } + function jsxExpressionContainer(expression) { + const node = { + type: "JSXExpressionContainer", + expression + }; + const defs = NODE_FIELDS.JSXExpressionContainer; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function jsxSpreadChild(expression) { + const node = { + type: "JSXSpreadChild", + expression + }; + const defs = NODE_FIELDS.JSXSpreadChild; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function jsxIdentifier(name) { + const node = { + type: "JSXIdentifier", + name + }; + const defs = NODE_FIELDS.JSXIdentifier; + validate(defs.name, node, "name", name); + return node; + } + function jsxMemberExpression(object, property) { + const node = { + type: "JSXMemberExpression", + object, + property + }; + const defs = NODE_FIELDS.JSXMemberExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.property, node, "property", property, 1); + return node; + } + function jsxNamespacedName(namespace, name) { + const node = { + type: "JSXNamespacedName", + namespace, + name + }; + const defs = NODE_FIELDS.JSXNamespacedName; + validate(defs.namespace, node, "namespace", namespace, 1); + validate(defs.name, node, "name", name, 1); + return node; + } + function jsxOpeningElement(name, attributes, selfClosing = false) { + const node = { + type: "JSXOpeningElement", + name, + attributes, + selfClosing + }; + const defs = NODE_FIELDS.JSXOpeningElement; + validate(defs.name, node, "name", name, 1); + validate(defs.attributes, node, "attributes", attributes, 1); + validate(defs.selfClosing, node, "selfClosing", selfClosing); + return node; + } + function jsxSpreadAttribute(argument) { + const node = { + type: "JSXSpreadAttribute", + argument + }; + const defs = NODE_FIELDS.JSXSpreadAttribute; + validate(defs.argument, node, "argument", argument, 1); + return node; + } + function jsxText(value) { + const node = { + type: "JSXText", + value + }; + const defs = NODE_FIELDS.JSXText; + validate(defs.value, node, "value", value); + return node; + } + function jsxFragment(openingFragment, closingFragment, children) { + const node = { + type: "JSXFragment", + openingFragment, + closingFragment, + children + }; + const defs = NODE_FIELDS.JSXFragment; + validate(defs.openingFragment, node, "openingFragment", openingFragment, 1); + validate(defs.closingFragment, node, "closingFragment", closingFragment, 1); + validate(defs.children, node, "children", children, 1); + return node; + } + function jsxOpeningFragment() { + return { + type: "JSXOpeningFragment" + }; + } + function jsxClosingFragment() { + return { + type: "JSXClosingFragment" + }; + } + function noop() { + return { + type: "Noop" + }; + } + function placeholder(expectedNode, name) { + const node = { + type: "Placeholder", + expectedNode, + name + }; + const defs = NODE_FIELDS.Placeholder; + validate(defs.expectedNode, node, "expectedNode", expectedNode); + validate(defs.name, node, "name", name, 1); + return node; + } + function v8IntrinsicIdentifier(name) { + const node = { + type: "V8IntrinsicIdentifier", + name + }; + const defs = NODE_FIELDS.V8IntrinsicIdentifier; + validate(defs.name, node, "name", name); + return node; + } + function argumentPlaceholder() { + return { + type: "ArgumentPlaceholder" + }; + } + function bindExpression(object, callee) { + const node = { + type: "BindExpression", + object, + callee + }; + const defs = NODE_FIELDS.BindExpression; + validate(defs.object, node, "object", object, 1); + validate(defs.callee, node, "callee", callee, 1); + return node; + } + function importAttribute(key, value) { + const node = { + type: "ImportAttribute", + key, + value + }; + const defs = NODE_FIELDS.ImportAttribute; + validate(defs.key, node, "key", key, 1); + validate(defs.value, node, "value", value, 1); + return node; + } + function decorator(expression) { + const node = { + type: "Decorator", + expression + }; + const defs = NODE_FIELDS.Decorator; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function doExpression(body, async = false) { + const node = { + type: "DoExpression", + body, + async + }; + const defs = NODE_FIELDS.DoExpression; + validate(defs.body, node, "body", body, 1); + validate(defs.async, node, "async", async); + return node; + } + function exportDefaultSpecifier(exported) { + const node = { + type: "ExportDefaultSpecifier", + exported + }; + const defs = NODE_FIELDS.ExportDefaultSpecifier; + validate(defs.exported, node, "exported", exported, 1); + return node; + } + function recordExpression(properties) { + const node = { + type: "RecordExpression", + properties + }; + const defs = NODE_FIELDS.RecordExpression; + validate(defs.properties, node, "properties", properties, 1); + return node; + } + function tupleExpression(elements = []) { + const node = { + type: "TupleExpression", + elements + }; + const defs = NODE_FIELDS.TupleExpression; + validate(defs.elements, node, "elements", elements, 1); + return node; + } + function decimalLiteral(value) { + const node = { + type: "DecimalLiteral", + value + }; + const defs = NODE_FIELDS.DecimalLiteral; + validate(defs.value, node, "value", value); + return node; + } + function moduleExpression(body) { + const node = { + type: "ModuleExpression", + body + }; + const defs = NODE_FIELDS.ModuleExpression; + validate(defs.body, node, "body", body, 1); + return node; + } + function topicReference() { + return { + type: "TopicReference" + }; + } + function pipelineTopicExpression(expression) { + const node = { + type: "PipelineTopicExpression", + expression + }; + const defs = NODE_FIELDS.PipelineTopicExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function pipelineBareFunction(callee) { + const node = { + type: "PipelineBareFunction", + callee + }; + const defs = NODE_FIELDS.PipelineBareFunction; + validate(defs.callee, node, "callee", callee, 1); + return node; + } + function pipelinePrimaryTopicReference() { + return { + type: "PipelinePrimaryTopicReference" + }; + } + function tsParameterProperty(parameter) { + const node = { + type: "TSParameterProperty", + parameter + }; + const defs = NODE_FIELDS.TSParameterProperty; + validate(defs.parameter, node, "parameter", parameter, 1); + return node; + } + function tsDeclareFunction(id = null, typeParameters = null, params, returnType = null) { + const node = { + type: "TSDeclareFunction", + id, + typeParameters, + params, + returnType + }; + const defs = NODE_FIELDS.TSDeclareFunction; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function tsDeclareMethod(decorators = null, key, typeParameters = null, params, returnType = null) { + const node = { + type: "TSDeclareMethod", + decorators, + key, + typeParameters, + params, + returnType + }; + const defs = NODE_FIELDS.TSDeclareMethod; + validate(defs.decorators, node, "decorators", decorators, 1); + validate(defs.key, node, "key", key, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.params, node, "params", params, 1); + validate(defs.returnType, node, "returnType", returnType, 1); + return node; + } + function tsQualifiedName(left, right) { + const node = { + type: "TSQualifiedName", + left, + right + }; + const defs = NODE_FIELDS.TSQualifiedName; + validate(defs.left, node, "left", left, 1); + validate(defs.right, node, "right", right, 1); + return node; + } + function tsCallSignatureDeclaration(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSCallSignatureDeclaration", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSCallSignatureDeclaration; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsConstructSignatureDeclaration(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSConstructSignatureDeclaration", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSConstructSignatureDeclaration; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsPropertySignature(key, typeAnnotation = null) { + const node = { + type: "TSPropertySignature", + key, + typeAnnotation, + kind: null + }; + const defs = NODE_FIELDS.TSPropertySignature; + validate(defs.key, node, "key", key, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsMethodSignature(key, typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSMethodSignature", + key, + typeParameters, + parameters, + typeAnnotation, + kind: null + }; + const defs = NODE_FIELDS.TSMethodSignature; + validate(defs.key, node, "key", key, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsIndexSignature(parameters, typeAnnotation = null) { + const node = { + type: "TSIndexSignature", + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSIndexSignature; + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsAnyKeyword() { + return { + type: "TSAnyKeyword" + }; + } + function tsBooleanKeyword() { + return { + type: "TSBooleanKeyword" + }; + } + function tsBigIntKeyword() { + return { + type: "TSBigIntKeyword" + }; + } + function tsIntrinsicKeyword() { + return { + type: "TSIntrinsicKeyword" + }; + } + function tsNeverKeyword() { + return { + type: "TSNeverKeyword" + }; + } + function tsNullKeyword() { + return { + type: "TSNullKeyword" + }; + } + function tsNumberKeyword() { + return { + type: "TSNumberKeyword" + }; + } + function tsObjectKeyword() { + return { + type: "TSObjectKeyword" + }; + } + function tsStringKeyword() { + return { + type: "TSStringKeyword" + }; + } + function tsSymbolKeyword() { + return { + type: "TSSymbolKeyword" + }; + } + function tsUndefinedKeyword() { + return { + type: "TSUndefinedKeyword" + }; + } + function tsUnknownKeyword() { + return { + type: "TSUnknownKeyword" + }; + } + function tsVoidKeyword() { + return { + type: "TSVoidKeyword" + }; + } + function tsThisType() { + return { + type: "TSThisType" + }; + } + function tsFunctionType(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSFunctionType", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSFunctionType; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsConstructorType(typeParameters = null, parameters, typeAnnotation = null) { + const node = { + type: "TSConstructorType", + typeParameters, + parameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSConstructorType; + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.parameters, node, "parameters", parameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeReference(typeName, typeParameters = null) { + const node = { + type: "TSTypeReference", + typeName, + typeParameters + }; + const defs = NODE_FIELDS.TSTypeReference; + validate(defs.typeName, node, "typeName", typeName, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsTypePredicate(parameterName, typeAnnotation = null, asserts = null) { + const node = { + type: "TSTypePredicate", + parameterName, + typeAnnotation, + asserts + }; + const defs = NODE_FIELDS.TSTypePredicate; + validate(defs.parameterName, node, "parameterName", parameterName, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.asserts, node, "asserts", asserts); + return node; + } + function tsTypeQuery(exprName, typeParameters = null) { + const node = { + type: "TSTypeQuery", + exprName, + typeParameters + }; + const defs = NODE_FIELDS.TSTypeQuery; + validate(defs.exprName, node, "exprName", exprName, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsTypeLiteral(members) { + const node = { + type: "TSTypeLiteral", + members + }; + const defs = NODE_FIELDS.TSTypeLiteral; + validate(defs.members, node, "members", members, 1); + return node; + } + function tsArrayType(elementType) { + const node = { + type: "TSArrayType", + elementType + }; + const defs = NODE_FIELDS.TSArrayType; + validate(defs.elementType, node, "elementType", elementType, 1); + return node; + } + function tsTupleType(elementTypes) { + const node = { + type: "TSTupleType", + elementTypes + }; + const defs = NODE_FIELDS.TSTupleType; + validate(defs.elementTypes, node, "elementTypes", elementTypes, 1); + return node; + } + function tsOptionalType(typeAnnotation) { + const node = { + type: "TSOptionalType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSOptionalType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsRestType(typeAnnotation) { + const node = { + type: "TSRestType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSRestType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsNamedTupleMember(label, elementType, optional = false) { + const node = { + type: "TSNamedTupleMember", + label, + elementType, + optional + }; + const defs = NODE_FIELDS.TSNamedTupleMember; + validate(defs.label, node, "label", label, 1); + validate(defs.elementType, node, "elementType", elementType, 1); + validate(defs.optional, node, "optional", optional); + return node; + } + function tsUnionType(types) { + const node = { + type: "TSUnionType", + types + }; + const defs = NODE_FIELDS.TSUnionType; + validate(defs.types, node, "types", types, 1); + return node; + } + function tsIntersectionType(types) { + const node = { + type: "TSIntersectionType", + types + }; + const defs = NODE_FIELDS.TSIntersectionType; + validate(defs.types, node, "types", types, 1); + return node; + } + function tsConditionalType(checkType, extendsType, trueType, falseType) { + const node = { + type: "TSConditionalType", + checkType, + extendsType, + trueType, + falseType + }; + const defs = NODE_FIELDS.TSConditionalType; + validate(defs.checkType, node, "checkType", checkType, 1); + validate(defs.extendsType, node, "extendsType", extendsType, 1); + validate(defs.trueType, node, "trueType", trueType, 1); + validate(defs.falseType, node, "falseType", falseType, 1); + return node; + } + function tsInferType(typeParameter) { + const node = { + type: "TSInferType", + typeParameter + }; + const defs = NODE_FIELDS.TSInferType; + validate(defs.typeParameter, node, "typeParameter", typeParameter, 1); + return node; + } + function tsParenthesizedType(typeAnnotation) { + const node = { + type: "TSParenthesizedType", + typeAnnotation + }; + const defs = NODE_FIELDS.TSParenthesizedType; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeOperator(typeAnnotation) { + const node = { + type: "TSTypeOperator", + typeAnnotation, + operator: null + }; + const defs = NODE_FIELDS.TSTypeOperator; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsIndexedAccessType(objectType, indexType) { + const node = { + type: "TSIndexedAccessType", + objectType, + indexType + }; + const defs = NODE_FIELDS.TSIndexedAccessType; + validate(defs.objectType, node, "objectType", objectType, 1); + validate(defs.indexType, node, "indexType", indexType, 1); + return node; + } + function tsMappedType(typeParameter, typeAnnotation = null, nameType = null) { + const node = { + type: "TSMappedType", + typeParameter, + typeAnnotation, + nameType + }; + const defs = NODE_FIELDS.TSMappedType; + validate(defs.typeParameter, node, "typeParameter", typeParameter, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.nameType, node, "nameType", nameType, 1); + return node; + } + function tsLiteralType(literal) { + const node = { + type: "TSLiteralType", + literal + }; + const defs = NODE_FIELDS.TSLiteralType; + validate(defs.literal, node, "literal", literal, 1); + return node; + } + function tsExpressionWithTypeArguments(expression, typeParameters = null) { + const node = { + type: "TSExpressionWithTypeArguments", + expression, + typeParameters + }; + const defs = NODE_FIELDS.TSExpressionWithTypeArguments; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsInterfaceDeclaration(id, typeParameters = null, _extends = null, body) { + const node = { + type: "TSInterfaceDeclaration", + id, + typeParameters, + extends: _extends, + body + }; + const defs = NODE_FIELDS.TSInterfaceDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.extends, node, "extends", _extends, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function tsInterfaceBody(body) { + const node = { + type: "TSInterfaceBody", + body + }; + const defs = NODE_FIELDS.TSInterfaceBody; + validate(defs.body, node, "body", body, 1); + return node; + } + function tsTypeAliasDeclaration(id, typeParameters = null, typeAnnotation) { + const node = { + type: "TSTypeAliasDeclaration", + id, + typeParameters, + typeAnnotation + }; + const defs = NODE_FIELDS.TSTypeAliasDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsInstantiationExpression(expression, typeParameters = null) { + const node = { + type: "TSInstantiationExpression", + expression, + typeParameters + }; + const defs = NODE_FIELDS.TSInstantiationExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsAsExpression(expression, typeAnnotation) { + const node = { + type: "TSAsExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TSAsExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsSatisfiesExpression(expression, typeAnnotation) { + const node = { + type: "TSSatisfiesExpression", + expression, + typeAnnotation + }; + const defs = NODE_FIELDS.TSSatisfiesExpression; + validate(defs.expression, node, "expression", expression, 1); + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeAssertion(typeAnnotation, expression) { + const node = { + type: "TSTypeAssertion", + typeAnnotation, + expression + }; + const defs = NODE_FIELDS.TSTypeAssertion; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsEnumDeclaration(id, members) { + const node = { + type: "TSEnumDeclaration", + id, + members + }; + const defs = NODE_FIELDS.TSEnumDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.members, node, "members", members, 1); + return node; + } + function tsEnumMember(id, initializer = null) { + const node = { + type: "TSEnumMember", + id, + initializer + }; + const defs = NODE_FIELDS.TSEnumMember; + validate(defs.id, node, "id", id, 1); + validate(defs.initializer, node, "initializer", initializer, 1); + return node; + } + function tsModuleDeclaration(id, body) { + const node = { + type: "TSModuleDeclaration", + id, + body, + kind: null + }; + const defs = NODE_FIELDS.TSModuleDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.body, node, "body", body, 1); + return node; + } + function tsModuleBlock(body) { + const node = { + type: "TSModuleBlock", + body + }; + const defs = NODE_FIELDS.TSModuleBlock; + validate(defs.body, node, "body", body, 1); + return node; + } + function tsImportType(argument, qualifier = null, typeParameters = null) { + const node = { + type: "TSImportType", + argument, + qualifier, + typeParameters + }; + const defs = NODE_FIELDS.TSImportType; + validate(defs.argument, node, "argument", argument, 1); + validate(defs.qualifier, node, "qualifier", qualifier, 1); + validate(defs.typeParameters, node, "typeParameters", typeParameters, 1); + return node; + } + function tsImportEqualsDeclaration(id, moduleReference) { + const node = { + type: "TSImportEqualsDeclaration", + id, + moduleReference, + isExport: null + }; + const defs = NODE_FIELDS.TSImportEqualsDeclaration; + validate(defs.id, node, "id", id, 1); + validate(defs.moduleReference, node, "moduleReference", moduleReference, 1); + return node; + } + function tsExternalModuleReference(expression) { + const node = { + type: "TSExternalModuleReference", + expression + }; + const defs = NODE_FIELDS.TSExternalModuleReference; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsNonNullExpression(expression) { + const node = { + type: "TSNonNullExpression", + expression + }; + const defs = NODE_FIELDS.TSNonNullExpression; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsExportAssignment(expression) { + const node = { + type: "TSExportAssignment", + expression + }; + const defs = NODE_FIELDS.TSExportAssignment; + validate(defs.expression, node, "expression", expression, 1); + return node; + } + function tsNamespaceExportDeclaration(id) { + const node = { + type: "TSNamespaceExportDeclaration", + id + }; + const defs = NODE_FIELDS.TSNamespaceExportDeclaration; + validate(defs.id, node, "id", id, 1); + return node; + } + function tsTypeAnnotation(typeAnnotation) { + const node = { + type: "TSTypeAnnotation", + typeAnnotation + }; + const defs = NODE_FIELDS.TSTypeAnnotation; + validate(defs.typeAnnotation, node, "typeAnnotation", typeAnnotation, 1); + return node; + } + function tsTypeParameterInstantiation(params) { + const node = { + type: "TSTypeParameterInstantiation", + params + }; + const defs = NODE_FIELDS.TSTypeParameterInstantiation; + validate(defs.params, node, "params", params, 1); + return node; + } + function tsTypeParameterDeclaration(params) { + const node = { + type: "TSTypeParameterDeclaration", + params + }; + const defs = NODE_FIELDS.TSTypeParameterDeclaration; + validate(defs.params, node, "params", params, 1); + return node; + } + function tsTypeParameter(constraint = null, _default = null, name) { + const node = { + type: "TSTypeParameter", + constraint, + default: _default, + name + }; + const defs = NODE_FIELDS.TSTypeParameter; + validate(defs.constraint, node, "constraint", constraint, 1); + validate(defs.default, node, "default", _default, 1); + validate(defs.name, node, "name", name); + return node; + } + function NumberLiteral(value) { + (0, _deprecationWarning.default)("NumberLiteral", "NumericLiteral", "The node type "); + return numericLiteral(value); + } + function RegexLiteral(pattern, flags = "") { + (0, _deprecationWarning.default)("RegexLiteral", "RegExpLiteral", "The node type "); + return regExpLiteral(pattern, flags); + } + function RestProperty(argument) { + (0, _deprecationWarning.default)("RestProperty", "RestElement", "The node type "); + return restElement(argument); + } + function SpreadProperty(argument) { + (0, _deprecationWarning.default)("SpreadProperty", "SpreadElement", "The node type "); + return spreadElement(argument); + } + + + return generated$2; +} + +var hasRequiredCleanJSXElementLiteralChild; + +function requireCleanJSXElementLiteralChild () { + if (hasRequiredCleanJSXElementLiteralChild) return cleanJSXElementLiteralChild; + hasRequiredCleanJSXElementLiteralChild = 1; + + Object.defineProperty(cleanJSXElementLiteralChild, "__esModule", { + value: true + }); + cleanJSXElementLiteralChild.default = cleanJSXElementLiteralChild$1; + var _index = requireGenerated$2(); + var _index2 = requireLib$1(); + function cleanJSXElementLiteralChild$1(child, args) { + const lines = child.value.split(/\r\n|\n|\r/); + let lastNonEmptyLine = 0; + for (let i = 0; i < lines.length; i++) { + if (/[^ \t]/.exec(lines[i])) { + lastNonEmptyLine = i; + } + } + let str = ""; + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + const isFirstLine = i === 0; + const isLastLine = i === lines.length - 1; + const isLastNonEmptyLine = i === lastNonEmptyLine; + let trimmedLine = line.replace(/\t/g, " "); + if (!isFirstLine) { + trimmedLine = trimmedLine.replace(/^ +/, ""); + } + if (!isLastLine) { + trimmedLine = trimmedLine.replace(/ +$/, ""); + } + if (trimmedLine) { + if (!isLastNonEmptyLine) { + trimmedLine += " "; + } + str += trimmedLine; + } + } + if (str) args.push((0, _index2.inherits)((0, _index.stringLiteral)(str), child)); + } + + + return cleanJSXElementLiteralChild; +} + +var hasRequiredBuildChildren; + +function requireBuildChildren () { + if (hasRequiredBuildChildren) return buildChildren; + hasRequiredBuildChildren = 1; + + Object.defineProperty(buildChildren, "__esModule", { + value: true + }); + buildChildren.default = buildChildren$1; + var _index = requireGenerated$3(); + var _cleanJSXElementLiteralChild = requireCleanJSXElementLiteralChild(); + function buildChildren$1(node) { + const elements = []; + for (let i = 0; i < node.children.length; i++) { + let child = node.children[i]; + if ((0, _index.isJSXText)(child)) { + (0, _cleanJSXElementLiteralChild.default)(child, elements); + continue; + } + if ((0, _index.isJSXExpressionContainer)(child)) child = child.expression; + if ((0, _index.isJSXEmptyExpression)(child)) continue; + elements.push(child); + } + return elements; + } + + + return buildChildren; +} + +var assertNode = {}; + +var isNode = {}; + +var hasRequiredIsNode; + +function requireIsNode () { + if (hasRequiredIsNode) return isNode; + hasRequiredIsNode = 1; + + Object.defineProperty(isNode, "__esModule", { + value: true + }); + isNode.default = isNode$1; + var _index = requireDefinitions(); + function isNode$1(node) { + return !!(node && _index.VISITOR_KEYS[node.type]); + } + + + return isNode; +} + +var hasRequiredAssertNode; + +function requireAssertNode () { + if (hasRequiredAssertNode) return assertNode; + hasRequiredAssertNode = 1; + + Object.defineProperty(assertNode, "__esModule", { + value: true + }); + assertNode.default = assertNode$1; + var _isNode = requireIsNode(); + function assertNode$1(node) { + if (!(0, _isNode.default)(node)) { + var _node$type; + const type = (_node$type = node == null ? void 0 : node.type) != null ? _node$type : JSON.stringify(node); + throw new TypeError(`Not a valid node of type "${type}"`); + } + } + + + return assertNode; +} + +var generated$1 = {}; + +var hasRequiredGenerated$1; + +function requireGenerated$1 () { + if (hasRequiredGenerated$1) return generated$1; + hasRequiredGenerated$1 = 1; + + Object.defineProperty(generated$1, "__esModule", { + value: true + }); + generated$1.assertAccessor = assertAccessor; + generated$1.assertAnyTypeAnnotation = assertAnyTypeAnnotation; + generated$1.assertArgumentPlaceholder = assertArgumentPlaceholder; + generated$1.assertArrayExpression = assertArrayExpression; + generated$1.assertArrayPattern = assertArrayPattern; + generated$1.assertArrayTypeAnnotation = assertArrayTypeAnnotation; + generated$1.assertArrowFunctionExpression = assertArrowFunctionExpression; + generated$1.assertAssignmentExpression = assertAssignmentExpression; + generated$1.assertAssignmentPattern = assertAssignmentPattern; + generated$1.assertAwaitExpression = assertAwaitExpression; + generated$1.assertBigIntLiteral = assertBigIntLiteral; + generated$1.assertBinary = assertBinary; + generated$1.assertBinaryExpression = assertBinaryExpression; + generated$1.assertBindExpression = assertBindExpression; + generated$1.assertBlock = assertBlock; + generated$1.assertBlockParent = assertBlockParent; + generated$1.assertBlockStatement = assertBlockStatement; + generated$1.assertBooleanLiteral = assertBooleanLiteral; + generated$1.assertBooleanLiteralTypeAnnotation = assertBooleanLiteralTypeAnnotation; + generated$1.assertBooleanTypeAnnotation = assertBooleanTypeAnnotation; + generated$1.assertBreakStatement = assertBreakStatement; + generated$1.assertCallExpression = assertCallExpression; + generated$1.assertCatchClause = assertCatchClause; + generated$1.assertClass = assertClass; + generated$1.assertClassAccessorProperty = assertClassAccessorProperty; + generated$1.assertClassBody = assertClassBody; + generated$1.assertClassDeclaration = assertClassDeclaration; + generated$1.assertClassExpression = assertClassExpression; + generated$1.assertClassImplements = assertClassImplements; + generated$1.assertClassMethod = assertClassMethod; + generated$1.assertClassPrivateMethod = assertClassPrivateMethod; + generated$1.assertClassPrivateProperty = assertClassPrivateProperty; + generated$1.assertClassProperty = assertClassProperty; + generated$1.assertCompletionStatement = assertCompletionStatement; + generated$1.assertConditional = assertConditional; + generated$1.assertConditionalExpression = assertConditionalExpression; + generated$1.assertContinueStatement = assertContinueStatement; + generated$1.assertDebuggerStatement = assertDebuggerStatement; + generated$1.assertDecimalLiteral = assertDecimalLiteral; + generated$1.assertDeclaration = assertDeclaration; + generated$1.assertDeclareClass = assertDeclareClass; + generated$1.assertDeclareExportAllDeclaration = assertDeclareExportAllDeclaration; + generated$1.assertDeclareExportDeclaration = assertDeclareExportDeclaration; + generated$1.assertDeclareFunction = assertDeclareFunction; + generated$1.assertDeclareInterface = assertDeclareInterface; + generated$1.assertDeclareModule = assertDeclareModule; + generated$1.assertDeclareModuleExports = assertDeclareModuleExports; + generated$1.assertDeclareOpaqueType = assertDeclareOpaqueType; + generated$1.assertDeclareTypeAlias = assertDeclareTypeAlias; + generated$1.assertDeclareVariable = assertDeclareVariable; + generated$1.assertDeclaredPredicate = assertDeclaredPredicate; + generated$1.assertDecorator = assertDecorator; + generated$1.assertDirective = assertDirective; + generated$1.assertDirectiveLiteral = assertDirectiveLiteral; + generated$1.assertDoExpression = assertDoExpression; + generated$1.assertDoWhileStatement = assertDoWhileStatement; + generated$1.assertEmptyStatement = assertEmptyStatement; + generated$1.assertEmptyTypeAnnotation = assertEmptyTypeAnnotation; + generated$1.assertEnumBody = assertEnumBody; + generated$1.assertEnumBooleanBody = assertEnumBooleanBody; + generated$1.assertEnumBooleanMember = assertEnumBooleanMember; + generated$1.assertEnumDeclaration = assertEnumDeclaration; + generated$1.assertEnumDefaultedMember = assertEnumDefaultedMember; + generated$1.assertEnumMember = assertEnumMember; + generated$1.assertEnumNumberBody = assertEnumNumberBody; + generated$1.assertEnumNumberMember = assertEnumNumberMember; + generated$1.assertEnumStringBody = assertEnumStringBody; + generated$1.assertEnumStringMember = assertEnumStringMember; + generated$1.assertEnumSymbolBody = assertEnumSymbolBody; + generated$1.assertExistsTypeAnnotation = assertExistsTypeAnnotation; + generated$1.assertExportAllDeclaration = assertExportAllDeclaration; + generated$1.assertExportDeclaration = assertExportDeclaration; + generated$1.assertExportDefaultDeclaration = assertExportDefaultDeclaration; + generated$1.assertExportDefaultSpecifier = assertExportDefaultSpecifier; + generated$1.assertExportNamedDeclaration = assertExportNamedDeclaration; + generated$1.assertExportNamespaceSpecifier = assertExportNamespaceSpecifier; + generated$1.assertExportSpecifier = assertExportSpecifier; + generated$1.assertExpression = assertExpression; + generated$1.assertExpressionStatement = assertExpressionStatement; + generated$1.assertExpressionWrapper = assertExpressionWrapper; + generated$1.assertFile = assertFile; + generated$1.assertFlow = assertFlow; + generated$1.assertFlowBaseAnnotation = assertFlowBaseAnnotation; + generated$1.assertFlowDeclaration = assertFlowDeclaration; + generated$1.assertFlowPredicate = assertFlowPredicate; + generated$1.assertFlowType = assertFlowType; + generated$1.assertFor = assertFor; + generated$1.assertForInStatement = assertForInStatement; + generated$1.assertForOfStatement = assertForOfStatement; + generated$1.assertForStatement = assertForStatement; + generated$1.assertForXStatement = assertForXStatement; + generated$1.assertFunction = assertFunction; + generated$1.assertFunctionDeclaration = assertFunctionDeclaration; + generated$1.assertFunctionExpression = assertFunctionExpression; + generated$1.assertFunctionParent = assertFunctionParent; + generated$1.assertFunctionTypeAnnotation = assertFunctionTypeAnnotation; + generated$1.assertFunctionTypeParam = assertFunctionTypeParam; + generated$1.assertGenericTypeAnnotation = assertGenericTypeAnnotation; + generated$1.assertIdentifier = assertIdentifier; + generated$1.assertIfStatement = assertIfStatement; + generated$1.assertImmutable = assertImmutable; + generated$1.assertImport = assertImport; + generated$1.assertImportAttribute = assertImportAttribute; + generated$1.assertImportDeclaration = assertImportDeclaration; + generated$1.assertImportDefaultSpecifier = assertImportDefaultSpecifier; + generated$1.assertImportExpression = assertImportExpression; + generated$1.assertImportNamespaceSpecifier = assertImportNamespaceSpecifier; + generated$1.assertImportOrExportDeclaration = assertImportOrExportDeclaration; + generated$1.assertImportSpecifier = assertImportSpecifier; + generated$1.assertIndexedAccessType = assertIndexedAccessType; + generated$1.assertInferredPredicate = assertInferredPredicate; + generated$1.assertInterfaceDeclaration = assertInterfaceDeclaration; + generated$1.assertInterfaceExtends = assertInterfaceExtends; + generated$1.assertInterfaceTypeAnnotation = assertInterfaceTypeAnnotation; + generated$1.assertInterpreterDirective = assertInterpreterDirective; + generated$1.assertIntersectionTypeAnnotation = assertIntersectionTypeAnnotation; + generated$1.assertJSX = assertJSX; + generated$1.assertJSXAttribute = assertJSXAttribute; + generated$1.assertJSXClosingElement = assertJSXClosingElement; + generated$1.assertJSXClosingFragment = assertJSXClosingFragment; + generated$1.assertJSXElement = assertJSXElement; + generated$1.assertJSXEmptyExpression = assertJSXEmptyExpression; + generated$1.assertJSXExpressionContainer = assertJSXExpressionContainer; + generated$1.assertJSXFragment = assertJSXFragment; + generated$1.assertJSXIdentifier = assertJSXIdentifier; + generated$1.assertJSXMemberExpression = assertJSXMemberExpression; + generated$1.assertJSXNamespacedName = assertJSXNamespacedName; + generated$1.assertJSXOpeningElement = assertJSXOpeningElement; + generated$1.assertJSXOpeningFragment = assertJSXOpeningFragment; + generated$1.assertJSXSpreadAttribute = assertJSXSpreadAttribute; + generated$1.assertJSXSpreadChild = assertJSXSpreadChild; + generated$1.assertJSXText = assertJSXText; + generated$1.assertLVal = assertLVal; + generated$1.assertLabeledStatement = assertLabeledStatement; + generated$1.assertLiteral = assertLiteral; + generated$1.assertLogicalExpression = assertLogicalExpression; + generated$1.assertLoop = assertLoop; + generated$1.assertMemberExpression = assertMemberExpression; + generated$1.assertMetaProperty = assertMetaProperty; + generated$1.assertMethod = assertMethod; + generated$1.assertMiscellaneous = assertMiscellaneous; + generated$1.assertMixedTypeAnnotation = assertMixedTypeAnnotation; + generated$1.assertModuleDeclaration = assertModuleDeclaration; + generated$1.assertModuleExpression = assertModuleExpression; + generated$1.assertModuleSpecifier = assertModuleSpecifier; + generated$1.assertNewExpression = assertNewExpression; + generated$1.assertNoop = assertNoop; + generated$1.assertNullLiteral = assertNullLiteral; + generated$1.assertNullLiteralTypeAnnotation = assertNullLiteralTypeAnnotation; + generated$1.assertNullableTypeAnnotation = assertNullableTypeAnnotation; + generated$1.assertNumberLiteral = assertNumberLiteral; + generated$1.assertNumberLiteralTypeAnnotation = assertNumberLiteralTypeAnnotation; + generated$1.assertNumberTypeAnnotation = assertNumberTypeAnnotation; + generated$1.assertNumericLiteral = assertNumericLiteral; + generated$1.assertObjectExpression = assertObjectExpression; + generated$1.assertObjectMember = assertObjectMember; + generated$1.assertObjectMethod = assertObjectMethod; + generated$1.assertObjectPattern = assertObjectPattern; + generated$1.assertObjectProperty = assertObjectProperty; + generated$1.assertObjectTypeAnnotation = assertObjectTypeAnnotation; + generated$1.assertObjectTypeCallProperty = assertObjectTypeCallProperty; + generated$1.assertObjectTypeIndexer = assertObjectTypeIndexer; + generated$1.assertObjectTypeInternalSlot = assertObjectTypeInternalSlot; + generated$1.assertObjectTypeProperty = assertObjectTypeProperty; + generated$1.assertObjectTypeSpreadProperty = assertObjectTypeSpreadProperty; + generated$1.assertOpaqueType = assertOpaqueType; + generated$1.assertOptionalCallExpression = assertOptionalCallExpression; + generated$1.assertOptionalIndexedAccessType = assertOptionalIndexedAccessType; + generated$1.assertOptionalMemberExpression = assertOptionalMemberExpression; + generated$1.assertParenthesizedExpression = assertParenthesizedExpression; + generated$1.assertPattern = assertPattern; + generated$1.assertPatternLike = assertPatternLike; + generated$1.assertPipelineBareFunction = assertPipelineBareFunction; + generated$1.assertPipelinePrimaryTopicReference = assertPipelinePrimaryTopicReference; + generated$1.assertPipelineTopicExpression = assertPipelineTopicExpression; + generated$1.assertPlaceholder = assertPlaceholder; + generated$1.assertPrivate = assertPrivate; + generated$1.assertPrivateName = assertPrivateName; + generated$1.assertProgram = assertProgram; + generated$1.assertProperty = assertProperty; + generated$1.assertPureish = assertPureish; + generated$1.assertQualifiedTypeIdentifier = assertQualifiedTypeIdentifier; + generated$1.assertRecordExpression = assertRecordExpression; + generated$1.assertRegExpLiteral = assertRegExpLiteral; + generated$1.assertRegexLiteral = assertRegexLiteral; + generated$1.assertRestElement = assertRestElement; + generated$1.assertRestProperty = assertRestProperty; + generated$1.assertReturnStatement = assertReturnStatement; + generated$1.assertScopable = assertScopable; + generated$1.assertSequenceExpression = assertSequenceExpression; + generated$1.assertSpreadElement = assertSpreadElement; + generated$1.assertSpreadProperty = assertSpreadProperty; + generated$1.assertStandardized = assertStandardized; + generated$1.assertStatement = assertStatement; + generated$1.assertStaticBlock = assertStaticBlock; + generated$1.assertStringLiteral = assertStringLiteral; + generated$1.assertStringLiteralTypeAnnotation = assertStringLiteralTypeAnnotation; + generated$1.assertStringTypeAnnotation = assertStringTypeAnnotation; + generated$1.assertSuper = assertSuper; + generated$1.assertSwitchCase = assertSwitchCase; + generated$1.assertSwitchStatement = assertSwitchStatement; + generated$1.assertSymbolTypeAnnotation = assertSymbolTypeAnnotation; + generated$1.assertTSAnyKeyword = assertTSAnyKeyword; + generated$1.assertTSArrayType = assertTSArrayType; + generated$1.assertTSAsExpression = assertTSAsExpression; + generated$1.assertTSBaseType = assertTSBaseType; + generated$1.assertTSBigIntKeyword = assertTSBigIntKeyword; + generated$1.assertTSBooleanKeyword = assertTSBooleanKeyword; + generated$1.assertTSCallSignatureDeclaration = assertTSCallSignatureDeclaration; + generated$1.assertTSConditionalType = assertTSConditionalType; + generated$1.assertTSConstructSignatureDeclaration = assertTSConstructSignatureDeclaration; + generated$1.assertTSConstructorType = assertTSConstructorType; + generated$1.assertTSDeclareFunction = assertTSDeclareFunction; + generated$1.assertTSDeclareMethod = assertTSDeclareMethod; + generated$1.assertTSEntityName = assertTSEntityName; + generated$1.assertTSEnumDeclaration = assertTSEnumDeclaration; + generated$1.assertTSEnumMember = assertTSEnumMember; + generated$1.assertTSExportAssignment = assertTSExportAssignment; + generated$1.assertTSExpressionWithTypeArguments = assertTSExpressionWithTypeArguments; + generated$1.assertTSExternalModuleReference = assertTSExternalModuleReference; + generated$1.assertTSFunctionType = assertTSFunctionType; + generated$1.assertTSImportEqualsDeclaration = assertTSImportEqualsDeclaration; + generated$1.assertTSImportType = assertTSImportType; + generated$1.assertTSIndexSignature = assertTSIndexSignature; + generated$1.assertTSIndexedAccessType = assertTSIndexedAccessType; + generated$1.assertTSInferType = assertTSInferType; + generated$1.assertTSInstantiationExpression = assertTSInstantiationExpression; + generated$1.assertTSInterfaceBody = assertTSInterfaceBody; + generated$1.assertTSInterfaceDeclaration = assertTSInterfaceDeclaration; + generated$1.assertTSIntersectionType = assertTSIntersectionType; + generated$1.assertTSIntrinsicKeyword = assertTSIntrinsicKeyword; + generated$1.assertTSLiteralType = assertTSLiteralType; + generated$1.assertTSMappedType = assertTSMappedType; + generated$1.assertTSMethodSignature = assertTSMethodSignature; + generated$1.assertTSModuleBlock = assertTSModuleBlock; + generated$1.assertTSModuleDeclaration = assertTSModuleDeclaration; + generated$1.assertTSNamedTupleMember = assertTSNamedTupleMember; + generated$1.assertTSNamespaceExportDeclaration = assertTSNamespaceExportDeclaration; + generated$1.assertTSNeverKeyword = assertTSNeverKeyword; + generated$1.assertTSNonNullExpression = assertTSNonNullExpression; + generated$1.assertTSNullKeyword = assertTSNullKeyword; + generated$1.assertTSNumberKeyword = assertTSNumberKeyword; + generated$1.assertTSObjectKeyword = assertTSObjectKeyword; + generated$1.assertTSOptionalType = assertTSOptionalType; + generated$1.assertTSParameterProperty = assertTSParameterProperty; + generated$1.assertTSParenthesizedType = assertTSParenthesizedType; + generated$1.assertTSPropertySignature = assertTSPropertySignature; + generated$1.assertTSQualifiedName = assertTSQualifiedName; + generated$1.assertTSRestType = assertTSRestType; + generated$1.assertTSSatisfiesExpression = assertTSSatisfiesExpression; + generated$1.assertTSStringKeyword = assertTSStringKeyword; + generated$1.assertTSSymbolKeyword = assertTSSymbolKeyword; + generated$1.assertTSThisType = assertTSThisType; + generated$1.assertTSTupleType = assertTSTupleType; + generated$1.assertTSType = assertTSType; + generated$1.assertTSTypeAliasDeclaration = assertTSTypeAliasDeclaration; + generated$1.assertTSTypeAnnotation = assertTSTypeAnnotation; + generated$1.assertTSTypeAssertion = assertTSTypeAssertion; + generated$1.assertTSTypeElement = assertTSTypeElement; + generated$1.assertTSTypeLiteral = assertTSTypeLiteral; + generated$1.assertTSTypeOperator = assertTSTypeOperator; + generated$1.assertTSTypeParameter = assertTSTypeParameter; + generated$1.assertTSTypeParameterDeclaration = assertTSTypeParameterDeclaration; + generated$1.assertTSTypeParameterInstantiation = assertTSTypeParameterInstantiation; + generated$1.assertTSTypePredicate = assertTSTypePredicate; + generated$1.assertTSTypeQuery = assertTSTypeQuery; + generated$1.assertTSTypeReference = assertTSTypeReference; + generated$1.assertTSUndefinedKeyword = assertTSUndefinedKeyword; + generated$1.assertTSUnionType = assertTSUnionType; + generated$1.assertTSUnknownKeyword = assertTSUnknownKeyword; + generated$1.assertTSVoidKeyword = assertTSVoidKeyword; + generated$1.assertTaggedTemplateExpression = assertTaggedTemplateExpression; + generated$1.assertTemplateElement = assertTemplateElement; + generated$1.assertTemplateLiteral = assertTemplateLiteral; + generated$1.assertTerminatorless = assertTerminatorless; + generated$1.assertThisExpression = assertThisExpression; + generated$1.assertThisTypeAnnotation = assertThisTypeAnnotation; + generated$1.assertThrowStatement = assertThrowStatement; + generated$1.assertTopicReference = assertTopicReference; + generated$1.assertTryStatement = assertTryStatement; + generated$1.assertTupleExpression = assertTupleExpression; + generated$1.assertTupleTypeAnnotation = assertTupleTypeAnnotation; + generated$1.assertTypeAlias = assertTypeAlias; + generated$1.assertTypeAnnotation = assertTypeAnnotation; + generated$1.assertTypeCastExpression = assertTypeCastExpression; + generated$1.assertTypeParameter = assertTypeParameter; + generated$1.assertTypeParameterDeclaration = assertTypeParameterDeclaration; + generated$1.assertTypeParameterInstantiation = assertTypeParameterInstantiation; + generated$1.assertTypeScript = assertTypeScript; + generated$1.assertTypeofTypeAnnotation = assertTypeofTypeAnnotation; + generated$1.assertUnaryExpression = assertUnaryExpression; + generated$1.assertUnaryLike = assertUnaryLike; + generated$1.assertUnionTypeAnnotation = assertUnionTypeAnnotation; + generated$1.assertUpdateExpression = assertUpdateExpression; + generated$1.assertUserWhitespacable = assertUserWhitespacable; + generated$1.assertV8IntrinsicIdentifier = assertV8IntrinsicIdentifier; + generated$1.assertVariableDeclaration = assertVariableDeclaration; + generated$1.assertVariableDeclarator = assertVariableDeclarator; + generated$1.assertVariance = assertVariance; + generated$1.assertVoidTypeAnnotation = assertVoidTypeAnnotation; + generated$1.assertWhile = assertWhile; + generated$1.assertWhileStatement = assertWhileStatement; + generated$1.assertWithStatement = assertWithStatement; + generated$1.assertYieldExpression = assertYieldExpression; + var _is = requireIs(); + var _deprecationWarning = requireDeprecationWarning(); + function assert(type, node, opts) { + if (!(0, _is.default)(type, node, opts)) { + throw new Error(`Expected type "${type}" with option ${JSON.stringify(opts)}, ` + `but instead got "${node.type}".`); + } + } + function assertArrayExpression(node, opts) { + assert("ArrayExpression", node, opts); + } + function assertAssignmentExpression(node, opts) { + assert("AssignmentExpression", node, opts); + } + function assertBinaryExpression(node, opts) { + assert("BinaryExpression", node, opts); + } + function assertInterpreterDirective(node, opts) { + assert("InterpreterDirective", node, opts); + } + function assertDirective(node, opts) { + assert("Directive", node, opts); + } + function assertDirectiveLiteral(node, opts) { + assert("DirectiveLiteral", node, opts); + } + function assertBlockStatement(node, opts) { + assert("BlockStatement", node, opts); + } + function assertBreakStatement(node, opts) { + assert("BreakStatement", node, opts); + } + function assertCallExpression(node, opts) { + assert("CallExpression", node, opts); + } + function assertCatchClause(node, opts) { + assert("CatchClause", node, opts); + } + function assertConditionalExpression(node, opts) { + assert("ConditionalExpression", node, opts); + } + function assertContinueStatement(node, opts) { + assert("ContinueStatement", node, opts); + } + function assertDebuggerStatement(node, opts) { + assert("DebuggerStatement", node, opts); + } + function assertDoWhileStatement(node, opts) { + assert("DoWhileStatement", node, opts); + } + function assertEmptyStatement(node, opts) { + assert("EmptyStatement", node, opts); + } + function assertExpressionStatement(node, opts) { + assert("ExpressionStatement", node, opts); + } + function assertFile(node, opts) { + assert("File", node, opts); + } + function assertForInStatement(node, opts) { + assert("ForInStatement", node, opts); + } + function assertForStatement(node, opts) { + assert("ForStatement", node, opts); + } + function assertFunctionDeclaration(node, opts) { + assert("FunctionDeclaration", node, opts); + } + function assertFunctionExpression(node, opts) { + assert("FunctionExpression", node, opts); + } + function assertIdentifier(node, opts) { + assert("Identifier", node, opts); + } + function assertIfStatement(node, opts) { + assert("IfStatement", node, opts); + } + function assertLabeledStatement(node, opts) { + assert("LabeledStatement", node, opts); + } + function assertStringLiteral(node, opts) { + assert("StringLiteral", node, opts); + } + function assertNumericLiteral(node, opts) { + assert("NumericLiteral", node, opts); + } + function assertNullLiteral(node, opts) { + assert("NullLiteral", node, opts); + } + function assertBooleanLiteral(node, opts) { + assert("BooleanLiteral", node, opts); + } + function assertRegExpLiteral(node, opts) { + assert("RegExpLiteral", node, opts); + } + function assertLogicalExpression(node, opts) { + assert("LogicalExpression", node, opts); + } + function assertMemberExpression(node, opts) { + assert("MemberExpression", node, opts); + } + function assertNewExpression(node, opts) { + assert("NewExpression", node, opts); + } + function assertProgram(node, opts) { + assert("Program", node, opts); + } + function assertObjectExpression(node, opts) { + assert("ObjectExpression", node, opts); + } + function assertObjectMethod(node, opts) { + assert("ObjectMethod", node, opts); + } + function assertObjectProperty(node, opts) { + assert("ObjectProperty", node, opts); + } + function assertRestElement(node, opts) { + assert("RestElement", node, opts); + } + function assertReturnStatement(node, opts) { + assert("ReturnStatement", node, opts); + } + function assertSequenceExpression(node, opts) { + assert("SequenceExpression", node, opts); + } + function assertParenthesizedExpression(node, opts) { + assert("ParenthesizedExpression", node, opts); + } + function assertSwitchCase(node, opts) { + assert("SwitchCase", node, opts); + } + function assertSwitchStatement(node, opts) { + assert("SwitchStatement", node, opts); + } + function assertThisExpression(node, opts) { + assert("ThisExpression", node, opts); + } + function assertThrowStatement(node, opts) { + assert("ThrowStatement", node, opts); + } + function assertTryStatement(node, opts) { + assert("TryStatement", node, opts); + } + function assertUnaryExpression(node, opts) { + assert("UnaryExpression", node, opts); + } + function assertUpdateExpression(node, opts) { + assert("UpdateExpression", node, opts); + } + function assertVariableDeclaration(node, opts) { + assert("VariableDeclaration", node, opts); + } + function assertVariableDeclarator(node, opts) { + assert("VariableDeclarator", node, opts); + } + function assertWhileStatement(node, opts) { + assert("WhileStatement", node, opts); + } + function assertWithStatement(node, opts) { + assert("WithStatement", node, opts); + } + function assertAssignmentPattern(node, opts) { + assert("AssignmentPattern", node, opts); + } + function assertArrayPattern(node, opts) { + assert("ArrayPattern", node, opts); + } + function assertArrowFunctionExpression(node, opts) { + assert("ArrowFunctionExpression", node, opts); + } + function assertClassBody(node, opts) { + assert("ClassBody", node, opts); + } + function assertClassExpression(node, opts) { + assert("ClassExpression", node, opts); + } + function assertClassDeclaration(node, opts) { + assert("ClassDeclaration", node, opts); + } + function assertExportAllDeclaration(node, opts) { + assert("ExportAllDeclaration", node, opts); + } + function assertExportDefaultDeclaration(node, opts) { + assert("ExportDefaultDeclaration", node, opts); + } + function assertExportNamedDeclaration(node, opts) { + assert("ExportNamedDeclaration", node, opts); + } + function assertExportSpecifier(node, opts) { + assert("ExportSpecifier", node, opts); + } + function assertForOfStatement(node, opts) { + assert("ForOfStatement", node, opts); + } + function assertImportDeclaration(node, opts) { + assert("ImportDeclaration", node, opts); + } + function assertImportDefaultSpecifier(node, opts) { + assert("ImportDefaultSpecifier", node, opts); + } + function assertImportNamespaceSpecifier(node, opts) { + assert("ImportNamespaceSpecifier", node, opts); + } + function assertImportSpecifier(node, opts) { + assert("ImportSpecifier", node, opts); + } + function assertImportExpression(node, opts) { + assert("ImportExpression", node, opts); + } + function assertMetaProperty(node, opts) { + assert("MetaProperty", node, opts); + } + function assertClassMethod(node, opts) { + assert("ClassMethod", node, opts); + } + function assertObjectPattern(node, opts) { + assert("ObjectPattern", node, opts); + } + function assertSpreadElement(node, opts) { + assert("SpreadElement", node, opts); + } + function assertSuper(node, opts) { + assert("Super", node, opts); + } + function assertTaggedTemplateExpression(node, opts) { + assert("TaggedTemplateExpression", node, opts); + } + function assertTemplateElement(node, opts) { + assert("TemplateElement", node, opts); + } + function assertTemplateLiteral(node, opts) { + assert("TemplateLiteral", node, opts); + } + function assertYieldExpression(node, opts) { + assert("YieldExpression", node, opts); + } + function assertAwaitExpression(node, opts) { + assert("AwaitExpression", node, opts); + } + function assertImport(node, opts) { + assert("Import", node, opts); + } + function assertBigIntLiteral(node, opts) { + assert("BigIntLiteral", node, opts); + } + function assertExportNamespaceSpecifier(node, opts) { + assert("ExportNamespaceSpecifier", node, opts); + } + function assertOptionalMemberExpression(node, opts) { + assert("OptionalMemberExpression", node, opts); + } + function assertOptionalCallExpression(node, opts) { + assert("OptionalCallExpression", node, opts); + } + function assertClassProperty(node, opts) { + assert("ClassProperty", node, opts); + } + function assertClassAccessorProperty(node, opts) { + assert("ClassAccessorProperty", node, opts); + } + function assertClassPrivateProperty(node, opts) { + assert("ClassPrivateProperty", node, opts); + } + function assertClassPrivateMethod(node, opts) { + assert("ClassPrivateMethod", node, opts); + } + function assertPrivateName(node, opts) { + assert("PrivateName", node, opts); + } + function assertStaticBlock(node, opts) { + assert("StaticBlock", node, opts); + } + function assertAnyTypeAnnotation(node, opts) { + assert("AnyTypeAnnotation", node, opts); + } + function assertArrayTypeAnnotation(node, opts) { + assert("ArrayTypeAnnotation", node, opts); + } + function assertBooleanTypeAnnotation(node, opts) { + assert("BooleanTypeAnnotation", node, opts); + } + function assertBooleanLiteralTypeAnnotation(node, opts) { + assert("BooleanLiteralTypeAnnotation", node, opts); + } + function assertNullLiteralTypeAnnotation(node, opts) { + assert("NullLiteralTypeAnnotation", node, opts); + } + function assertClassImplements(node, opts) { + assert("ClassImplements", node, opts); + } + function assertDeclareClass(node, opts) { + assert("DeclareClass", node, opts); + } + function assertDeclareFunction(node, opts) { + assert("DeclareFunction", node, opts); + } + function assertDeclareInterface(node, opts) { + assert("DeclareInterface", node, opts); + } + function assertDeclareModule(node, opts) { + assert("DeclareModule", node, opts); + } + function assertDeclareModuleExports(node, opts) { + assert("DeclareModuleExports", node, opts); + } + function assertDeclareTypeAlias(node, opts) { + assert("DeclareTypeAlias", node, opts); + } + function assertDeclareOpaqueType(node, opts) { + assert("DeclareOpaqueType", node, opts); + } + function assertDeclareVariable(node, opts) { + assert("DeclareVariable", node, opts); + } + function assertDeclareExportDeclaration(node, opts) { + assert("DeclareExportDeclaration", node, opts); + } + function assertDeclareExportAllDeclaration(node, opts) { + assert("DeclareExportAllDeclaration", node, opts); + } + function assertDeclaredPredicate(node, opts) { + assert("DeclaredPredicate", node, opts); + } + function assertExistsTypeAnnotation(node, opts) { + assert("ExistsTypeAnnotation", node, opts); + } + function assertFunctionTypeAnnotation(node, opts) { + assert("FunctionTypeAnnotation", node, opts); + } + function assertFunctionTypeParam(node, opts) { + assert("FunctionTypeParam", node, opts); + } + function assertGenericTypeAnnotation(node, opts) { + assert("GenericTypeAnnotation", node, opts); + } + function assertInferredPredicate(node, opts) { + assert("InferredPredicate", node, opts); + } + function assertInterfaceExtends(node, opts) { + assert("InterfaceExtends", node, opts); + } + function assertInterfaceDeclaration(node, opts) { + assert("InterfaceDeclaration", node, opts); + } + function assertInterfaceTypeAnnotation(node, opts) { + assert("InterfaceTypeAnnotation", node, opts); + } + function assertIntersectionTypeAnnotation(node, opts) { + assert("IntersectionTypeAnnotation", node, opts); + } + function assertMixedTypeAnnotation(node, opts) { + assert("MixedTypeAnnotation", node, opts); + } + function assertEmptyTypeAnnotation(node, opts) { + assert("EmptyTypeAnnotation", node, opts); + } + function assertNullableTypeAnnotation(node, opts) { + assert("NullableTypeAnnotation", node, opts); + } + function assertNumberLiteralTypeAnnotation(node, opts) { + assert("NumberLiteralTypeAnnotation", node, opts); + } + function assertNumberTypeAnnotation(node, opts) { + assert("NumberTypeAnnotation", node, opts); + } + function assertObjectTypeAnnotation(node, opts) { + assert("ObjectTypeAnnotation", node, opts); + } + function assertObjectTypeInternalSlot(node, opts) { + assert("ObjectTypeInternalSlot", node, opts); + } + function assertObjectTypeCallProperty(node, opts) { + assert("ObjectTypeCallProperty", node, opts); + } + function assertObjectTypeIndexer(node, opts) { + assert("ObjectTypeIndexer", node, opts); + } + function assertObjectTypeProperty(node, opts) { + assert("ObjectTypeProperty", node, opts); + } + function assertObjectTypeSpreadProperty(node, opts) { + assert("ObjectTypeSpreadProperty", node, opts); + } + function assertOpaqueType(node, opts) { + assert("OpaqueType", node, opts); + } + function assertQualifiedTypeIdentifier(node, opts) { + assert("QualifiedTypeIdentifier", node, opts); + } + function assertStringLiteralTypeAnnotation(node, opts) { + assert("StringLiteralTypeAnnotation", node, opts); + } + function assertStringTypeAnnotation(node, opts) { + assert("StringTypeAnnotation", node, opts); + } + function assertSymbolTypeAnnotation(node, opts) { + assert("SymbolTypeAnnotation", node, opts); + } + function assertThisTypeAnnotation(node, opts) { + assert("ThisTypeAnnotation", node, opts); + } + function assertTupleTypeAnnotation(node, opts) { + assert("TupleTypeAnnotation", node, opts); + } + function assertTypeofTypeAnnotation(node, opts) { + assert("TypeofTypeAnnotation", node, opts); + } + function assertTypeAlias(node, opts) { + assert("TypeAlias", node, opts); + } + function assertTypeAnnotation(node, opts) { + assert("TypeAnnotation", node, opts); + } + function assertTypeCastExpression(node, opts) { + assert("TypeCastExpression", node, opts); + } + function assertTypeParameter(node, opts) { + assert("TypeParameter", node, opts); + } + function assertTypeParameterDeclaration(node, opts) { + assert("TypeParameterDeclaration", node, opts); + } + function assertTypeParameterInstantiation(node, opts) { + assert("TypeParameterInstantiation", node, opts); + } + function assertUnionTypeAnnotation(node, opts) { + assert("UnionTypeAnnotation", node, opts); + } + function assertVariance(node, opts) { + assert("Variance", node, opts); + } + function assertVoidTypeAnnotation(node, opts) { + assert("VoidTypeAnnotation", node, opts); + } + function assertEnumDeclaration(node, opts) { + assert("EnumDeclaration", node, opts); + } + function assertEnumBooleanBody(node, opts) { + assert("EnumBooleanBody", node, opts); + } + function assertEnumNumberBody(node, opts) { + assert("EnumNumberBody", node, opts); + } + function assertEnumStringBody(node, opts) { + assert("EnumStringBody", node, opts); + } + function assertEnumSymbolBody(node, opts) { + assert("EnumSymbolBody", node, opts); + } + function assertEnumBooleanMember(node, opts) { + assert("EnumBooleanMember", node, opts); + } + function assertEnumNumberMember(node, opts) { + assert("EnumNumberMember", node, opts); + } + function assertEnumStringMember(node, opts) { + assert("EnumStringMember", node, opts); + } + function assertEnumDefaultedMember(node, opts) { + assert("EnumDefaultedMember", node, opts); + } + function assertIndexedAccessType(node, opts) { + assert("IndexedAccessType", node, opts); + } + function assertOptionalIndexedAccessType(node, opts) { + assert("OptionalIndexedAccessType", node, opts); + } + function assertJSXAttribute(node, opts) { + assert("JSXAttribute", node, opts); + } + function assertJSXClosingElement(node, opts) { + assert("JSXClosingElement", node, opts); + } + function assertJSXElement(node, opts) { + assert("JSXElement", node, opts); + } + function assertJSXEmptyExpression(node, opts) { + assert("JSXEmptyExpression", node, opts); + } + function assertJSXExpressionContainer(node, opts) { + assert("JSXExpressionContainer", node, opts); + } + function assertJSXSpreadChild(node, opts) { + assert("JSXSpreadChild", node, opts); + } + function assertJSXIdentifier(node, opts) { + assert("JSXIdentifier", node, opts); + } + function assertJSXMemberExpression(node, opts) { + assert("JSXMemberExpression", node, opts); + } + function assertJSXNamespacedName(node, opts) { + assert("JSXNamespacedName", node, opts); + } + function assertJSXOpeningElement(node, opts) { + assert("JSXOpeningElement", node, opts); + } + function assertJSXSpreadAttribute(node, opts) { + assert("JSXSpreadAttribute", node, opts); + } + function assertJSXText(node, opts) { + assert("JSXText", node, opts); + } + function assertJSXFragment(node, opts) { + assert("JSXFragment", node, opts); + } + function assertJSXOpeningFragment(node, opts) { + assert("JSXOpeningFragment", node, opts); + } + function assertJSXClosingFragment(node, opts) { + assert("JSXClosingFragment", node, opts); + } + function assertNoop(node, opts) { + assert("Noop", node, opts); + } + function assertPlaceholder(node, opts) { + assert("Placeholder", node, opts); + } + function assertV8IntrinsicIdentifier(node, opts) { + assert("V8IntrinsicIdentifier", node, opts); + } + function assertArgumentPlaceholder(node, opts) { + assert("ArgumentPlaceholder", node, opts); + } + function assertBindExpression(node, opts) { + assert("BindExpression", node, opts); + } + function assertImportAttribute(node, opts) { + assert("ImportAttribute", node, opts); + } + function assertDecorator(node, opts) { + assert("Decorator", node, opts); + } + function assertDoExpression(node, opts) { + assert("DoExpression", node, opts); + } + function assertExportDefaultSpecifier(node, opts) { + assert("ExportDefaultSpecifier", node, opts); + } + function assertRecordExpression(node, opts) { + assert("RecordExpression", node, opts); + } + function assertTupleExpression(node, opts) { + assert("TupleExpression", node, opts); + } + function assertDecimalLiteral(node, opts) { + assert("DecimalLiteral", node, opts); + } + function assertModuleExpression(node, opts) { + assert("ModuleExpression", node, opts); + } + function assertTopicReference(node, opts) { + assert("TopicReference", node, opts); + } + function assertPipelineTopicExpression(node, opts) { + assert("PipelineTopicExpression", node, opts); + } + function assertPipelineBareFunction(node, opts) { + assert("PipelineBareFunction", node, opts); + } + function assertPipelinePrimaryTopicReference(node, opts) { + assert("PipelinePrimaryTopicReference", node, opts); + } + function assertTSParameterProperty(node, opts) { + assert("TSParameterProperty", node, opts); + } + function assertTSDeclareFunction(node, opts) { + assert("TSDeclareFunction", node, opts); + } + function assertTSDeclareMethod(node, opts) { + assert("TSDeclareMethod", node, opts); + } + function assertTSQualifiedName(node, opts) { + assert("TSQualifiedName", node, opts); + } + function assertTSCallSignatureDeclaration(node, opts) { + assert("TSCallSignatureDeclaration", node, opts); + } + function assertTSConstructSignatureDeclaration(node, opts) { + assert("TSConstructSignatureDeclaration", node, opts); + } + function assertTSPropertySignature(node, opts) { + assert("TSPropertySignature", node, opts); + } + function assertTSMethodSignature(node, opts) { + assert("TSMethodSignature", node, opts); + } + function assertTSIndexSignature(node, opts) { + assert("TSIndexSignature", node, opts); + } + function assertTSAnyKeyword(node, opts) { + assert("TSAnyKeyword", node, opts); + } + function assertTSBooleanKeyword(node, opts) { + assert("TSBooleanKeyword", node, opts); + } + function assertTSBigIntKeyword(node, opts) { + assert("TSBigIntKeyword", node, opts); + } + function assertTSIntrinsicKeyword(node, opts) { + assert("TSIntrinsicKeyword", node, opts); + } + function assertTSNeverKeyword(node, opts) { + assert("TSNeverKeyword", node, opts); + } + function assertTSNullKeyword(node, opts) { + assert("TSNullKeyword", node, opts); + } + function assertTSNumberKeyword(node, opts) { + assert("TSNumberKeyword", node, opts); + } + function assertTSObjectKeyword(node, opts) { + assert("TSObjectKeyword", node, opts); + } + function assertTSStringKeyword(node, opts) { + assert("TSStringKeyword", node, opts); + } + function assertTSSymbolKeyword(node, opts) { + assert("TSSymbolKeyword", node, opts); + } + function assertTSUndefinedKeyword(node, opts) { + assert("TSUndefinedKeyword", node, opts); + } + function assertTSUnknownKeyword(node, opts) { + assert("TSUnknownKeyword", node, opts); + } + function assertTSVoidKeyword(node, opts) { + assert("TSVoidKeyword", node, opts); + } + function assertTSThisType(node, opts) { + assert("TSThisType", node, opts); + } + function assertTSFunctionType(node, opts) { + assert("TSFunctionType", node, opts); + } + function assertTSConstructorType(node, opts) { + assert("TSConstructorType", node, opts); + } + function assertTSTypeReference(node, opts) { + assert("TSTypeReference", node, opts); + } + function assertTSTypePredicate(node, opts) { + assert("TSTypePredicate", node, opts); + } + function assertTSTypeQuery(node, opts) { + assert("TSTypeQuery", node, opts); + } + function assertTSTypeLiteral(node, opts) { + assert("TSTypeLiteral", node, opts); + } + function assertTSArrayType(node, opts) { + assert("TSArrayType", node, opts); + } + function assertTSTupleType(node, opts) { + assert("TSTupleType", node, opts); + } + function assertTSOptionalType(node, opts) { + assert("TSOptionalType", node, opts); + } + function assertTSRestType(node, opts) { + assert("TSRestType", node, opts); + } + function assertTSNamedTupleMember(node, opts) { + assert("TSNamedTupleMember", node, opts); + } + function assertTSUnionType(node, opts) { + assert("TSUnionType", node, opts); + } + function assertTSIntersectionType(node, opts) { + assert("TSIntersectionType", node, opts); + } + function assertTSConditionalType(node, opts) { + assert("TSConditionalType", node, opts); + } + function assertTSInferType(node, opts) { + assert("TSInferType", node, opts); + } + function assertTSParenthesizedType(node, opts) { + assert("TSParenthesizedType", node, opts); + } + function assertTSTypeOperator(node, opts) { + assert("TSTypeOperator", node, opts); + } + function assertTSIndexedAccessType(node, opts) { + assert("TSIndexedAccessType", node, opts); + } + function assertTSMappedType(node, opts) { + assert("TSMappedType", node, opts); + } + function assertTSLiteralType(node, opts) { + assert("TSLiteralType", node, opts); + } + function assertTSExpressionWithTypeArguments(node, opts) { + assert("TSExpressionWithTypeArguments", node, opts); + } + function assertTSInterfaceDeclaration(node, opts) { + assert("TSInterfaceDeclaration", node, opts); + } + function assertTSInterfaceBody(node, opts) { + assert("TSInterfaceBody", node, opts); + } + function assertTSTypeAliasDeclaration(node, opts) { + assert("TSTypeAliasDeclaration", node, opts); + } + function assertTSInstantiationExpression(node, opts) { + assert("TSInstantiationExpression", node, opts); + } + function assertTSAsExpression(node, opts) { + assert("TSAsExpression", node, opts); + } + function assertTSSatisfiesExpression(node, opts) { + assert("TSSatisfiesExpression", node, opts); + } + function assertTSTypeAssertion(node, opts) { + assert("TSTypeAssertion", node, opts); + } + function assertTSEnumDeclaration(node, opts) { + assert("TSEnumDeclaration", node, opts); + } + function assertTSEnumMember(node, opts) { + assert("TSEnumMember", node, opts); + } + function assertTSModuleDeclaration(node, opts) { + assert("TSModuleDeclaration", node, opts); + } + function assertTSModuleBlock(node, opts) { + assert("TSModuleBlock", node, opts); + } + function assertTSImportType(node, opts) { + assert("TSImportType", node, opts); + } + function assertTSImportEqualsDeclaration(node, opts) { + assert("TSImportEqualsDeclaration", node, opts); + } + function assertTSExternalModuleReference(node, opts) { + assert("TSExternalModuleReference", node, opts); + } + function assertTSNonNullExpression(node, opts) { + assert("TSNonNullExpression", node, opts); + } + function assertTSExportAssignment(node, opts) { + assert("TSExportAssignment", node, opts); + } + function assertTSNamespaceExportDeclaration(node, opts) { + assert("TSNamespaceExportDeclaration", node, opts); + } + function assertTSTypeAnnotation(node, opts) { + assert("TSTypeAnnotation", node, opts); + } + function assertTSTypeParameterInstantiation(node, opts) { + assert("TSTypeParameterInstantiation", node, opts); + } + function assertTSTypeParameterDeclaration(node, opts) { + assert("TSTypeParameterDeclaration", node, opts); + } + function assertTSTypeParameter(node, opts) { + assert("TSTypeParameter", node, opts); + } + function assertStandardized(node, opts) { + assert("Standardized", node, opts); + } + function assertExpression(node, opts) { + assert("Expression", node, opts); + } + function assertBinary(node, opts) { + assert("Binary", node, opts); + } + function assertScopable(node, opts) { + assert("Scopable", node, opts); + } + function assertBlockParent(node, opts) { + assert("BlockParent", node, opts); + } + function assertBlock(node, opts) { + assert("Block", node, opts); + } + function assertStatement(node, opts) { + assert("Statement", node, opts); + } + function assertTerminatorless(node, opts) { + assert("Terminatorless", node, opts); + } + function assertCompletionStatement(node, opts) { + assert("CompletionStatement", node, opts); + } + function assertConditional(node, opts) { + assert("Conditional", node, opts); + } + function assertLoop(node, opts) { + assert("Loop", node, opts); + } + function assertWhile(node, opts) { + assert("While", node, opts); + } + function assertExpressionWrapper(node, opts) { + assert("ExpressionWrapper", node, opts); + } + function assertFor(node, opts) { + assert("For", node, opts); + } + function assertForXStatement(node, opts) { + assert("ForXStatement", node, opts); + } + function assertFunction(node, opts) { + assert("Function", node, opts); + } + function assertFunctionParent(node, opts) { + assert("FunctionParent", node, opts); + } + function assertPureish(node, opts) { + assert("Pureish", node, opts); + } + function assertDeclaration(node, opts) { + assert("Declaration", node, opts); + } + function assertPatternLike(node, opts) { + assert("PatternLike", node, opts); + } + function assertLVal(node, opts) { + assert("LVal", node, opts); + } + function assertTSEntityName(node, opts) { + assert("TSEntityName", node, opts); + } + function assertLiteral(node, opts) { + assert("Literal", node, opts); + } + function assertImmutable(node, opts) { + assert("Immutable", node, opts); + } + function assertUserWhitespacable(node, opts) { + assert("UserWhitespacable", node, opts); + } + function assertMethod(node, opts) { + assert("Method", node, opts); + } + function assertObjectMember(node, opts) { + assert("ObjectMember", node, opts); + } + function assertProperty(node, opts) { + assert("Property", node, opts); + } + function assertUnaryLike(node, opts) { + assert("UnaryLike", node, opts); + } + function assertPattern(node, opts) { + assert("Pattern", node, opts); + } + function assertClass(node, opts) { + assert("Class", node, opts); + } + function assertImportOrExportDeclaration(node, opts) { + assert("ImportOrExportDeclaration", node, opts); + } + function assertExportDeclaration(node, opts) { + assert("ExportDeclaration", node, opts); + } + function assertModuleSpecifier(node, opts) { + assert("ModuleSpecifier", node, opts); + } + function assertAccessor(node, opts) { + assert("Accessor", node, opts); + } + function assertPrivate(node, opts) { + assert("Private", node, opts); + } + function assertFlow(node, opts) { + assert("Flow", node, opts); + } + function assertFlowType(node, opts) { + assert("FlowType", node, opts); + } + function assertFlowBaseAnnotation(node, opts) { + assert("FlowBaseAnnotation", node, opts); + } + function assertFlowDeclaration(node, opts) { + assert("FlowDeclaration", node, opts); + } + function assertFlowPredicate(node, opts) { + assert("FlowPredicate", node, opts); + } + function assertEnumBody(node, opts) { + assert("EnumBody", node, opts); + } + function assertEnumMember(node, opts) { + assert("EnumMember", node, opts); + } + function assertJSX(node, opts) { + assert("JSX", node, opts); + } + function assertMiscellaneous(node, opts) { + assert("Miscellaneous", node, opts); + } + function assertTypeScript(node, opts) { + assert("TypeScript", node, opts); + } + function assertTSTypeElement(node, opts) { + assert("TSTypeElement", node, opts); + } + function assertTSType(node, opts) { + assert("TSType", node, opts); + } + function assertTSBaseType(node, opts) { + assert("TSBaseType", node, opts); + } + function assertNumberLiteral(node, opts) { + (0, _deprecationWarning.default)("assertNumberLiteral", "assertNumericLiteral"); + assert("NumberLiteral", node, opts); + } + function assertRegexLiteral(node, opts) { + (0, _deprecationWarning.default)("assertRegexLiteral", "assertRegExpLiteral"); + assert("RegexLiteral", node, opts); + } + function assertRestProperty(node, opts) { + (0, _deprecationWarning.default)("assertRestProperty", "assertRestElement"); + assert("RestProperty", node, opts); + } + function assertSpreadProperty(node, opts) { + (0, _deprecationWarning.default)("assertSpreadProperty", "assertSpreadElement"); + assert("SpreadProperty", node, opts); + } + function assertModuleDeclaration(node, opts) { + (0, _deprecationWarning.default)("assertModuleDeclaration", "assertImportOrExportDeclaration"); + assert("ModuleDeclaration", node, opts); + } + + + return generated$1; +} + +var createTypeAnnotationBasedOnTypeof = {}; + +var hasRequiredCreateTypeAnnotationBasedOnTypeof; + +function requireCreateTypeAnnotationBasedOnTypeof () { + if (hasRequiredCreateTypeAnnotationBasedOnTypeof) return createTypeAnnotationBasedOnTypeof; + hasRequiredCreateTypeAnnotationBasedOnTypeof = 1; + + Object.defineProperty(createTypeAnnotationBasedOnTypeof, "__esModule", { + value: true + }); + createTypeAnnotationBasedOnTypeof.default = void 0; + var _index = requireGenerated$2(); + createTypeAnnotationBasedOnTypeof.default = createTypeAnnotationBasedOnTypeof$1; + function createTypeAnnotationBasedOnTypeof$1(type) { + switch (type) { + case "string": + return (0, _index.stringTypeAnnotation)(); + case "number": + return (0, _index.numberTypeAnnotation)(); + case "undefined": + return (0, _index.voidTypeAnnotation)(); + case "boolean": + return (0, _index.booleanTypeAnnotation)(); + case "function": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Function")); + case "object": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Object")); + case "symbol": + return (0, _index.genericTypeAnnotation)((0, _index.identifier)("Symbol")); + case "bigint": + return (0, _index.anyTypeAnnotation)(); + } + throw new Error("Invalid typeof value: " + type); + } + + + return createTypeAnnotationBasedOnTypeof; +} + +var createFlowUnionType = {}; + +var removeTypeDuplicates$1 = {}; + +var hasRequiredRemoveTypeDuplicates$1; + +function requireRemoveTypeDuplicates$1 () { + if (hasRequiredRemoveTypeDuplicates$1) return removeTypeDuplicates$1; + hasRequiredRemoveTypeDuplicates$1 = 1; + + Object.defineProperty(removeTypeDuplicates$1, "__esModule", { + value: true + }); + removeTypeDuplicates$1.default = removeTypeDuplicates; + var _index = requireGenerated$3(); + function getQualifiedName(node) { + return (0, _index.isIdentifier)(node) ? node.name : `${node.id.name}.${getQualifiedName(node.qualification)}`; + } + function removeTypeDuplicates(nodesIn) { + const nodes = Array.from(nodesIn); + const generics = new Map(); + const bases = new Map(); + const typeGroups = new Set(); + const types = []; + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + if (!node) continue; + if (types.includes(node)) { + continue; + } + if ((0, _index.isAnyTypeAnnotation)(node)) { + return [node]; + } + if ((0, _index.isFlowBaseAnnotation)(node)) { + bases.set(node.type, node); + continue; + } + if ((0, _index.isUnionTypeAnnotation)(node)) { + if (!typeGroups.has(node.types)) { + nodes.push(...node.types); + typeGroups.add(node.types); + } + continue; + } + if ((0, _index.isGenericTypeAnnotation)(node)) { + const name = getQualifiedName(node.id); + if (generics.has(name)) { + let existing = generics.get(name); + if (existing.typeParameters) { + if (node.typeParameters) { + existing.typeParameters.params.push(...node.typeParameters.params); + existing.typeParameters.params = removeTypeDuplicates(existing.typeParameters.params); + } + } else { + existing = node.typeParameters; + } + } else { + generics.set(name, node); + } + continue; + } + types.push(node); + } + for (const [, baseType] of bases) { + types.push(baseType); + } + for (const [, genericName] of generics) { + types.push(genericName); + } + return types; + } + + + return removeTypeDuplicates$1; +} + +var hasRequiredCreateFlowUnionType; + +function requireCreateFlowUnionType () { + if (hasRequiredCreateFlowUnionType) return createFlowUnionType; + hasRequiredCreateFlowUnionType = 1; + + Object.defineProperty(createFlowUnionType, "__esModule", { + value: true + }); + createFlowUnionType.default = createFlowUnionType$1; + var _index = requireGenerated$2(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates$1(); + function createFlowUnionType$1(types) { + const flattened = (0, _removeTypeDuplicates.default)(types); + if (flattened.length === 1) { + return flattened[0]; + } else { + return (0, _index.unionTypeAnnotation)(flattened); + } + } + + + return createFlowUnionType; +} + +var createTSUnionType = {}; + +var removeTypeDuplicates = {}; + +var hasRequiredRemoveTypeDuplicates; + +function requireRemoveTypeDuplicates () { + if (hasRequiredRemoveTypeDuplicates) return removeTypeDuplicates; + hasRequiredRemoveTypeDuplicates = 1; + + Object.defineProperty(removeTypeDuplicates, "__esModule", { + value: true + }); + removeTypeDuplicates.default = removeTypeDuplicates$1; + var _index = requireGenerated$3(); + function getQualifiedName(node) { + return (0, _index.isIdentifier)(node) ? node.name : `${node.right.name}.${getQualifiedName(node.left)}`; + } + function removeTypeDuplicates$1(nodesIn) { + const nodes = Array.from(nodesIn); + const generics = new Map(); + const bases = new Map(); + const typeGroups = new Set(); + const types = []; + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + if (!node) continue; + if (types.includes(node)) { + continue; + } + if ((0, _index.isTSAnyKeyword)(node)) { + return [node]; + } + if ((0, _index.isTSBaseType)(node)) { + bases.set(node.type, node); + continue; + } + if ((0, _index.isTSUnionType)(node)) { + if (!typeGroups.has(node.types)) { + nodes.push(...node.types); + typeGroups.add(node.types); + } + continue; + } + if ((0, _index.isTSTypeReference)(node) && node.typeParameters) { + const name = getQualifiedName(node.typeName); + if (generics.has(name)) { + let existing = generics.get(name); + if (existing.typeParameters) { + if (node.typeParameters) { + existing.typeParameters.params.push(...node.typeParameters.params); + existing.typeParameters.params = removeTypeDuplicates$1(existing.typeParameters.params); + } + } else { + existing = node.typeParameters; + } + } else { + generics.set(name, node); + } + continue; + } + types.push(node); + } + for (const [, baseType] of bases) { + types.push(baseType); + } + for (const [, genericName] of generics) { + types.push(genericName); + } + return types; + } + + + return removeTypeDuplicates; +} + +var hasRequiredCreateTSUnionType; + +function requireCreateTSUnionType () { + if (hasRequiredCreateTSUnionType) return createTSUnionType; + hasRequiredCreateTSUnionType = 1; + + Object.defineProperty(createTSUnionType, "__esModule", { + value: true + }); + createTSUnionType.default = createTSUnionType$1; + var _index = requireGenerated$2(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates(); + var _index2 = requireGenerated$3(); + function createTSUnionType$1(typeAnnotations) { + const types = typeAnnotations.map(type => { + return (0, _index2.isTSTypeAnnotation)(type) ? type.typeAnnotation : type; + }); + const flattened = (0, _removeTypeDuplicates.default)(types); + if (flattened.length === 1) { + return flattened[0]; + } else { + return (0, _index.tsUnionType)(flattened); + } + } + + + return createTSUnionType; +} + +var uppercase = {}; + +var hasRequiredUppercase; + +function requireUppercase () { + if (hasRequiredUppercase) return uppercase; + hasRequiredUppercase = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "AnyTypeAnnotation", { + enumerable: true, + get: function () { + return _index.anyTypeAnnotation; + } + }); + Object.defineProperty(exports, "ArgumentPlaceholder", { + enumerable: true, + get: function () { + return _index.argumentPlaceholder; + } + }); + Object.defineProperty(exports, "ArrayExpression", { + enumerable: true, + get: function () { + return _index.arrayExpression; + } + }); + Object.defineProperty(exports, "ArrayPattern", { + enumerable: true, + get: function () { + return _index.arrayPattern; + } + }); + Object.defineProperty(exports, "ArrayTypeAnnotation", { + enumerable: true, + get: function () { + return _index.arrayTypeAnnotation; + } + }); + Object.defineProperty(exports, "ArrowFunctionExpression", { + enumerable: true, + get: function () { + return _index.arrowFunctionExpression; + } + }); + Object.defineProperty(exports, "AssignmentExpression", { + enumerable: true, + get: function () { + return _index.assignmentExpression; + } + }); + Object.defineProperty(exports, "AssignmentPattern", { + enumerable: true, + get: function () { + return _index.assignmentPattern; + } + }); + Object.defineProperty(exports, "AwaitExpression", { + enumerable: true, + get: function () { + return _index.awaitExpression; + } + }); + Object.defineProperty(exports, "BigIntLiteral", { + enumerable: true, + get: function () { + return _index.bigIntLiteral; + } + }); + Object.defineProperty(exports, "BinaryExpression", { + enumerable: true, + get: function () { + return _index.binaryExpression; + } + }); + Object.defineProperty(exports, "BindExpression", { + enumerable: true, + get: function () { + return _index.bindExpression; + } + }); + Object.defineProperty(exports, "BlockStatement", { + enumerable: true, + get: function () { + return _index.blockStatement; + } + }); + Object.defineProperty(exports, "BooleanLiteral", { + enumerable: true, + get: function () { + return _index.booleanLiteral; + } + }); + Object.defineProperty(exports, "BooleanLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.booleanLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "BooleanTypeAnnotation", { + enumerable: true, + get: function () { + return _index.booleanTypeAnnotation; + } + }); + Object.defineProperty(exports, "BreakStatement", { + enumerable: true, + get: function () { + return _index.breakStatement; + } + }); + Object.defineProperty(exports, "CallExpression", { + enumerable: true, + get: function () { + return _index.callExpression; + } + }); + Object.defineProperty(exports, "CatchClause", { + enumerable: true, + get: function () { + return _index.catchClause; + } + }); + Object.defineProperty(exports, "ClassAccessorProperty", { + enumerable: true, + get: function () { + return _index.classAccessorProperty; + } + }); + Object.defineProperty(exports, "ClassBody", { + enumerable: true, + get: function () { + return _index.classBody; + } + }); + Object.defineProperty(exports, "ClassDeclaration", { + enumerable: true, + get: function () { + return _index.classDeclaration; + } + }); + Object.defineProperty(exports, "ClassExpression", { + enumerable: true, + get: function () { + return _index.classExpression; + } + }); + Object.defineProperty(exports, "ClassImplements", { + enumerable: true, + get: function () { + return _index.classImplements; + } + }); + Object.defineProperty(exports, "ClassMethod", { + enumerable: true, + get: function () { + return _index.classMethod; + } + }); + Object.defineProperty(exports, "ClassPrivateMethod", { + enumerable: true, + get: function () { + return _index.classPrivateMethod; + } + }); + Object.defineProperty(exports, "ClassPrivateProperty", { + enumerable: true, + get: function () { + return _index.classPrivateProperty; + } + }); + Object.defineProperty(exports, "ClassProperty", { + enumerable: true, + get: function () { + return _index.classProperty; + } + }); + Object.defineProperty(exports, "ConditionalExpression", { + enumerable: true, + get: function () { + return _index.conditionalExpression; + } + }); + Object.defineProperty(exports, "ContinueStatement", { + enumerable: true, + get: function () { + return _index.continueStatement; + } + }); + Object.defineProperty(exports, "DebuggerStatement", { + enumerable: true, + get: function () { + return _index.debuggerStatement; + } + }); + Object.defineProperty(exports, "DecimalLiteral", { + enumerable: true, + get: function () { + return _index.decimalLiteral; + } + }); + Object.defineProperty(exports, "DeclareClass", { + enumerable: true, + get: function () { + return _index.declareClass; + } + }); + Object.defineProperty(exports, "DeclareExportAllDeclaration", { + enumerable: true, + get: function () { + return _index.declareExportAllDeclaration; + } + }); + Object.defineProperty(exports, "DeclareExportDeclaration", { + enumerable: true, + get: function () { + return _index.declareExportDeclaration; + } + }); + Object.defineProperty(exports, "DeclareFunction", { + enumerable: true, + get: function () { + return _index.declareFunction; + } + }); + Object.defineProperty(exports, "DeclareInterface", { + enumerable: true, + get: function () { + return _index.declareInterface; + } + }); + Object.defineProperty(exports, "DeclareModule", { + enumerable: true, + get: function () { + return _index.declareModule; + } + }); + Object.defineProperty(exports, "DeclareModuleExports", { + enumerable: true, + get: function () { + return _index.declareModuleExports; + } + }); + Object.defineProperty(exports, "DeclareOpaqueType", { + enumerable: true, + get: function () { + return _index.declareOpaqueType; + } + }); + Object.defineProperty(exports, "DeclareTypeAlias", { + enumerable: true, + get: function () { + return _index.declareTypeAlias; + } + }); + Object.defineProperty(exports, "DeclareVariable", { + enumerable: true, + get: function () { + return _index.declareVariable; + } + }); + Object.defineProperty(exports, "DeclaredPredicate", { + enumerable: true, + get: function () { + return _index.declaredPredicate; + } + }); + Object.defineProperty(exports, "Decorator", { + enumerable: true, + get: function () { + return _index.decorator; + } + }); + Object.defineProperty(exports, "Directive", { + enumerable: true, + get: function () { + return _index.directive; + } + }); + Object.defineProperty(exports, "DirectiveLiteral", { + enumerable: true, + get: function () { + return _index.directiveLiteral; + } + }); + Object.defineProperty(exports, "DoExpression", { + enumerable: true, + get: function () { + return _index.doExpression; + } + }); + Object.defineProperty(exports, "DoWhileStatement", { + enumerable: true, + get: function () { + return _index.doWhileStatement; + } + }); + Object.defineProperty(exports, "EmptyStatement", { + enumerable: true, + get: function () { + return _index.emptyStatement; + } + }); + Object.defineProperty(exports, "EmptyTypeAnnotation", { + enumerable: true, + get: function () { + return _index.emptyTypeAnnotation; + } + }); + Object.defineProperty(exports, "EnumBooleanBody", { + enumerable: true, + get: function () { + return _index.enumBooleanBody; + } + }); + Object.defineProperty(exports, "EnumBooleanMember", { + enumerable: true, + get: function () { + return _index.enumBooleanMember; + } + }); + Object.defineProperty(exports, "EnumDeclaration", { + enumerable: true, + get: function () { + return _index.enumDeclaration; + } + }); + Object.defineProperty(exports, "EnumDefaultedMember", { + enumerable: true, + get: function () { + return _index.enumDefaultedMember; + } + }); + Object.defineProperty(exports, "EnumNumberBody", { + enumerable: true, + get: function () { + return _index.enumNumberBody; + } + }); + Object.defineProperty(exports, "EnumNumberMember", { + enumerable: true, + get: function () { + return _index.enumNumberMember; + } + }); + Object.defineProperty(exports, "EnumStringBody", { + enumerable: true, + get: function () { + return _index.enumStringBody; + } + }); + Object.defineProperty(exports, "EnumStringMember", { + enumerable: true, + get: function () { + return _index.enumStringMember; + } + }); + Object.defineProperty(exports, "EnumSymbolBody", { + enumerable: true, + get: function () { + return _index.enumSymbolBody; + } + }); + Object.defineProperty(exports, "ExistsTypeAnnotation", { + enumerable: true, + get: function () { + return _index.existsTypeAnnotation; + } + }); + Object.defineProperty(exports, "ExportAllDeclaration", { + enumerable: true, + get: function () { + return _index.exportAllDeclaration; + } + }); + Object.defineProperty(exports, "ExportDefaultDeclaration", { + enumerable: true, + get: function () { + return _index.exportDefaultDeclaration; + } + }); + Object.defineProperty(exports, "ExportDefaultSpecifier", { + enumerable: true, + get: function () { + return _index.exportDefaultSpecifier; + } + }); + Object.defineProperty(exports, "ExportNamedDeclaration", { + enumerable: true, + get: function () { + return _index.exportNamedDeclaration; + } + }); + Object.defineProperty(exports, "ExportNamespaceSpecifier", { + enumerable: true, + get: function () { + return _index.exportNamespaceSpecifier; + } + }); + Object.defineProperty(exports, "ExportSpecifier", { + enumerable: true, + get: function () { + return _index.exportSpecifier; + } + }); + Object.defineProperty(exports, "ExpressionStatement", { + enumerable: true, + get: function () { + return _index.expressionStatement; + } + }); + Object.defineProperty(exports, "File", { + enumerable: true, + get: function () { + return _index.file; + } + }); + Object.defineProperty(exports, "ForInStatement", { + enumerable: true, + get: function () { + return _index.forInStatement; + } + }); + Object.defineProperty(exports, "ForOfStatement", { + enumerable: true, + get: function () { + return _index.forOfStatement; + } + }); + Object.defineProperty(exports, "ForStatement", { + enumerable: true, + get: function () { + return _index.forStatement; + } + }); + Object.defineProperty(exports, "FunctionDeclaration", { + enumerable: true, + get: function () { + return _index.functionDeclaration; + } + }); + Object.defineProperty(exports, "FunctionExpression", { + enumerable: true, + get: function () { + return _index.functionExpression; + } + }); + Object.defineProperty(exports, "FunctionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.functionTypeAnnotation; + } + }); + Object.defineProperty(exports, "FunctionTypeParam", { + enumerable: true, + get: function () { + return _index.functionTypeParam; + } + }); + Object.defineProperty(exports, "GenericTypeAnnotation", { + enumerable: true, + get: function () { + return _index.genericTypeAnnotation; + } + }); + Object.defineProperty(exports, "Identifier", { + enumerable: true, + get: function () { + return _index.identifier; + } + }); + Object.defineProperty(exports, "IfStatement", { + enumerable: true, + get: function () { + return _index.ifStatement; + } + }); + Object.defineProperty(exports, "Import", { + enumerable: true, + get: function () { + return _index.import; + } + }); + Object.defineProperty(exports, "ImportAttribute", { + enumerable: true, + get: function () { + return _index.importAttribute; + } + }); + Object.defineProperty(exports, "ImportDeclaration", { + enumerable: true, + get: function () { + return _index.importDeclaration; + } + }); + Object.defineProperty(exports, "ImportDefaultSpecifier", { + enumerable: true, + get: function () { + return _index.importDefaultSpecifier; + } + }); + Object.defineProperty(exports, "ImportExpression", { + enumerable: true, + get: function () { + return _index.importExpression; + } + }); + Object.defineProperty(exports, "ImportNamespaceSpecifier", { + enumerable: true, + get: function () { + return _index.importNamespaceSpecifier; + } + }); + Object.defineProperty(exports, "ImportSpecifier", { + enumerable: true, + get: function () { + return _index.importSpecifier; + } + }); + Object.defineProperty(exports, "IndexedAccessType", { + enumerable: true, + get: function () { + return _index.indexedAccessType; + } + }); + Object.defineProperty(exports, "InferredPredicate", { + enumerable: true, + get: function () { + return _index.inferredPredicate; + } + }); + Object.defineProperty(exports, "InterfaceDeclaration", { + enumerable: true, + get: function () { + return _index.interfaceDeclaration; + } + }); + Object.defineProperty(exports, "InterfaceExtends", { + enumerable: true, + get: function () { + return _index.interfaceExtends; + } + }); + Object.defineProperty(exports, "InterfaceTypeAnnotation", { + enumerable: true, + get: function () { + return _index.interfaceTypeAnnotation; + } + }); + Object.defineProperty(exports, "InterpreterDirective", { + enumerable: true, + get: function () { + return _index.interpreterDirective; + } + }); + Object.defineProperty(exports, "IntersectionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.intersectionTypeAnnotation; + } + }); + Object.defineProperty(exports, "JSXAttribute", { + enumerable: true, + get: function () { + return _index.jsxAttribute; + } + }); + Object.defineProperty(exports, "JSXClosingElement", { + enumerable: true, + get: function () { + return _index.jsxClosingElement; + } + }); + Object.defineProperty(exports, "JSXClosingFragment", { + enumerable: true, + get: function () { + return _index.jsxClosingFragment; + } + }); + Object.defineProperty(exports, "JSXElement", { + enumerable: true, + get: function () { + return _index.jsxElement; + } + }); + Object.defineProperty(exports, "JSXEmptyExpression", { + enumerable: true, + get: function () { + return _index.jsxEmptyExpression; + } + }); + Object.defineProperty(exports, "JSXExpressionContainer", { + enumerable: true, + get: function () { + return _index.jsxExpressionContainer; + } + }); + Object.defineProperty(exports, "JSXFragment", { + enumerable: true, + get: function () { + return _index.jsxFragment; + } + }); + Object.defineProperty(exports, "JSXIdentifier", { + enumerable: true, + get: function () { + return _index.jsxIdentifier; + } + }); + Object.defineProperty(exports, "JSXMemberExpression", { + enumerable: true, + get: function () { + return _index.jsxMemberExpression; + } + }); + Object.defineProperty(exports, "JSXNamespacedName", { + enumerable: true, + get: function () { + return _index.jsxNamespacedName; + } + }); + Object.defineProperty(exports, "JSXOpeningElement", { + enumerable: true, + get: function () { + return _index.jsxOpeningElement; + } + }); + Object.defineProperty(exports, "JSXOpeningFragment", { + enumerable: true, + get: function () { + return _index.jsxOpeningFragment; + } + }); + Object.defineProperty(exports, "JSXSpreadAttribute", { + enumerable: true, + get: function () { + return _index.jsxSpreadAttribute; + } + }); + Object.defineProperty(exports, "JSXSpreadChild", { + enumerable: true, + get: function () { + return _index.jsxSpreadChild; + } + }); + Object.defineProperty(exports, "JSXText", { + enumerable: true, + get: function () { + return _index.jsxText; + } + }); + Object.defineProperty(exports, "LabeledStatement", { + enumerable: true, + get: function () { + return _index.labeledStatement; + } + }); + Object.defineProperty(exports, "LogicalExpression", { + enumerable: true, + get: function () { + return _index.logicalExpression; + } + }); + Object.defineProperty(exports, "MemberExpression", { + enumerable: true, + get: function () { + return _index.memberExpression; + } + }); + Object.defineProperty(exports, "MetaProperty", { + enumerable: true, + get: function () { + return _index.metaProperty; + } + }); + Object.defineProperty(exports, "MixedTypeAnnotation", { + enumerable: true, + get: function () { + return _index.mixedTypeAnnotation; + } + }); + Object.defineProperty(exports, "ModuleExpression", { + enumerable: true, + get: function () { + return _index.moduleExpression; + } + }); + Object.defineProperty(exports, "NewExpression", { + enumerable: true, + get: function () { + return _index.newExpression; + } + }); + Object.defineProperty(exports, "Noop", { + enumerable: true, + get: function () { + return _index.noop; + } + }); + Object.defineProperty(exports, "NullLiteral", { + enumerable: true, + get: function () { + return _index.nullLiteral; + } + }); + Object.defineProperty(exports, "NullLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.nullLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "NullableTypeAnnotation", { + enumerable: true, + get: function () { + return _index.nullableTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumberLiteral", { + enumerable: true, + get: function () { + return _index.numberLiteral; + } + }); + Object.defineProperty(exports, "NumberLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.numberLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumberTypeAnnotation", { + enumerable: true, + get: function () { + return _index.numberTypeAnnotation; + } + }); + Object.defineProperty(exports, "NumericLiteral", { + enumerable: true, + get: function () { + return _index.numericLiteral; + } + }); + Object.defineProperty(exports, "ObjectExpression", { + enumerable: true, + get: function () { + return _index.objectExpression; + } + }); + Object.defineProperty(exports, "ObjectMethod", { + enumerable: true, + get: function () { + return _index.objectMethod; + } + }); + Object.defineProperty(exports, "ObjectPattern", { + enumerable: true, + get: function () { + return _index.objectPattern; + } + }); + Object.defineProperty(exports, "ObjectProperty", { + enumerable: true, + get: function () { + return _index.objectProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeAnnotation", { + enumerable: true, + get: function () { + return _index.objectTypeAnnotation; + } + }); + Object.defineProperty(exports, "ObjectTypeCallProperty", { + enumerable: true, + get: function () { + return _index.objectTypeCallProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeIndexer", { + enumerable: true, + get: function () { + return _index.objectTypeIndexer; + } + }); + Object.defineProperty(exports, "ObjectTypeInternalSlot", { + enumerable: true, + get: function () { + return _index.objectTypeInternalSlot; + } + }); + Object.defineProperty(exports, "ObjectTypeProperty", { + enumerable: true, + get: function () { + return _index.objectTypeProperty; + } + }); + Object.defineProperty(exports, "ObjectTypeSpreadProperty", { + enumerable: true, + get: function () { + return _index.objectTypeSpreadProperty; + } + }); + Object.defineProperty(exports, "OpaqueType", { + enumerable: true, + get: function () { + return _index.opaqueType; + } + }); + Object.defineProperty(exports, "OptionalCallExpression", { + enumerable: true, + get: function () { + return _index.optionalCallExpression; + } + }); + Object.defineProperty(exports, "OptionalIndexedAccessType", { + enumerable: true, + get: function () { + return _index.optionalIndexedAccessType; + } + }); + Object.defineProperty(exports, "OptionalMemberExpression", { + enumerable: true, + get: function () { + return _index.optionalMemberExpression; + } + }); + Object.defineProperty(exports, "ParenthesizedExpression", { + enumerable: true, + get: function () { + return _index.parenthesizedExpression; + } + }); + Object.defineProperty(exports, "PipelineBareFunction", { + enumerable: true, + get: function () { + return _index.pipelineBareFunction; + } + }); + Object.defineProperty(exports, "PipelinePrimaryTopicReference", { + enumerable: true, + get: function () { + return _index.pipelinePrimaryTopicReference; + } + }); + Object.defineProperty(exports, "PipelineTopicExpression", { + enumerable: true, + get: function () { + return _index.pipelineTopicExpression; + } + }); + Object.defineProperty(exports, "Placeholder", { + enumerable: true, + get: function () { + return _index.placeholder; + } + }); + Object.defineProperty(exports, "PrivateName", { + enumerable: true, + get: function () { + return _index.privateName; + } + }); + Object.defineProperty(exports, "Program", { + enumerable: true, + get: function () { + return _index.program; + } + }); + Object.defineProperty(exports, "QualifiedTypeIdentifier", { + enumerable: true, + get: function () { + return _index.qualifiedTypeIdentifier; + } + }); + Object.defineProperty(exports, "RecordExpression", { + enumerable: true, + get: function () { + return _index.recordExpression; + } + }); + Object.defineProperty(exports, "RegExpLiteral", { + enumerable: true, + get: function () { + return _index.regExpLiteral; + } + }); + Object.defineProperty(exports, "RegexLiteral", { + enumerable: true, + get: function () { + return _index.regexLiteral; + } + }); + Object.defineProperty(exports, "RestElement", { + enumerable: true, + get: function () { + return _index.restElement; + } + }); + Object.defineProperty(exports, "RestProperty", { + enumerable: true, + get: function () { + return _index.restProperty; + } + }); + Object.defineProperty(exports, "ReturnStatement", { + enumerable: true, + get: function () { + return _index.returnStatement; + } + }); + Object.defineProperty(exports, "SequenceExpression", { + enumerable: true, + get: function () { + return _index.sequenceExpression; + } + }); + Object.defineProperty(exports, "SpreadElement", { + enumerable: true, + get: function () { + return _index.spreadElement; + } + }); + Object.defineProperty(exports, "SpreadProperty", { + enumerable: true, + get: function () { + return _index.spreadProperty; + } + }); + Object.defineProperty(exports, "StaticBlock", { + enumerable: true, + get: function () { + return _index.staticBlock; + } + }); + Object.defineProperty(exports, "StringLiteral", { + enumerable: true, + get: function () { + return _index.stringLiteral; + } + }); + Object.defineProperty(exports, "StringLiteralTypeAnnotation", { + enumerable: true, + get: function () { + return _index.stringLiteralTypeAnnotation; + } + }); + Object.defineProperty(exports, "StringTypeAnnotation", { + enumerable: true, + get: function () { + return _index.stringTypeAnnotation; + } + }); + Object.defineProperty(exports, "Super", { + enumerable: true, + get: function () { + return _index.super; + } + }); + Object.defineProperty(exports, "SwitchCase", { + enumerable: true, + get: function () { + return _index.switchCase; + } + }); + Object.defineProperty(exports, "SwitchStatement", { + enumerable: true, + get: function () { + return _index.switchStatement; + } + }); + Object.defineProperty(exports, "SymbolTypeAnnotation", { + enumerable: true, + get: function () { + return _index.symbolTypeAnnotation; + } + }); + Object.defineProperty(exports, "TSAnyKeyword", { + enumerable: true, + get: function () { + return _index.tsAnyKeyword; + } + }); + Object.defineProperty(exports, "TSArrayType", { + enumerable: true, + get: function () { + return _index.tsArrayType; + } + }); + Object.defineProperty(exports, "TSAsExpression", { + enumerable: true, + get: function () { + return _index.tsAsExpression; + } + }); + Object.defineProperty(exports, "TSBigIntKeyword", { + enumerable: true, + get: function () { + return _index.tsBigIntKeyword; + } + }); + Object.defineProperty(exports, "TSBooleanKeyword", { + enumerable: true, + get: function () { + return _index.tsBooleanKeyword; + } + }); + Object.defineProperty(exports, "TSCallSignatureDeclaration", { + enumerable: true, + get: function () { + return _index.tsCallSignatureDeclaration; + } + }); + Object.defineProperty(exports, "TSConditionalType", { + enumerable: true, + get: function () { + return _index.tsConditionalType; + } + }); + Object.defineProperty(exports, "TSConstructSignatureDeclaration", { + enumerable: true, + get: function () { + return _index.tsConstructSignatureDeclaration; + } + }); + Object.defineProperty(exports, "TSConstructorType", { + enumerable: true, + get: function () { + return _index.tsConstructorType; + } + }); + Object.defineProperty(exports, "TSDeclareFunction", { + enumerable: true, + get: function () { + return _index.tsDeclareFunction; + } + }); + Object.defineProperty(exports, "TSDeclareMethod", { + enumerable: true, + get: function () { + return _index.tsDeclareMethod; + } + }); + Object.defineProperty(exports, "TSEnumDeclaration", { + enumerable: true, + get: function () { + return _index.tsEnumDeclaration; + } + }); + Object.defineProperty(exports, "TSEnumMember", { + enumerable: true, + get: function () { + return _index.tsEnumMember; + } + }); + Object.defineProperty(exports, "TSExportAssignment", { + enumerable: true, + get: function () { + return _index.tsExportAssignment; + } + }); + Object.defineProperty(exports, "TSExpressionWithTypeArguments", { + enumerable: true, + get: function () { + return _index.tsExpressionWithTypeArguments; + } + }); + Object.defineProperty(exports, "TSExternalModuleReference", { + enumerable: true, + get: function () { + return _index.tsExternalModuleReference; + } + }); + Object.defineProperty(exports, "TSFunctionType", { + enumerable: true, + get: function () { + return _index.tsFunctionType; + } + }); + Object.defineProperty(exports, "TSImportEqualsDeclaration", { + enumerable: true, + get: function () { + return _index.tsImportEqualsDeclaration; + } + }); + Object.defineProperty(exports, "TSImportType", { + enumerable: true, + get: function () { + return _index.tsImportType; + } + }); + Object.defineProperty(exports, "TSIndexSignature", { + enumerable: true, + get: function () { + return _index.tsIndexSignature; + } + }); + Object.defineProperty(exports, "TSIndexedAccessType", { + enumerable: true, + get: function () { + return _index.tsIndexedAccessType; + } + }); + Object.defineProperty(exports, "TSInferType", { + enumerable: true, + get: function () { + return _index.tsInferType; + } + }); + Object.defineProperty(exports, "TSInstantiationExpression", { + enumerable: true, + get: function () { + return _index.tsInstantiationExpression; + } + }); + Object.defineProperty(exports, "TSInterfaceBody", { + enumerable: true, + get: function () { + return _index.tsInterfaceBody; + } + }); + Object.defineProperty(exports, "TSInterfaceDeclaration", { + enumerable: true, + get: function () { + return _index.tsInterfaceDeclaration; + } + }); + Object.defineProperty(exports, "TSIntersectionType", { + enumerable: true, + get: function () { + return _index.tsIntersectionType; + } + }); + Object.defineProperty(exports, "TSIntrinsicKeyword", { + enumerable: true, + get: function () { + return _index.tsIntrinsicKeyword; + } + }); + Object.defineProperty(exports, "TSLiteralType", { + enumerable: true, + get: function () { + return _index.tsLiteralType; + } + }); + Object.defineProperty(exports, "TSMappedType", { + enumerable: true, + get: function () { + return _index.tsMappedType; + } + }); + Object.defineProperty(exports, "TSMethodSignature", { + enumerable: true, + get: function () { + return _index.tsMethodSignature; + } + }); + Object.defineProperty(exports, "TSModuleBlock", { + enumerable: true, + get: function () { + return _index.tsModuleBlock; + } + }); + Object.defineProperty(exports, "TSModuleDeclaration", { + enumerable: true, + get: function () { + return _index.tsModuleDeclaration; + } + }); + Object.defineProperty(exports, "TSNamedTupleMember", { + enumerable: true, + get: function () { + return _index.tsNamedTupleMember; + } + }); + Object.defineProperty(exports, "TSNamespaceExportDeclaration", { + enumerable: true, + get: function () { + return _index.tsNamespaceExportDeclaration; + } + }); + Object.defineProperty(exports, "TSNeverKeyword", { + enumerable: true, + get: function () { + return _index.tsNeverKeyword; + } + }); + Object.defineProperty(exports, "TSNonNullExpression", { + enumerable: true, + get: function () { + return _index.tsNonNullExpression; + } + }); + Object.defineProperty(exports, "TSNullKeyword", { + enumerable: true, + get: function () { + return _index.tsNullKeyword; + } + }); + Object.defineProperty(exports, "TSNumberKeyword", { + enumerable: true, + get: function () { + return _index.tsNumberKeyword; + } + }); + Object.defineProperty(exports, "TSObjectKeyword", { + enumerable: true, + get: function () { + return _index.tsObjectKeyword; + } + }); + Object.defineProperty(exports, "TSOptionalType", { + enumerable: true, + get: function () { + return _index.tsOptionalType; + } + }); + Object.defineProperty(exports, "TSParameterProperty", { + enumerable: true, + get: function () { + return _index.tsParameterProperty; + } + }); + Object.defineProperty(exports, "TSParenthesizedType", { + enumerable: true, + get: function () { + return _index.tsParenthesizedType; + } + }); + Object.defineProperty(exports, "TSPropertySignature", { + enumerable: true, + get: function () { + return _index.tsPropertySignature; + } + }); + Object.defineProperty(exports, "TSQualifiedName", { + enumerable: true, + get: function () { + return _index.tsQualifiedName; + } + }); + Object.defineProperty(exports, "TSRestType", { + enumerable: true, + get: function () { + return _index.tsRestType; + } + }); + Object.defineProperty(exports, "TSSatisfiesExpression", { + enumerable: true, + get: function () { + return _index.tsSatisfiesExpression; + } + }); + Object.defineProperty(exports, "TSStringKeyword", { + enumerable: true, + get: function () { + return _index.tsStringKeyword; + } + }); + Object.defineProperty(exports, "TSSymbolKeyword", { + enumerable: true, + get: function () { + return _index.tsSymbolKeyword; + } + }); + Object.defineProperty(exports, "TSThisType", { + enumerable: true, + get: function () { + return _index.tsThisType; + } + }); + Object.defineProperty(exports, "TSTupleType", { + enumerable: true, + get: function () { + return _index.tsTupleType; + } + }); + Object.defineProperty(exports, "TSTypeAliasDeclaration", { + enumerable: true, + get: function () { + return _index.tsTypeAliasDeclaration; + } + }); + Object.defineProperty(exports, "TSTypeAnnotation", { + enumerable: true, + get: function () { + return _index.tsTypeAnnotation; + } + }); + Object.defineProperty(exports, "TSTypeAssertion", { + enumerable: true, + get: function () { + return _index.tsTypeAssertion; + } + }); + Object.defineProperty(exports, "TSTypeLiteral", { + enumerable: true, + get: function () { + return _index.tsTypeLiteral; + } + }); + Object.defineProperty(exports, "TSTypeOperator", { + enumerable: true, + get: function () { + return _index.tsTypeOperator; + } + }); + Object.defineProperty(exports, "TSTypeParameter", { + enumerable: true, + get: function () { + return _index.tsTypeParameter; + } + }); + Object.defineProperty(exports, "TSTypeParameterDeclaration", { + enumerable: true, + get: function () { + return _index.tsTypeParameterDeclaration; + } + }); + Object.defineProperty(exports, "TSTypeParameterInstantiation", { + enumerable: true, + get: function () { + return _index.tsTypeParameterInstantiation; + } + }); + Object.defineProperty(exports, "TSTypePredicate", { + enumerable: true, + get: function () { + return _index.tsTypePredicate; + } + }); + Object.defineProperty(exports, "TSTypeQuery", { + enumerable: true, + get: function () { + return _index.tsTypeQuery; + } + }); + Object.defineProperty(exports, "TSTypeReference", { + enumerable: true, + get: function () { + return _index.tsTypeReference; + } + }); + Object.defineProperty(exports, "TSUndefinedKeyword", { + enumerable: true, + get: function () { + return _index.tsUndefinedKeyword; + } + }); + Object.defineProperty(exports, "TSUnionType", { + enumerable: true, + get: function () { + return _index.tsUnionType; + } + }); + Object.defineProperty(exports, "TSUnknownKeyword", { + enumerable: true, + get: function () { + return _index.tsUnknownKeyword; + } + }); + Object.defineProperty(exports, "TSVoidKeyword", { + enumerable: true, + get: function () { + return _index.tsVoidKeyword; + } + }); + Object.defineProperty(exports, "TaggedTemplateExpression", { + enumerable: true, + get: function () { + return _index.taggedTemplateExpression; + } + }); + Object.defineProperty(exports, "TemplateElement", { + enumerable: true, + get: function () { + return _index.templateElement; + } + }); + Object.defineProperty(exports, "TemplateLiteral", { + enumerable: true, + get: function () { + return _index.templateLiteral; + } + }); + Object.defineProperty(exports, "ThisExpression", { + enumerable: true, + get: function () { + return _index.thisExpression; + } + }); + Object.defineProperty(exports, "ThisTypeAnnotation", { + enumerable: true, + get: function () { + return _index.thisTypeAnnotation; + } + }); + Object.defineProperty(exports, "ThrowStatement", { + enumerable: true, + get: function () { + return _index.throwStatement; + } + }); + Object.defineProperty(exports, "TopicReference", { + enumerable: true, + get: function () { + return _index.topicReference; + } + }); + Object.defineProperty(exports, "TryStatement", { + enumerable: true, + get: function () { + return _index.tryStatement; + } + }); + Object.defineProperty(exports, "TupleExpression", { + enumerable: true, + get: function () { + return _index.tupleExpression; + } + }); + Object.defineProperty(exports, "TupleTypeAnnotation", { + enumerable: true, + get: function () { + return _index.tupleTypeAnnotation; + } + }); + Object.defineProperty(exports, "TypeAlias", { + enumerable: true, + get: function () { + return _index.typeAlias; + } + }); + Object.defineProperty(exports, "TypeAnnotation", { + enumerable: true, + get: function () { + return _index.typeAnnotation; + } + }); + Object.defineProperty(exports, "TypeCastExpression", { + enumerable: true, + get: function () { + return _index.typeCastExpression; + } + }); + Object.defineProperty(exports, "TypeParameter", { + enumerable: true, + get: function () { + return _index.typeParameter; + } + }); + Object.defineProperty(exports, "TypeParameterDeclaration", { + enumerable: true, + get: function () { + return _index.typeParameterDeclaration; + } + }); + Object.defineProperty(exports, "TypeParameterInstantiation", { + enumerable: true, + get: function () { + return _index.typeParameterInstantiation; + } + }); + Object.defineProperty(exports, "TypeofTypeAnnotation", { + enumerable: true, + get: function () { + return _index.typeofTypeAnnotation; + } + }); + Object.defineProperty(exports, "UnaryExpression", { + enumerable: true, + get: function () { + return _index.unaryExpression; + } + }); + Object.defineProperty(exports, "UnionTypeAnnotation", { + enumerable: true, + get: function () { + return _index.unionTypeAnnotation; + } + }); + Object.defineProperty(exports, "UpdateExpression", { + enumerable: true, + get: function () { + return _index.updateExpression; + } + }); + Object.defineProperty(exports, "V8IntrinsicIdentifier", { + enumerable: true, + get: function () { + return _index.v8IntrinsicIdentifier; + } + }); + Object.defineProperty(exports, "VariableDeclaration", { + enumerable: true, + get: function () { + return _index.variableDeclaration; + } + }); + Object.defineProperty(exports, "VariableDeclarator", { + enumerable: true, + get: function () { + return _index.variableDeclarator; + } + }); + Object.defineProperty(exports, "Variance", { + enumerable: true, + get: function () { + return _index.variance; + } + }); + Object.defineProperty(exports, "VoidTypeAnnotation", { + enumerable: true, + get: function () { + return _index.voidTypeAnnotation; + } + }); + Object.defineProperty(exports, "WhileStatement", { + enumerable: true, + get: function () { + return _index.whileStatement; + } + }); + Object.defineProperty(exports, "WithStatement", { + enumerable: true, + get: function () { + return _index.withStatement; + } + }); + Object.defineProperty(exports, "YieldExpression", { + enumerable: true, + get: function () { + return _index.yieldExpression; + } + }); + var _index = requireGenerated$2(); + + +} (uppercase)); + return uppercase; +} + +var productions = {}; + +var hasRequiredProductions; + +function requireProductions () { + if (hasRequiredProductions) return productions; + hasRequiredProductions = 1; + + Object.defineProperty(productions, "__esModule", { + value: true + }); + productions.buildUndefinedNode = buildUndefinedNode; + var _index = requireGenerated$2(); + function buildUndefinedNode() { + return (0, _index.unaryExpression)("void", (0, _index.numericLiteral)(0), true); + } + + + return productions; +} + +var cloneNode = {}; + +var hasRequiredCloneNode; + +function requireCloneNode () { + if (hasRequiredCloneNode) return cloneNode; + hasRequiredCloneNode = 1; + + Object.defineProperty(cloneNode, "__esModule", { + value: true + }); + cloneNode.default = cloneNode$1; + var _index = requireDefinitions(); + var _index2 = requireGenerated$3(); + const { + hasOwn + } = { + hasOwn: Function.call.bind(Object.prototype.hasOwnProperty) + }; + function cloneIfNode(obj, deep, withoutLoc, commentsCache) { + if (obj && typeof obj.type === "string") { + return cloneNodeInternal(obj, deep, withoutLoc, commentsCache); + } + return obj; + } + function cloneIfNodeOrArray(obj, deep, withoutLoc, commentsCache) { + if (Array.isArray(obj)) { + return obj.map(node => cloneIfNode(node, deep, withoutLoc, commentsCache)); + } + return cloneIfNode(obj, deep, withoutLoc, commentsCache); + } + function cloneNode$1(node, deep = true, withoutLoc = false) { + return cloneNodeInternal(node, deep, withoutLoc, new Map()); + } + function cloneNodeInternal(node, deep = true, withoutLoc = false, commentsCache) { + if (!node) return node; + const { + type + } = node; + const newNode = { + type: node.type + }; + if ((0, _index2.isIdentifier)(node)) { + newNode.name = node.name; + if (hasOwn(node, "optional") && typeof node.optional === "boolean") { + newNode.optional = node.optional; + } + if (hasOwn(node, "typeAnnotation")) { + newNode.typeAnnotation = deep ? cloneIfNodeOrArray(node.typeAnnotation, true, withoutLoc, commentsCache) : node.typeAnnotation; + } + if (hasOwn(node, "decorators")) { + newNode.decorators = deep ? cloneIfNodeOrArray(node.decorators, true, withoutLoc, commentsCache) : node.decorators; + } + } else if (!hasOwn(_index.NODE_FIELDS, type)) { + throw new Error(`Unknown node type: "${type}"`); + } else { + for (const field of Object.keys(_index.NODE_FIELDS[type])) { + if (hasOwn(node, field)) { + if (deep) { + newNode[field] = (0, _index2.isFile)(node) && field === "comments" ? maybeCloneComments(node.comments, deep, withoutLoc, commentsCache) : cloneIfNodeOrArray(node[field], true, withoutLoc, commentsCache); + } else { + newNode[field] = node[field]; + } + } + } + } + if (hasOwn(node, "loc")) { + if (withoutLoc) { + newNode.loc = null; + } else { + newNode.loc = node.loc; + } + } + if (hasOwn(node, "leadingComments")) { + newNode.leadingComments = maybeCloneComments(node.leadingComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "innerComments")) { + newNode.innerComments = maybeCloneComments(node.innerComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "trailingComments")) { + newNode.trailingComments = maybeCloneComments(node.trailingComments, deep, withoutLoc, commentsCache); + } + if (hasOwn(node, "extra")) { + newNode.extra = Object.assign({}, node.extra); + } + return newNode; + } + function maybeCloneComments(comments, deep, withoutLoc, commentsCache) { + if (!comments || !deep) { + return comments; + } + return comments.map(comment => { + const cache = commentsCache.get(comment); + if (cache) return cache; + const { + type, + value, + loc + } = comment; + const ret = { + type, + value, + loc + }; + if (withoutLoc) { + ret.loc = null; + } + commentsCache.set(comment, ret); + return ret; + }); + } + + + return cloneNode; +} + +var clone = {}; + +var hasRequiredClone; + +function requireClone () { + if (hasRequiredClone) return clone; + hasRequiredClone = 1; + + Object.defineProperty(clone, "__esModule", { + value: true + }); + clone.default = clone$1; + var _cloneNode = requireCloneNode(); + function clone$1(node) { + return (0, _cloneNode.default)(node, false); + } + + + return clone; +} + +var cloneDeep = {}; + +var hasRequiredCloneDeep; + +function requireCloneDeep () { + if (hasRequiredCloneDeep) return cloneDeep; + hasRequiredCloneDeep = 1; + + Object.defineProperty(cloneDeep, "__esModule", { + value: true + }); + cloneDeep.default = cloneDeep$1; + var _cloneNode = requireCloneNode(); + function cloneDeep$1(node) { + return (0, _cloneNode.default)(node); + } + + + return cloneDeep; +} + +var cloneDeepWithoutLoc = {}; + +var hasRequiredCloneDeepWithoutLoc; + +function requireCloneDeepWithoutLoc () { + if (hasRequiredCloneDeepWithoutLoc) return cloneDeepWithoutLoc; + hasRequiredCloneDeepWithoutLoc = 1; + + Object.defineProperty(cloneDeepWithoutLoc, "__esModule", { + value: true + }); + cloneDeepWithoutLoc.default = cloneDeepWithoutLoc$1; + var _cloneNode = requireCloneNode(); + function cloneDeepWithoutLoc$1(node) { + return (0, _cloneNode.default)(node, true, true); + } + + + return cloneDeepWithoutLoc; +} + +var cloneWithoutLoc = {}; + +var hasRequiredCloneWithoutLoc; + +function requireCloneWithoutLoc () { + if (hasRequiredCloneWithoutLoc) return cloneWithoutLoc; + hasRequiredCloneWithoutLoc = 1; + + Object.defineProperty(cloneWithoutLoc, "__esModule", { + value: true + }); + cloneWithoutLoc.default = cloneWithoutLoc$1; + var _cloneNode = requireCloneNode(); + function cloneWithoutLoc$1(node) { + return (0, _cloneNode.default)(node, false, true); + } + + + return cloneWithoutLoc; +} + +var addComment = {}; + +var addComments = {}; + +var hasRequiredAddComments; + +function requireAddComments () { + if (hasRequiredAddComments) return addComments; + hasRequiredAddComments = 1; + + Object.defineProperty(addComments, "__esModule", { + value: true + }); + addComments.default = addComments$1; + function addComments$1(node, type, comments) { + if (!comments || !node) return node; + const key = `${type}Comments`; + if (node[key]) { + if (type === "leading") { + node[key] = comments.concat(node[key]); + } else { + node[key].push(...comments); + } + } else { + node[key] = comments; + } + return node; + } + + + return addComments; +} + +var hasRequiredAddComment; + +function requireAddComment () { + if (hasRequiredAddComment) return addComment; + hasRequiredAddComment = 1; + + Object.defineProperty(addComment, "__esModule", { + value: true + }); + addComment.default = addComment$1; + var _addComments = requireAddComments(); + function addComment$1(node, type, content, line) { + return (0, _addComments.default)(node, type, [{ + type: line ? "CommentLine" : "CommentBlock", + value: content + }]); + } + + + return addComment; +} + +var inheritInnerComments = {}; + +var inherit = {}; + +var hasRequiredInherit; + +function requireInherit () { + if (hasRequiredInherit) return inherit; + hasRequiredInherit = 1; + + Object.defineProperty(inherit, "__esModule", { + value: true + }); + inherit.default = inherit$1; + function inherit$1(key, child, parent) { + if (child && parent) { + child[key] = Array.from(new Set([].concat(child[key], parent[key]).filter(Boolean))); + } + } + + + return inherit; +} + +var hasRequiredInheritInnerComments; + +function requireInheritInnerComments () { + if (hasRequiredInheritInnerComments) return inheritInnerComments; + hasRequiredInheritInnerComments = 1; + + Object.defineProperty(inheritInnerComments, "__esModule", { + value: true + }); + inheritInnerComments.default = inheritInnerComments$1; + var _inherit = requireInherit(); + function inheritInnerComments$1(child, parent) { + (0, _inherit.default)("innerComments", child, parent); + } + + + return inheritInnerComments; +} + +var inheritLeadingComments = {}; + +var hasRequiredInheritLeadingComments; + +function requireInheritLeadingComments () { + if (hasRequiredInheritLeadingComments) return inheritLeadingComments; + hasRequiredInheritLeadingComments = 1; + + Object.defineProperty(inheritLeadingComments, "__esModule", { + value: true + }); + inheritLeadingComments.default = inheritLeadingComments$1; + var _inherit = requireInherit(); + function inheritLeadingComments$1(child, parent) { + (0, _inherit.default)("leadingComments", child, parent); + } + + + return inheritLeadingComments; +} + +var inheritsComments = {}; + +var inheritTrailingComments = {}; + +var hasRequiredInheritTrailingComments; + +function requireInheritTrailingComments () { + if (hasRequiredInheritTrailingComments) return inheritTrailingComments; + hasRequiredInheritTrailingComments = 1; + + Object.defineProperty(inheritTrailingComments, "__esModule", { + value: true + }); + inheritTrailingComments.default = inheritTrailingComments$1; + var _inherit = requireInherit(); + function inheritTrailingComments$1(child, parent) { + (0, _inherit.default)("trailingComments", child, parent); + } + + + return inheritTrailingComments; +} + +var hasRequiredInheritsComments; + +function requireInheritsComments () { + if (hasRequiredInheritsComments) return inheritsComments; + hasRequiredInheritsComments = 1; + + Object.defineProperty(inheritsComments, "__esModule", { + value: true + }); + inheritsComments.default = inheritsComments$1; + var _inheritTrailingComments = requireInheritTrailingComments(); + var _inheritLeadingComments = requireInheritLeadingComments(); + var _inheritInnerComments = requireInheritInnerComments(); + function inheritsComments$1(child, parent) { + (0, _inheritTrailingComments.default)(child, parent); + (0, _inheritLeadingComments.default)(child, parent); + (0, _inheritInnerComments.default)(child, parent); + return child; + } + + + return inheritsComments; +} + +var removeComments = {}; + +var hasRequiredRemoveComments; + +function requireRemoveComments () { + if (hasRequiredRemoveComments) return removeComments; + hasRequiredRemoveComments = 1; + + Object.defineProperty(removeComments, "__esModule", { + value: true + }); + removeComments.default = removeComments$1; + var _index = requireConstants(); + function removeComments$1(node) { + _index.COMMENT_KEYS.forEach(key => { + node[key] = null; + }); + return node; + } + + + return removeComments; +} + +var generated = {}; + +var hasRequiredGenerated; + +function requireGenerated () { + if (hasRequiredGenerated) return generated; + hasRequiredGenerated = 1; + + Object.defineProperty(generated, "__esModule", { + value: true + }); + generated.WHILE_TYPES = generated.USERWHITESPACABLE_TYPES = generated.UNARYLIKE_TYPES = generated.TYPESCRIPT_TYPES = generated.TSTYPE_TYPES = generated.TSTYPEELEMENT_TYPES = generated.TSENTITYNAME_TYPES = generated.TSBASETYPE_TYPES = generated.TERMINATORLESS_TYPES = generated.STATEMENT_TYPES = generated.STANDARDIZED_TYPES = generated.SCOPABLE_TYPES = generated.PUREISH_TYPES = generated.PROPERTY_TYPES = generated.PRIVATE_TYPES = generated.PATTERN_TYPES = generated.PATTERNLIKE_TYPES = generated.OBJECTMEMBER_TYPES = generated.MODULESPECIFIER_TYPES = generated.MODULEDECLARATION_TYPES = generated.MISCELLANEOUS_TYPES = generated.METHOD_TYPES = generated.LVAL_TYPES = generated.LOOP_TYPES = generated.LITERAL_TYPES = generated.JSX_TYPES = generated.IMPORTOREXPORTDECLARATION_TYPES = generated.IMMUTABLE_TYPES = generated.FUNCTION_TYPES = generated.FUNCTIONPARENT_TYPES = generated.FOR_TYPES = generated.FORXSTATEMENT_TYPES = generated.FLOW_TYPES = generated.FLOWTYPE_TYPES = generated.FLOWPREDICATE_TYPES = generated.FLOWDECLARATION_TYPES = generated.FLOWBASEANNOTATION_TYPES = generated.EXPRESSION_TYPES = generated.EXPRESSIONWRAPPER_TYPES = generated.EXPORTDECLARATION_TYPES = generated.ENUMMEMBER_TYPES = generated.ENUMBODY_TYPES = generated.DECLARATION_TYPES = generated.CONDITIONAL_TYPES = generated.COMPLETIONSTATEMENT_TYPES = generated.CLASS_TYPES = generated.BLOCK_TYPES = generated.BLOCKPARENT_TYPES = generated.BINARY_TYPES = generated.ACCESSOR_TYPES = void 0; + var _index = requireDefinitions(); + generated.STANDARDIZED_TYPES = _index.FLIPPED_ALIAS_KEYS["Standardized"]; + generated.EXPRESSION_TYPES = _index.FLIPPED_ALIAS_KEYS["Expression"]; + generated.BINARY_TYPES = _index.FLIPPED_ALIAS_KEYS["Binary"]; + generated.SCOPABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["Scopable"]; + generated.BLOCKPARENT_TYPES = _index.FLIPPED_ALIAS_KEYS["BlockParent"]; + generated.BLOCK_TYPES = _index.FLIPPED_ALIAS_KEYS["Block"]; + generated.STATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["Statement"]; + generated.TERMINATORLESS_TYPES = _index.FLIPPED_ALIAS_KEYS["Terminatorless"]; + generated.COMPLETIONSTATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["CompletionStatement"]; + generated.CONDITIONAL_TYPES = _index.FLIPPED_ALIAS_KEYS["Conditional"]; + generated.LOOP_TYPES = _index.FLIPPED_ALIAS_KEYS["Loop"]; + generated.WHILE_TYPES = _index.FLIPPED_ALIAS_KEYS["While"]; + generated.EXPRESSIONWRAPPER_TYPES = _index.FLIPPED_ALIAS_KEYS["ExpressionWrapper"]; + generated.FOR_TYPES = _index.FLIPPED_ALIAS_KEYS["For"]; + generated.FORXSTATEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["ForXStatement"]; + generated.FUNCTION_TYPES = _index.FLIPPED_ALIAS_KEYS["Function"]; + generated.FUNCTIONPARENT_TYPES = _index.FLIPPED_ALIAS_KEYS["FunctionParent"]; + generated.PUREISH_TYPES = _index.FLIPPED_ALIAS_KEYS["Pureish"]; + generated.DECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["Declaration"]; + generated.PATTERNLIKE_TYPES = _index.FLIPPED_ALIAS_KEYS["PatternLike"]; + generated.LVAL_TYPES = _index.FLIPPED_ALIAS_KEYS["LVal"]; + generated.TSENTITYNAME_TYPES = _index.FLIPPED_ALIAS_KEYS["TSEntityName"]; + generated.LITERAL_TYPES = _index.FLIPPED_ALIAS_KEYS["Literal"]; + generated.IMMUTABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["Immutable"]; + generated.USERWHITESPACABLE_TYPES = _index.FLIPPED_ALIAS_KEYS["UserWhitespacable"]; + generated.METHOD_TYPES = _index.FLIPPED_ALIAS_KEYS["Method"]; + generated.OBJECTMEMBER_TYPES = _index.FLIPPED_ALIAS_KEYS["ObjectMember"]; + generated.PROPERTY_TYPES = _index.FLIPPED_ALIAS_KEYS["Property"]; + generated.UNARYLIKE_TYPES = _index.FLIPPED_ALIAS_KEYS["UnaryLike"]; + generated.PATTERN_TYPES = _index.FLIPPED_ALIAS_KEYS["Pattern"]; + generated.CLASS_TYPES = _index.FLIPPED_ALIAS_KEYS["Class"]; + const IMPORTOREXPORTDECLARATION_TYPES = generated.IMPORTOREXPORTDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["ImportOrExportDeclaration"]; + generated.EXPORTDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["ExportDeclaration"]; + generated.MODULESPECIFIER_TYPES = _index.FLIPPED_ALIAS_KEYS["ModuleSpecifier"]; + generated.ACCESSOR_TYPES = _index.FLIPPED_ALIAS_KEYS["Accessor"]; + generated.PRIVATE_TYPES = _index.FLIPPED_ALIAS_KEYS["Private"]; + generated.FLOW_TYPES = _index.FLIPPED_ALIAS_KEYS["Flow"]; + generated.FLOWTYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowType"]; + generated.FLOWBASEANNOTATION_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowBaseAnnotation"]; + generated.FLOWDECLARATION_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowDeclaration"]; + generated.FLOWPREDICATE_TYPES = _index.FLIPPED_ALIAS_KEYS["FlowPredicate"]; + generated.ENUMBODY_TYPES = _index.FLIPPED_ALIAS_KEYS["EnumBody"]; + generated.ENUMMEMBER_TYPES = _index.FLIPPED_ALIAS_KEYS["EnumMember"]; + generated.JSX_TYPES = _index.FLIPPED_ALIAS_KEYS["JSX"]; + generated.MISCELLANEOUS_TYPES = _index.FLIPPED_ALIAS_KEYS["Miscellaneous"]; + generated.TYPESCRIPT_TYPES = _index.FLIPPED_ALIAS_KEYS["TypeScript"]; + generated.TSTYPEELEMENT_TYPES = _index.FLIPPED_ALIAS_KEYS["TSTypeElement"]; + generated.TSTYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["TSType"]; + generated.TSBASETYPE_TYPES = _index.FLIPPED_ALIAS_KEYS["TSBaseType"]; + generated.MODULEDECLARATION_TYPES = IMPORTOREXPORTDECLARATION_TYPES; + + + return generated; +} + +var ensureBlock = {}; + +var toBlock = {}; + +var hasRequiredToBlock; + +function requireToBlock () { + if (hasRequiredToBlock) return toBlock; + hasRequiredToBlock = 1; + + Object.defineProperty(toBlock, "__esModule", { + value: true + }); + toBlock.default = toBlock$1; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + function toBlock$1(node, parent) { + if ((0, _index.isBlockStatement)(node)) { + return node; + } + let blockNodes = []; + if ((0, _index.isEmptyStatement)(node)) { + blockNodes = []; + } else { + if (!(0, _index.isStatement)(node)) { + if ((0, _index.isFunction)(parent)) { + node = (0, _index2.returnStatement)(node); + } else { + node = (0, _index2.expressionStatement)(node); + } + } + blockNodes = [node]; + } + return (0, _index2.blockStatement)(blockNodes); + } + + + return toBlock; +} + +var hasRequiredEnsureBlock; + +function requireEnsureBlock () { + if (hasRequiredEnsureBlock) return ensureBlock; + hasRequiredEnsureBlock = 1; + + Object.defineProperty(ensureBlock, "__esModule", { + value: true + }); + ensureBlock.default = ensureBlock$1; + var _toBlock = requireToBlock(); + function ensureBlock$1(node, key = "body") { + const result = (0, _toBlock.default)(node[key], node); + node[key] = result; + return result; + } + + + return ensureBlock; +} + +var toBindingIdentifierName = {}; + +var toIdentifier = {}; + +var hasRequiredToIdentifier; + +function requireToIdentifier () { + if (hasRequiredToIdentifier) return toIdentifier; + hasRequiredToIdentifier = 1; + + Object.defineProperty(toIdentifier, "__esModule", { + value: true + }); + toIdentifier.default = toIdentifier$1; + var _isValidIdentifier = requireIsValidIdentifier(); + var _helperValidatorIdentifier = requireLib$3(); + function toIdentifier$1(input) { + input = input + ""; + let name = ""; + for (const c of input) { + name += (0, _helperValidatorIdentifier.isIdentifierChar)(c.codePointAt(0)) ? c : "-"; + } + name = name.replace(/^[-0-9]+/, ""); + name = name.replace(/[-\s]+(.)?/g, function (match, c) { + return c ? c.toUpperCase() : ""; + }); + if (!(0, _isValidIdentifier.default)(name)) { + name = `_${name}`; + } + return name || "_"; + } + + + return toIdentifier; +} + +var hasRequiredToBindingIdentifierName; + +function requireToBindingIdentifierName () { + if (hasRequiredToBindingIdentifierName) return toBindingIdentifierName; + hasRequiredToBindingIdentifierName = 1; + + Object.defineProperty(toBindingIdentifierName, "__esModule", { + value: true + }); + toBindingIdentifierName.default = toBindingIdentifierName$1; + var _toIdentifier = requireToIdentifier(); + function toBindingIdentifierName$1(name) { + name = (0, _toIdentifier.default)(name); + if (name === "eval" || name === "arguments") name = "_" + name; + return name; + } + + + return toBindingIdentifierName; +} + +var toComputedKey = {}; + +var hasRequiredToComputedKey; + +function requireToComputedKey () { + if (hasRequiredToComputedKey) return toComputedKey; + hasRequiredToComputedKey = 1; + + Object.defineProperty(toComputedKey, "__esModule", { + value: true + }); + toComputedKey.default = toComputedKey$1; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + function toComputedKey$1(node, key = node.key || node.property) { + if (!node.computed && (0, _index.isIdentifier)(key)) key = (0, _index2.stringLiteral)(key.name); + return key; + } + + + return toComputedKey; +} + +var toExpression = {}; + +var hasRequiredToExpression; + +function requireToExpression () { + if (hasRequiredToExpression) return toExpression; + hasRequiredToExpression = 1; + + Object.defineProperty(toExpression, "__esModule", { + value: true + }); + toExpression.default = void 0; + var _index = requireGenerated$3(); + toExpression.default = toExpression$1; + function toExpression$1(node) { + if ((0, _index.isExpressionStatement)(node)) { + node = node.expression; + } + if ((0, _index.isExpression)(node)) { + return node; + } + if ((0, _index.isClass)(node)) { + node.type = "ClassExpression"; + } else if ((0, _index.isFunction)(node)) { + node.type = "FunctionExpression"; + } + if (!(0, _index.isExpression)(node)) { + throw new Error(`cannot turn ${node.type} to an expression`); + } + return node; + } + + + return toExpression; +} + +var toKeyAlias = {}; + +var removePropertiesDeep = {}; + +var traverseFast = {}; + +var hasRequiredTraverseFast; + +function requireTraverseFast () { + if (hasRequiredTraverseFast) return traverseFast; + hasRequiredTraverseFast = 1; + + Object.defineProperty(traverseFast, "__esModule", { + value: true + }); + traverseFast.default = traverseFast$1; + var _index = requireDefinitions(); + function traverseFast$1(node, enter, opts) { + if (!node) return; + const keys = _index.VISITOR_KEYS[node.type]; + if (!keys) return; + opts = opts || {}; + enter(node, opts); + for (const key of keys) { + const subNode = node[key]; + if (Array.isArray(subNode)) { + for (const node of subNode) { + traverseFast$1(node, enter, opts); + } + } else { + traverseFast$1(subNode, enter, opts); + } + } + } + + + return traverseFast; +} + +var removeProperties = {}; + +var hasRequiredRemoveProperties; + +function requireRemoveProperties () { + if (hasRequiredRemoveProperties) return removeProperties; + hasRequiredRemoveProperties = 1; + + Object.defineProperty(removeProperties, "__esModule", { + value: true + }); + removeProperties.default = removeProperties$1; + var _index = requireConstants(); + const CLEAR_KEYS = ["tokens", "start", "end", "loc", "raw", "rawValue"]; + const CLEAR_KEYS_PLUS_COMMENTS = [..._index.COMMENT_KEYS, "comments", ...CLEAR_KEYS]; + function removeProperties$1(node, opts = {}) { + const map = opts.preserveComments ? CLEAR_KEYS : CLEAR_KEYS_PLUS_COMMENTS; + for (const key of map) { + if (node[key] != null) node[key] = undefined; + } + for (const key of Object.keys(node)) { + if (key[0] === "_" && node[key] != null) node[key] = undefined; + } + const symbols = Object.getOwnPropertySymbols(node); + for (const sym of symbols) { + node[sym] = null; + } + } + + + return removeProperties; +} + +var hasRequiredRemovePropertiesDeep; + +function requireRemovePropertiesDeep () { + if (hasRequiredRemovePropertiesDeep) return removePropertiesDeep; + hasRequiredRemovePropertiesDeep = 1; + + Object.defineProperty(removePropertiesDeep, "__esModule", { + value: true + }); + removePropertiesDeep.default = removePropertiesDeep$1; + var _traverseFast = requireTraverseFast(); + var _removeProperties = requireRemoveProperties(); + function removePropertiesDeep$1(tree, opts) { + (0, _traverseFast.default)(tree, _removeProperties.default, opts); + return tree; + } + + + return removePropertiesDeep; +} + +var hasRequiredToKeyAlias; + +function requireToKeyAlias () { + if (hasRequiredToKeyAlias) return toKeyAlias; + hasRequiredToKeyAlias = 1; + + Object.defineProperty(toKeyAlias, "__esModule", { + value: true + }); + toKeyAlias.default = toKeyAlias$1; + var _index = requireGenerated$3(); + var _cloneNode = requireCloneNode(); + var _removePropertiesDeep = requireRemovePropertiesDeep(); + function toKeyAlias$1(node, key = node.key) { + let alias; + if (node.kind === "method") { + return toKeyAlias$1.increment() + ""; + } else if ((0, _index.isIdentifier)(key)) { + alias = key.name; + } else if ((0, _index.isStringLiteral)(key)) { + alias = JSON.stringify(key.value); + } else { + alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneNode.default)(key))); + } + if (node.computed) { + alias = `[${alias}]`; + } + if (node.static) { + alias = `static:${alias}`; + } + return alias; + } + toKeyAlias$1.uid = 0; + toKeyAlias$1.increment = function () { + if (toKeyAlias$1.uid >= Number.MAX_SAFE_INTEGER) { + return toKeyAlias$1.uid = 0; + } else { + return toKeyAlias$1.uid++; + } + }; + + + return toKeyAlias; +} + +var toStatement = {}; + +var hasRequiredToStatement; + +function requireToStatement () { + if (hasRequiredToStatement) return toStatement; + hasRequiredToStatement = 1; + + Object.defineProperty(toStatement, "__esModule", { + value: true + }); + toStatement.default = void 0; + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + toStatement.default = toStatement$1; + function toStatement$1(node, ignore) { + if ((0, _index.isStatement)(node)) { + return node; + } + let mustHaveId = false; + let newType; + if ((0, _index.isClass)(node)) { + mustHaveId = true; + newType = "ClassDeclaration"; + } else if ((0, _index.isFunction)(node)) { + mustHaveId = true; + newType = "FunctionDeclaration"; + } else if ((0, _index.isAssignmentExpression)(node)) { + return (0, _index2.expressionStatement)(node); + } + if (mustHaveId && !node.id) { + newType = false; + } + if (!newType) { + if (ignore) { + return false; + } else { + throw new Error(`cannot turn ${node.type} to a statement`); + } + } + node.type = newType; + return node; + } + + + return toStatement; +} + +var valueToNode = {}; + +var hasRequiredValueToNode; + +function requireValueToNode () { + if (hasRequiredValueToNode) return valueToNode; + hasRequiredValueToNode = 1; + + Object.defineProperty(valueToNode, "__esModule", { + value: true + }); + valueToNode.default = void 0; + var _isValidIdentifier = requireIsValidIdentifier(); + var _index = requireGenerated$2(); + valueToNode.default = valueToNode$1; + const objectToString = Function.call.bind(Object.prototype.toString); + function isRegExp(value) { + return objectToString(value) === "[object RegExp]"; + } + function isPlainObject(value) { + if (typeof value !== "object" || value === null || Object.prototype.toString.call(value) !== "[object Object]") { + return false; + } + const proto = Object.getPrototypeOf(value); + return proto === null || Object.getPrototypeOf(proto) === null; + } + function valueToNode$1(value) { + if (value === undefined) { + return (0, _index.identifier)("undefined"); + } + if (value === true || value === false) { + return (0, _index.booleanLiteral)(value); + } + if (value === null) { + return (0, _index.nullLiteral)(); + } + if (typeof value === "string") { + return (0, _index.stringLiteral)(value); + } + if (typeof value === "number") { + let result; + if (Number.isFinite(value)) { + result = (0, _index.numericLiteral)(Math.abs(value)); + } else { + let numerator; + if (Number.isNaN(value)) { + numerator = (0, _index.numericLiteral)(0); + } else { + numerator = (0, _index.numericLiteral)(1); + } + result = (0, _index.binaryExpression)("/", numerator, (0, _index.numericLiteral)(0)); + } + if (value < 0 || Object.is(value, -0)) { + result = (0, _index.unaryExpression)("-", result); + } + return result; + } + if (isRegExp(value)) { + const pattern = value.source; + const flags = /\/([a-z]*)$/.exec(value.toString())[1]; + return (0, _index.regExpLiteral)(pattern, flags); + } + if (Array.isArray(value)) { + return (0, _index.arrayExpression)(value.map(valueToNode$1)); + } + if (isPlainObject(value)) { + const props = []; + for (const key of Object.keys(value)) { + let nodeKey; + if ((0, _isValidIdentifier.default)(key)) { + nodeKey = (0, _index.identifier)(key); + } else { + nodeKey = (0, _index.stringLiteral)(key); + } + props.push((0, _index.objectProperty)(nodeKey, valueToNode$1(value[key]))); + } + return (0, _index.objectExpression)(props); + } + throw new Error("don't know how to turn this value into a node"); + } + + + return valueToNode; +} + +var appendToMemberExpression = {}; + +var hasRequiredAppendToMemberExpression; + +function requireAppendToMemberExpression () { + if (hasRequiredAppendToMemberExpression) return appendToMemberExpression; + hasRequiredAppendToMemberExpression = 1; + + Object.defineProperty(appendToMemberExpression, "__esModule", { + value: true + }); + appendToMemberExpression.default = appendToMemberExpression$1; + var _index = requireGenerated$2(); + function appendToMemberExpression$1(member, append, computed = false) { + member.object = (0, _index.memberExpression)(member.object, member.property, member.computed); + member.property = append; + member.computed = !!computed; + return member; + } + + + return appendToMemberExpression; +} + +var inherits = {}; + +var hasRequiredInherits; + +function requireInherits () { + if (hasRequiredInherits) return inherits; + hasRequiredInherits = 1; + + Object.defineProperty(inherits, "__esModule", { + value: true + }); + inherits.default = inherits$1; + var _index = requireConstants(); + var _inheritsComments = requireInheritsComments(); + function inherits$1(child, parent) { + if (!child || !parent) return child; + for (const key of _index.INHERIT_KEYS.optional) { + if (child[key] == null) { + child[key] = parent[key]; + } + } + for (const key of Object.keys(parent)) { + if (key[0] === "_" && key !== "__clone") { + child[key] = parent[key]; + } + } + for (const key of _index.INHERIT_KEYS.force) { + child[key] = parent[key]; + } + (0, _inheritsComments.default)(child, parent); + return child; + } + + + return inherits; +} + +var prependToMemberExpression = {}; + +var hasRequiredPrependToMemberExpression; + +function requirePrependToMemberExpression () { + if (hasRequiredPrependToMemberExpression) return prependToMemberExpression; + hasRequiredPrependToMemberExpression = 1; + + Object.defineProperty(prependToMemberExpression, "__esModule", { + value: true + }); + prependToMemberExpression.default = prependToMemberExpression$1; + var _index = requireGenerated$2(); + var _index2 = requireLib$1(); + function prependToMemberExpression$1(member, prepend) { + if ((0, _index2.isSuper)(member.object)) { + throw new Error("Cannot prepend node to super property access (`super.foo`)."); + } + member.object = (0, _index.memberExpression)(prepend, member.object); + return member; + } + + + return prependToMemberExpression; +} + +var getAssignmentIdentifiers = {}; + +var hasRequiredGetAssignmentIdentifiers; + +function requireGetAssignmentIdentifiers () { + if (hasRequiredGetAssignmentIdentifiers) return getAssignmentIdentifiers; + hasRequiredGetAssignmentIdentifiers = 1; + + Object.defineProperty(getAssignmentIdentifiers, "__esModule", { + value: true + }); + getAssignmentIdentifiers.default = getAssignmentIdentifiers$1; + function getAssignmentIdentifiers$1(node) { + const search = [].concat(node); + const ids = Object.create(null); + while (search.length) { + const id = search.pop(); + if (!id) continue; + switch (id.type) { + case "ArrayPattern": + search.push(...id.elements); + break; + case "AssignmentExpression": + case "AssignmentPattern": + case "ForInStatement": + case "ForOfStatement": + search.push(id.left); + break; + case "ObjectPattern": + search.push(...id.properties); + break; + case "ObjectProperty": + search.push(id.value); + break; + case "RestElement": + case "UpdateExpression": + search.push(id.argument); + break; + case "UnaryExpression": + if (id.operator === "delete") { + search.push(id.argument); + } + break; + case "Identifier": + ids[id.name] = id; + break; + } + } + return ids; + } + + + return getAssignmentIdentifiers; +} + +var getBindingIdentifiers = {}; + +var hasRequiredGetBindingIdentifiers; + +function requireGetBindingIdentifiers () { + if (hasRequiredGetBindingIdentifiers) return getBindingIdentifiers; + hasRequiredGetBindingIdentifiers = 1; + + Object.defineProperty(getBindingIdentifiers, "__esModule", { + value: true + }); + getBindingIdentifiers.default = getBindingIdentifiers$1; + var _index = requireGenerated$3(); + function getBindingIdentifiers$1(node, duplicates, outerOnly, newBindingsOnly) { + const search = [].concat(node); + const ids = Object.create(null); + while (search.length) { + const id = search.shift(); + if (!id) continue; + if (newBindingsOnly && ((0, _index.isAssignmentExpression)(id) || (0, _index.isUnaryExpression)(id) || (0, _index.isUpdateExpression)(id))) { + continue; + } + if ((0, _index.isIdentifier)(id)) { + if (duplicates) { + const _ids = ids[id.name] = ids[id.name] || []; + _ids.push(id); + } else { + ids[id.name] = id; + } + continue; + } + if ((0, _index.isExportDeclaration)(id) && !(0, _index.isExportAllDeclaration)(id)) { + if ((0, _index.isDeclaration)(id.declaration)) { + search.push(id.declaration); + } + continue; + } + if (outerOnly) { + if ((0, _index.isFunctionDeclaration)(id)) { + search.push(id.id); + continue; + } + if ((0, _index.isFunctionExpression)(id)) { + continue; + } + } + const keys = getBindingIdentifiers$1.keys[id.type]; + if (keys) { + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const nodes = id[key]; + if (nodes) { + if (Array.isArray(nodes)) { + search.push(...nodes); + } else { + search.push(nodes); + } + } + } + } + } + return ids; + } + const keys = { + DeclareClass: ["id"], + DeclareFunction: ["id"], + DeclareModule: ["id"], + DeclareVariable: ["id"], + DeclareInterface: ["id"], + DeclareTypeAlias: ["id"], + DeclareOpaqueType: ["id"], + InterfaceDeclaration: ["id"], + TypeAlias: ["id"], + OpaqueType: ["id"], + CatchClause: ["param"], + LabeledStatement: ["label"], + UnaryExpression: ["argument"], + AssignmentExpression: ["left"], + ImportSpecifier: ["local"], + ImportNamespaceSpecifier: ["local"], + ImportDefaultSpecifier: ["local"], + ImportDeclaration: ["specifiers"], + ExportSpecifier: ["exported"], + ExportNamespaceSpecifier: ["exported"], + ExportDefaultSpecifier: ["exported"], + FunctionDeclaration: ["id", "params"], + FunctionExpression: ["id", "params"], + ArrowFunctionExpression: ["params"], + ObjectMethod: ["params"], + ClassMethod: ["params"], + ClassPrivateMethod: ["params"], + ForInStatement: ["left"], + ForOfStatement: ["left"], + ClassDeclaration: ["id"], + ClassExpression: ["id"], + RestElement: ["argument"], + UpdateExpression: ["argument"], + ObjectProperty: ["value"], + AssignmentPattern: ["left"], + ArrayPattern: ["elements"], + ObjectPattern: ["properties"], + VariableDeclaration: ["declarations"], + VariableDeclarator: ["id"] + }; + getBindingIdentifiers$1.keys = keys; + + + return getBindingIdentifiers; +} + +var getOuterBindingIdentifiers = {}; + +var hasRequiredGetOuterBindingIdentifiers; + +function requireGetOuterBindingIdentifiers () { + if (hasRequiredGetOuterBindingIdentifiers) return getOuterBindingIdentifiers; + hasRequiredGetOuterBindingIdentifiers = 1; + + Object.defineProperty(getOuterBindingIdentifiers, "__esModule", { + value: true + }); + getOuterBindingIdentifiers.default = void 0; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + getOuterBindingIdentifiers.default = getOuterBindingIdentifiers$1; + function getOuterBindingIdentifiers$1(node, duplicates) { + return (0, _getBindingIdentifiers.default)(node, duplicates, true); + } + + + return getOuterBindingIdentifiers; +} + +var getFunctionName$3 = {}; + +var hasRequiredGetFunctionName; + +function requireGetFunctionName () { + if (hasRequiredGetFunctionName) return getFunctionName$3; + hasRequiredGetFunctionName = 1; + + Object.defineProperty(getFunctionName$3, "__esModule", { + value: true + }); + getFunctionName$3.default = getFunctionName; + var _index = requireGenerated$3(); + function getNameFromLiteralId(id) { + if ((0, _index.isNullLiteral)(id)) { + return "null"; + } + if ((0, _index.isRegExpLiteral)(id)) { + return `/${id.pattern}/${id.flags}`; + } + if ((0, _index.isTemplateLiteral)(id)) { + return id.quasis.map(quasi => quasi.value.raw).join(""); + } + if (id.value !== undefined) { + return String(id.value); + } + return null; + } + function getObjectMemberKey(node) { + if (!node.computed || (0, _index.isLiteral)(node.key)) { + return node.key; + } + } + function getFunctionName(node, parent) { + if ("id" in node && node.id) { + return { + name: node.id.name, + originalNode: node.id + }; + } + let prefix = ""; + let id; + if ((0, _index.isObjectProperty)(parent, { + value: node + })) { + id = getObjectMemberKey(parent); + } else if ((0, _index.isObjectMethod)(node) || (0, _index.isClassMethod)(node)) { + id = getObjectMemberKey(node); + if (node.kind === "get") prefix = "get ";else if (node.kind === "set") prefix = "set "; + } else if ((0, _index.isVariableDeclarator)(parent, { + init: node + })) { + id = parent.id; + } else if ((0, _index.isAssignmentExpression)(parent, { + operator: "=", + right: node + })) { + id = parent.left; + } + if (!id) return null; + const name = (0, _index.isLiteral)(id) ? getNameFromLiteralId(id) : (0, _index.isIdentifier)(id) ? id.name : (0, _index.isPrivateName)(id) ? id.id.name : null; + if (name == null) return null; + return { + name: prefix + name, + originalNode: id + }; + } + + + return getFunctionName$3; +} + +var traverse = {}; + +var hasRequiredTraverse; + +function requireTraverse () { + if (hasRequiredTraverse) return traverse; + hasRequiredTraverse = 1; + + Object.defineProperty(traverse, "__esModule", { + value: true + }); + traverse.default = traverse$1; + var _index = requireDefinitions(); + function traverse$1(node, handlers, state) { + if (typeof handlers === "function") { + handlers = { + enter: handlers + }; + } + const { + enter, + exit + } = handlers; + traverseSimpleImpl(node, enter, exit, state, []); + } + function traverseSimpleImpl(node, enter, exit, state, ancestors) { + const keys = _index.VISITOR_KEYS[node.type]; + if (!keys) return; + if (enter) enter(node, ancestors, state); + for (const key of keys) { + const subNode = node[key]; + if (Array.isArray(subNode)) { + for (let i = 0; i < subNode.length; i++) { + const child = subNode[i]; + if (!child) continue; + ancestors.push({ + node, + key, + index: i + }); + traverseSimpleImpl(child, enter, exit, state, ancestors); + ancestors.pop(); + } + } else if (subNode) { + ancestors.push({ + node, + key + }); + traverseSimpleImpl(subNode, enter, exit, state, ancestors); + ancestors.pop(); + } + } + if (exit) exit(node, ancestors, state); + } + + + return traverse; +} + +var isBinding = {}; + +var hasRequiredIsBinding; + +function requireIsBinding () { + if (hasRequiredIsBinding) return isBinding; + hasRequiredIsBinding = 1; + + Object.defineProperty(isBinding, "__esModule", { + value: true + }); + isBinding.default = isBinding$1; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + function isBinding$1(node, parent, grandparent) { + if (grandparent && node.type === "Identifier" && parent.type === "ObjectProperty" && grandparent.type === "ObjectExpression") { + return false; + } + const keys = _getBindingIdentifiers.default.keys[parent.type]; + if (keys) { + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const val = parent[key]; + if (Array.isArray(val)) { + if (val.includes(node)) return true; + } else { + if (val === node) return true; + } + } + } + return false; + } + + + return isBinding; +} + +var isBlockScoped = {}; + +var isLet = {}; + +var hasRequiredIsLet; + +function requireIsLet () { + if (hasRequiredIsLet) return isLet; + hasRequiredIsLet = 1; + + Object.defineProperty(isLet, "__esModule", { + value: true + }); + isLet.default = isLet$1; + var _index = requireGenerated$3(); + var _index2 = requireConstants(); + function isLet$1(node) { + return (0, _index.isVariableDeclaration)(node) && (node.kind !== "var" || node[_index2.BLOCK_SCOPED_SYMBOL]); + } + + + return isLet; +} + +var hasRequiredIsBlockScoped; + +function requireIsBlockScoped () { + if (hasRequiredIsBlockScoped) return isBlockScoped; + hasRequiredIsBlockScoped = 1; + + Object.defineProperty(isBlockScoped, "__esModule", { + value: true + }); + isBlockScoped.default = isBlockScoped$1; + var _index = requireGenerated$3(); + var _isLet = requireIsLet(); + function isBlockScoped$1(node) { + return (0, _index.isFunctionDeclaration)(node) || (0, _index.isClassDeclaration)(node) || (0, _isLet.default)(node); + } + + + return isBlockScoped; +} + +var isImmutable = {}; + +var hasRequiredIsImmutable; + +function requireIsImmutable () { + if (hasRequiredIsImmutable) return isImmutable; + hasRequiredIsImmutable = 1; + + Object.defineProperty(isImmutable, "__esModule", { + value: true + }); + isImmutable.default = isImmutable$1; + var _isType = requireIsType(); + var _index = requireGenerated$3(); + function isImmutable$1(node) { + if ((0, _isType.default)(node.type, "Immutable")) return true; + if ((0, _index.isIdentifier)(node)) { + if (node.name === "undefined") { + return true; + } else { + return false; + } + } + return false; + } + + + return isImmutable; +} + +var isNodesEquivalent = {}; + +var hasRequiredIsNodesEquivalent; + +function requireIsNodesEquivalent () { + if (hasRequiredIsNodesEquivalent) return isNodesEquivalent; + hasRequiredIsNodesEquivalent = 1; + + Object.defineProperty(isNodesEquivalent, "__esModule", { + value: true + }); + isNodesEquivalent.default = isNodesEquivalent$1; + var _index = requireDefinitions(); + function isNodesEquivalent$1(a, b) { + if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) { + return a === b; + } + if (a.type !== b.type) { + return false; + } + const fields = Object.keys(_index.NODE_FIELDS[a.type] || a.type); + const visitorKeys = _index.VISITOR_KEYS[a.type]; + for (const field of fields) { + const val_a = a[field]; + const val_b = b[field]; + if (typeof val_a !== typeof val_b) { + return false; + } + if (val_a == null && val_b == null) { + continue; + } else if (val_a == null || val_b == null) { + return false; + } + if (Array.isArray(val_a)) { + if (!Array.isArray(val_b)) { + return false; + } + if (val_a.length !== val_b.length) { + return false; + } + for (let i = 0; i < val_a.length; i++) { + if (!isNodesEquivalent$1(val_a[i], val_b[i])) { + return false; + } + } + continue; + } + if (typeof val_a === "object" && !(visitorKeys != null && visitorKeys.includes(field))) { + for (const key of Object.keys(val_a)) { + if (val_a[key] !== val_b[key]) { + return false; + } + } + continue; + } + if (!isNodesEquivalent$1(val_a, val_b)) { + return false; + } + } + return true; + } + + + return isNodesEquivalent; +} + +var isReferenced = {}; + +var hasRequiredIsReferenced; + +function requireIsReferenced () { + if (hasRequiredIsReferenced) return isReferenced; + hasRequiredIsReferenced = 1; + + Object.defineProperty(isReferenced, "__esModule", { + value: true + }); + isReferenced.default = isReferenced$1; + function isReferenced$1(node, parent, grandparent) { + switch (parent.type) { + case "MemberExpression": + case "OptionalMemberExpression": + if (parent.property === node) { + return !!parent.computed; + } + return parent.object === node; + case "JSXMemberExpression": + return parent.object === node; + case "VariableDeclarator": + return parent.init === node; + case "ArrowFunctionExpression": + return parent.body === node; + case "PrivateName": + return false; + case "ClassMethod": + case "ClassPrivateMethod": + case "ObjectMethod": + if (parent.key === node) { + return !!parent.computed; + } + return false; + case "ObjectProperty": + if (parent.key === node) { + return !!parent.computed; + } + return !grandparent || grandparent.type !== "ObjectPattern"; + case "ClassProperty": + case "ClassAccessorProperty": + if (parent.key === node) { + return !!parent.computed; + } + return true; + case "ClassPrivateProperty": + return parent.key !== node; + case "ClassDeclaration": + case "ClassExpression": + return parent.superClass === node; + case "AssignmentExpression": + return parent.right === node; + case "AssignmentPattern": + return parent.right === node; + case "LabeledStatement": + return false; + case "CatchClause": + return false; + case "RestElement": + return false; + case "BreakStatement": + case "ContinueStatement": + return false; + case "FunctionDeclaration": + case "FunctionExpression": + return false; + case "ExportNamespaceSpecifier": + case "ExportDefaultSpecifier": + return false; + case "ExportSpecifier": + if (grandparent != null && grandparent.source) { + return false; + } + return parent.local === node; + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "ImportSpecifier": + return false; + case "ImportAttribute": + return false; + case "JSXAttribute": + return false; + case "ObjectPattern": + case "ArrayPattern": + return false; + case "MetaProperty": + return false; + case "ObjectTypeProperty": + return parent.key !== node; + case "TSEnumMember": + return parent.id !== node; + case "TSPropertySignature": + if (parent.key === node) { + return !!parent.computed; + } + return true; + } + return true; + } + + + return isReferenced; +} + +var isScope = {}; + +var hasRequiredIsScope; + +function requireIsScope () { + if (hasRequiredIsScope) return isScope; + hasRequiredIsScope = 1; + + Object.defineProperty(isScope, "__esModule", { + value: true + }); + isScope.default = isScope$1; + var _index = requireGenerated$3(); + function isScope$1(node, parent) { + if ((0, _index.isBlockStatement)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) { + return false; + } + if ((0, _index.isPattern)(node) && ((0, _index.isFunction)(parent) || (0, _index.isCatchClause)(parent))) { + return true; + } + return (0, _index.isScopable)(node); + } + + + return isScope; +} + +var isSpecifierDefault = {}; + +var hasRequiredIsSpecifierDefault; + +function requireIsSpecifierDefault () { + if (hasRequiredIsSpecifierDefault) return isSpecifierDefault; + hasRequiredIsSpecifierDefault = 1; + + Object.defineProperty(isSpecifierDefault, "__esModule", { + value: true + }); + isSpecifierDefault.default = isSpecifierDefault$1; + var _index = requireGenerated$3(); + function isSpecifierDefault$1(specifier) { + return (0, _index.isImportDefaultSpecifier)(specifier) || (0, _index.isIdentifier)(specifier.imported || specifier.exported, { + name: "default" + }); + } + + + return isSpecifierDefault; +} + +var isValidES3Identifier = {}; + +var hasRequiredIsValidES3Identifier; + +function requireIsValidES3Identifier () { + if (hasRequiredIsValidES3Identifier) return isValidES3Identifier; + hasRequiredIsValidES3Identifier = 1; + + Object.defineProperty(isValidES3Identifier, "__esModule", { + value: true + }); + isValidES3Identifier.default = isValidES3Identifier$1; + var _isValidIdentifier = requireIsValidIdentifier(); + const RESERVED_WORDS_ES3_ONLY = new Set(["abstract", "boolean", "byte", "char", "double", "enum", "final", "float", "goto", "implements", "int", "interface", "long", "native", "package", "private", "protected", "public", "short", "static", "synchronized", "throws", "transient", "volatile"]); + function isValidES3Identifier$1(name) { + return (0, _isValidIdentifier.default)(name) && !RESERVED_WORDS_ES3_ONLY.has(name); + } + + + return isValidES3Identifier; +} + +var isVar = {}; + +var hasRequiredIsVar; + +function requireIsVar () { + if (hasRequiredIsVar) return isVar; + hasRequiredIsVar = 1; + + Object.defineProperty(isVar, "__esModule", { + value: true + }); + isVar.default = isVar$1; + var _index = requireGenerated$3(); + var _index2 = requireConstants(); + function isVar$1(node) { + return (0, _index.isVariableDeclaration)(node, { + kind: "var" + }) && !node[_index2.BLOCK_SCOPED_SYMBOL]; + } + + + return isVar; +} + +var toSequenceExpression = {}; + +var gatherSequenceExpressions = {}; + +var hasRequiredGatherSequenceExpressions; + +function requireGatherSequenceExpressions () { + if (hasRequiredGatherSequenceExpressions) return gatherSequenceExpressions; + hasRequiredGatherSequenceExpressions = 1; + + Object.defineProperty(gatherSequenceExpressions, "__esModule", { + value: true + }); + gatherSequenceExpressions.default = gatherSequenceExpressions$1; + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + var _index = requireGenerated$3(); + var _index2 = requireGenerated$2(); + var _productions = requireProductions(); + var _cloneNode = requireCloneNode(); + function gatherSequenceExpressions$1(nodes, declars) { + const exprs = []; + let ensureLastUndefined = true; + for (const node of nodes) { + if (!(0, _index.isEmptyStatement)(node)) { + ensureLastUndefined = false; + } + if ((0, _index.isExpression)(node)) { + exprs.push(node); + } else if ((0, _index.isExpressionStatement)(node)) { + exprs.push(node.expression); + } else if ((0, _index.isVariableDeclaration)(node)) { + if (node.kind !== "var") return; + for (const declar of node.declarations) { + const bindings = (0, _getBindingIdentifiers.default)(declar); + for (const key of Object.keys(bindings)) { + declars.push({ + kind: node.kind, + id: (0, _cloneNode.default)(bindings[key]) + }); + } + if (declar.init) { + exprs.push((0, _index2.assignmentExpression)("=", declar.id, declar.init)); + } + } + ensureLastUndefined = true; + } else if ((0, _index.isIfStatement)(node)) { + const consequent = node.consequent ? gatherSequenceExpressions$1([node.consequent], declars) : (0, _productions.buildUndefinedNode)(); + const alternate = node.alternate ? gatherSequenceExpressions$1([node.alternate], declars) : (0, _productions.buildUndefinedNode)(); + if (!consequent || !alternate) return; + exprs.push((0, _index2.conditionalExpression)(node.test, consequent, alternate)); + } else if ((0, _index.isBlockStatement)(node)) { + const body = gatherSequenceExpressions$1(node.body, declars); + if (!body) return; + exprs.push(body); + } else if ((0, _index.isEmptyStatement)(node)) { + if (nodes.indexOf(node) === 0) { + ensureLastUndefined = true; + } + } else { + return; + } + } + if (ensureLastUndefined) { + exprs.push((0, _productions.buildUndefinedNode)()); + } + if (exprs.length === 1) { + return exprs[0]; + } else { + return (0, _index2.sequenceExpression)(exprs); + } + } + + + return gatherSequenceExpressions; +} + +var hasRequiredToSequenceExpression; + +function requireToSequenceExpression () { + if (hasRequiredToSequenceExpression) return toSequenceExpression; + hasRequiredToSequenceExpression = 1; + + Object.defineProperty(toSequenceExpression, "__esModule", { + value: true + }); + toSequenceExpression.default = toSequenceExpression$1; + var _gatherSequenceExpressions = requireGatherSequenceExpressions(); + function toSequenceExpression$1(nodes, scope) { + if (!(nodes != null && nodes.length)) return; + const declars = []; + const result = (0, _gatherSequenceExpressions.default)(nodes, declars); + if (!result) return; + for (const declar of declars) { + scope.push(declar); + } + return result; + } + + + return toSequenceExpression; +} + +var hasRequiredLib$1; + +function requireLib$1 () { + if (hasRequiredLib$1) return lib$3; + hasRequiredLib$1 = 1; + (function (exports) { + + Object.defineProperty(exports, "__esModule", { + value: true + }); + var _exportNames = { + react: true, + assertNode: true, + createTypeAnnotationBasedOnTypeof: true, + createUnionTypeAnnotation: true, + createFlowUnionType: true, + createTSUnionType: true, + cloneNode: true, + clone: true, + cloneDeep: true, + cloneDeepWithoutLoc: true, + cloneWithoutLoc: true, + addComment: true, + addComments: true, + inheritInnerComments: true, + inheritLeadingComments: true, + inheritsComments: true, + inheritTrailingComments: true, + removeComments: true, + ensureBlock: true, + toBindingIdentifierName: true, + toBlock: true, + toComputedKey: true, + toExpression: true, + toIdentifier: true, + toKeyAlias: true, + toStatement: true, + valueToNode: true, + appendToMemberExpression: true, + inherits: true, + prependToMemberExpression: true, + removeProperties: true, + removePropertiesDeep: true, + removeTypeDuplicates: true, + getAssignmentIdentifiers: true, + getBindingIdentifiers: true, + getOuterBindingIdentifiers: true, + getFunctionName: true, + traverse: true, + traverseFast: true, + shallowEqual: true, + is: true, + isBinding: true, + isBlockScoped: true, + isImmutable: true, + isLet: true, + isNode: true, + isNodesEquivalent: true, + isPlaceholderType: true, + isReferenced: true, + isScope: true, + isSpecifierDefault: true, + isType: true, + isValidES3Identifier: true, + isValidIdentifier: true, + isVar: true, + matchesPattern: true, + validate: true, + buildMatchMemberExpression: true, + __internal__deprecationWarning: true + }; + Object.defineProperty(exports, "__internal__deprecationWarning", { + enumerable: true, + get: function () { + return _deprecationWarning.default; + } + }); + Object.defineProperty(exports, "addComment", { + enumerable: true, + get: function () { + return _addComment.default; + } + }); + Object.defineProperty(exports, "addComments", { + enumerable: true, + get: function () { + return _addComments.default; + } + }); + Object.defineProperty(exports, "appendToMemberExpression", { + enumerable: true, + get: function () { + return _appendToMemberExpression.default; + } + }); + Object.defineProperty(exports, "assertNode", { + enumerable: true, + get: function () { + return _assertNode.default; + } + }); + Object.defineProperty(exports, "buildMatchMemberExpression", { + enumerable: true, + get: function () { + return _buildMatchMemberExpression.default; + } + }); + Object.defineProperty(exports, "clone", { + enumerable: true, + get: function () { + return _clone.default; + } + }); + Object.defineProperty(exports, "cloneDeep", { + enumerable: true, + get: function () { + return _cloneDeep.default; + } + }); + Object.defineProperty(exports, "cloneDeepWithoutLoc", { + enumerable: true, + get: function () { + return _cloneDeepWithoutLoc.default; + } + }); + Object.defineProperty(exports, "cloneNode", { + enumerable: true, + get: function () { + return _cloneNode.default; + } + }); + Object.defineProperty(exports, "cloneWithoutLoc", { + enumerable: true, + get: function () { + return _cloneWithoutLoc.default; + } + }); + Object.defineProperty(exports, "createFlowUnionType", { + enumerable: true, + get: function () { + return _createFlowUnionType.default; + } + }); + Object.defineProperty(exports, "createTSUnionType", { + enumerable: true, + get: function () { + return _createTSUnionType.default; + } + }); + Object.defineProperty(exports, "createTypeAnnotationBasedOnTypeof", { + enumerable: true, + get: function () { + return _createTypeAnnotationBasedOnTypeof.default; + } + }); + Object.defineProperty(exports, "createUnionTypeAnnotation", { + enumerable: true, + get: function () { + return _createFlowUnionType.default; + } + }); + Object.defineProperty(exports, "ensureBlock", { + enumerable: true, + get: function () { + return _ensureBlock.default; + } + }); + Object.defineProperty(exports, "getAssignmentIdentifiers", { + enumerable: true, + get: function () { + return _getAssignmentIdentifiers.default; + } + }); + Object.defineProperty(exports, "getBindingIdentifiers", { + enumerable: true, + get: function () { + return _getBindingIdentifiers.default; + } + }); + Object.defineProperty(exports, "getFunctionName", { + enumerable: true, + get: function () { + return _getFunctionName.default; + } + }); + Object.defineProperty(exports, "getOuterBindingIdentifiers", { + enumerable: true, + get: function () { + return _getOuterBindingIdentifiers.default; + } + }); + Object.defineProperty(exports, "inheritInnerComments", { + enumerable: true, + get: function () { + return _inheritInnerComments.default; + } + }); + Object.defineProperty(exports, "inheritLeadingComments", { + enumerable: true, + get: function () { + return _inheritLeadingComments.default; + } + }); + Object.defineProperty(exports, "inheritTrailingComments", { + enumerable: true, + get: function () { + return _inheritTrailingComments.default; + } + }); + Object.defineProperty(exports, "inherits", { + enumerable: true, + get: function () { + return _inherits.default; + } + }); + Object.defineProperty(exports, "inheritsComments", { + enumerable: true, + get: function () { + return _inheritsComments.default; + } + }); + Object.defineProperty(exports, "is", { + enumerable: true, + get: function () { + return _is.default; + } + }); + Object.defineProperty(exports, "isBinding", { + enumerable: true, + get: function () { + return _isBinding.default; + } + }); + Object.defineProperty(exports, "isBlockScoped", { + enumerable: true, + get: function () { + return _isBlockScoped.default; + } + }); + Object.defineProperty(exports, "isImmutable", { + enumerable: true, + get: function () { + return _isImmutable.default; + } + }); + Object.defineProperty(exports, "isLet", { + enumerable: true, + get: function () { + return _isLet.default; + } + }); + Object.defineProperty(exports, "isNode", { + enumerable: true, + get: function () { + return _isNode.default; + } + }); + Object.defineProperty(exports, "isNodesEquivalent", { + enumerable: true, + get: function () { + return _isNodesEquivalent.default; + } + }); + Object.defineProperty(exports, "isPlaceholderType", { + enumerable: true, + get: function () { + return _isPlaceholderType.default; + } + }); + Object.defineProperty(exports, "isReferenced", { + enumerable: true, + get: function () { + return _isReferenced.default; + } + }); + Object.defineProperty(exports, "isScope", { + enumerable: true, + get: function () { + return _isScope.default; + } + }); + Object.defineProperty(exports, "isSpecifierDefault", { + enumerable: true, + get: function () { + return _isSpecifierDefault.default; + } + }); + Object.defineProperty(exports, "isType", { + enumerable: true, + get: function () { + return _isType.default; + } + }); + Object.defineProperty(exports, "isValidES3Identifier", { + enumerable: true, + get: function () { + return _isValidES3Identifier.default; + } + }); + Object.defineProperty(exports, "isValidIdentifier", { + enumerable: true, + get: function () { + return _isValidIdentifier.default; + } + }); + Object.defineProperty(exports, "isVar", { + enumerable: true, + get: function () { + return _isVar.default; + } + }); + Object.defineProperty(exports, "matchesPattern", { + enumerable: true, + get: function () { + return _matchesPattern.default; + } + }); + Object.defineProperty(exports, "prependToMemberExpression", { + enumerable: true, + get: function () { + return _prependToMemberExpression.default; + } + }); + exports.react = void 0; + Object.defineProperty(exports, "removeComments", { + enumerable: true, + get: function () { + return _removeComments.default; + } + }); + Object.defineProperty(exports, "removeProperties", { + enumerable: true, + get: function () { + return _removeProperties.default; + } + }); + Object.defineProperty(exports, "removePropertiesDeep", { + enumerable: true, + get: function () { + return _removePropertiesDeep.default; + } + }); + Object.defineProperty(exports, "removeTypeDuplicates", { + enumerable: true, + get: function () { + return _removeTypeDuplicates.default; + } + }); + Object.defineProperty(exports, "shallowEqual", { + enumerable: true, + get: function () { + return _shallowEqual.default; + } + }); + Object.defineProperty(exports, "toBindingIdentifierName", { + enumerable: true, + get: function () { + return _toBindingIdentifierName.default; + } + }); + Object.defineProperty(exports, "toBlock", { + enumerable: true, + get: function () { + return _toBlock.default; + } + }); + Object.defineProperty(exports, "toComputedKey", { + enumerable: true, + get: function () { + return _toComputedKey.default; + } + }); + Object.defineProperty(exports, "toExpression", { + enumerable: true, + get: function () { + return _toExpression.default; + } + }); + Object.defineProperty(exports, "toIdentifier", { + enumerable: true, + get: function () { + return _toIdentifier.default; + } + }); + Object.defineProperty(exports, "toKeyAlias", { + enumerable: true, + get: function () { + return _toKeyAlias.default; + } + }); + Object.defineProperty(exports, "toStatement", { + enumerable: true, + get: function () { + return _toStatement.default; + } + }); + Object.defineProperty(exports, "traverse", { + enumerable: true, + get: function () { + return _traverse.default; + } + }); + Object.defineProperty(exports, "traverseFast", { + enumerable: true, + get: function () { + return _traverseFast.default; + } + }); + Object.defineProperty(exports, "validate", { + enumerable: true, + get: function () { + return _validate.default; + } + }); + Object.defineProperty(exports, "valueToNode", { + enumerable: true, + get: function () { + return _valueToNode.default; + } + }); + var _isReactComponent = requireIsReactComponent(); + var _isCompatTag = requireIsCompatTag(); + var _buildChildren = requireBuildChildren(); + var _assertNode = requireAssertNode(); + var _index = requireGenerated$1(); + Object.keys(_index).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index[key]; + } + }); + }); + var _createTypeAnnotationBasedOnTypeof = requireCreateTypeAnnotationBasedOnTypeof(); + var _createFlowUnionType = requireCreateFlowUnionType(); + var _createTSUnionType = requireCreateTSUnionType(); + var _index2 = requireGenerated$2(); + Object.keys(_index2).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index2[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index2[key]; + } + }); + }); + var _uppercase = requireUppercase(); + Object.keys(_uppercase).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _uppercase[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _uppercase[key]; + } + }); + }); + var _productions = requireProductions(); + Object.keys(_productions).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _productions[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _productions[key]; + } + }); + }); + var _cloneNode = requireCloneNode(); + var _clone = requireClone(); + var _cloneDeep = requireCloneDeep(); + var _cloneDeepWithoutLoc = requireCloneDeepWithoutLoc(); + var _cloneWithoutLoc = requireCloneWithoutLoc(); + var _addComment = requireAddComment(); + var _addComments = requireAddComments(); + var _inheritInnerComments = requireInheritInnerComments(); + var _inheritLeadingComments = requireInheritLeadingComments(); + var _inheritsComments = requireInheritsComments(); + var _inheritTrailingComments = requireInheritTrailingComments(); + var _removeComments = requireRemoveComments(); + var _index3 = requireGenerated(); + Object.keys(_index3).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index3[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index3[key]; + } + }); + }); + var _index4 = requireConstants(); + Object.keys(_index4).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index4[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index4[key]; + } + }); + }); + var _ensureBlock = requireEnsureBlock(); + var _toBindingIdentifierName = requireToBindingIdentifierName(); + var _toBlock = requireToBlock(); + var _toComputedKey = requireToComputedKey(); + var _toExpression = requireToExpression(); + var _toIdentifier = requireToIdentifier(); + var _toKeyAlias = requireToKeyAlias(); + var _toStatement = requireToStatement(); + var _valueToNode = requireValueToNode(); + var _index5 = requireDefinitions(); + Object.keys(_index5).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index5[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index5[key]; + } + }); + }); + var _appendToMemberExpression = requireAppendToMemberExpression(); + var _inherits = requireInherits(); + var _prependToMemberExpression = requirePrependToMemberExpression(); + var _removeProperties = requireRemoveProperties(); + var _removePropertiesDeep = requireRemovePropertiesDeep(); + var _removeTypeDuplicates = requireRemoveTypeDuplicates$1(); + var _getAssignmentIdentifiers = requireGetAssignmentIdentifiers(); + var _getBindingIdentifiers = requireGetBindingIdentifiers(); + var _getOuterBindingIdentifiers = requireGetOuterBindingIdentifiers(); + var _getFunctionName = requireGetFunctionName(); + var _traverse = requireTraverse(); + Object.keys(_traverse).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _traverse[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _traverse[key]; + } + }); + }); + var _traverseFast = requireTraverseFast(); + var _shallowEqual = requireShallowEqual(); + var _is = requireIs(); + var _isBinding = requireIsBinding(); + var _isBlockScoped = requireIsBlockScoped(); + var _isImmutable = requireIsImmutable(); + var _isLet = requireIsLet(); + var _isNode = requireIsNode(); + var _isNodesEquivalent = requireIsNodesEquivalent(); + var _isPlaceholderType = requireIsPlaceholderType(); + var _isReferenced = requireIsReferenced(); + var _isScope = requireIsScope(); + var _isSpecifierDefault = requireIsSpecifierDefault(); + var _isType = requireIsType(); + var _isValidES3Identifier = requireIsValidES3Identifier(); + var _isValidIdentifier = requireIsValidIdentifier(); + var _isVar = requireIsVar(); + var _matchesPattern = requireMatchesPattern(); + var _validate = requireValidate(); + var _buildMatchMemberExpression = requireBuildMatchMemberExpression(); + var _index6 = requireGenerated$3(); + Object.keys(_index6).forEach(function (key) { + if (key === "default" || key === "__esModule") return; + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; + if (key in exports && exports[key] === _index6[key]) return; + Object.defineProperty(exports, key, { + enumerable: true, + get: function () { + return _index6[key]; + } + }); + }); + var _deprecationWarning = requireDeprecationWarning(); + exports.react = { + isReactComponent: _isReactComponent.default, + isCompatTag: _isCompatTag.default, + buildChildren: _buildChildren.default + }; + { + exports.toSequenceExpression = requireToSequenceExpression().default; + } + if (process.env.BABEL_TYPES_8_BREAKING) { + console.warn("BABEL_TYPES_8_BREAKING is not supported anymore. Use the latest Babel 8.0.0 pre-release instead!"); + } + + +} (lib$3)); + return lib$3; +} + +var libExports$1 = requireLib$1(); + +function Ok(val) { + return new OkImpl(val); +} +class OkImpl { + constructor(val) { + this.val = val; + } + map(fn) { + return new OkImpl(fn(this.val)); + } + mapErr(_fn) { + return this; + } + mapOr(_fallback, fn) { + return fn(this.val); + } + mapOrElse(_fallback, fn) { + return fn(this.val); + } + andThen(fn) { + return fn(this.val); + } + and(res) { + return res; + } + or(_res) { + return this; + } + orElse(_fn) { + return this; + } + isOk() { + return true; + } + isErr() { + return false; + } + expect(_msg) { + return this.val; + } + expectErr(msg) { + throw new Error(`${msg}: ${this.val}`); + } + unwrap() { + return this.val; + } + unwrapOr(_fallback) { + return this.val; + } + unwrapOrElse(_fallback) { + return this.val; + } + unwrapErr() { + if (this.val instanceof Error) { + throw this.val; + } + throw new Error(`Can't unwrap \`Ok\` to \`Err\`: ${this.val}`); + } +} +function Err(val) { + return new ErrImpl(val); +} +class ErrImpl { + constructor(val) { + this.val = val; + } + map(_fn) { + return this; + } + mapErr(fn) { + return new ErrImpl(fn(this.val)); + } + mapOr(fallback, _fn) { + return fallback; + } + mapOrElse(fallback, _fn) { + return fallback(); + } + andThen(_fn) { + return this; + } + and(_res) { + return this; + } + or(res) { + return res; + } + orElse(fn) { + return fn(this.val); + } + isOk() { + return false; + } + isErr() { + return true; + } + expect(msg) { + throw new Error(`${msg}: ${this.val}`); + } + expectErr(_msg) { + return this.val; + } + unwrap() { + if (this.val instanceof Error) { + throw this.val; + } + throw new Error(`Can't unwrap \`Err\` to \`Ok\`: ${this.val}`); + } + unwrapOr(fallback) { + return fallback; + } + unwrapOrElse(fallback) { + return fallback(this.val); + } + unwrapErr() { + return this.val; + } +} + +function assertExhaustive$1(_, errorMsg) { + throw new Error(errorMsg); +} +function retainWhere(array, predicate) { + let writeIndex = 0; + for (let readIndex = 0; readIndex < array.length; readIndex++) { + const item = array[readIndex]; + if (predicate(item) === true) { + array[writeIndex++] = item; + } + } + array.length = writeIndex; +} +function retainWhere_Set(items, predicate) { + for (const item of items) { + if (!predicate(item)) { + items.delete(item); + } + } +} +function getOrInsertWith(m, key, makeDefault) { + if (m.has(key)) { + return m.get(key); + } + else { + const defaultValue = makeDefault(); + m.set(key, defaultValue); + return defaultValue; + } +} +function getOrInsertDefault(m, key, defaultValue) { + if (m.has(key)) { + return m.get(key); + } + else { + m.set(key, defaultValue); + return defaultValue; + } +} +function Set_equal(a, b) { + if (a.size !== b.size) { + return false; + } + for (const item of a) { + if (!b.has(item)) { + return false; + } + } + return true; +} +function Set_union(a, b) { + const union = new Set(a); + for (const item of b) { + union.add(item); + } + return union; +} +function Set_intersect(sets) { + if (sets.length === 0 || sets.some(s => s.size === 0)) { + return new Set(); + } + else if (sets.length === 1) { + return new Set(sets[0]); + } + const result = new Set(); + const first = sets[0]; + outer: for (const e of first) { + for (let i = 1; i < sets.length; i++) { + if (!sets[i].has(e)) { + continue outer; + } + } + result.add(e); + } + return result; +} +function Iterable_some(iter, pred) { + for (const item of iter) { + if (pred(item)) { + return true; + } + } + return false; +} +function Set_filter(source, fn) { + const result = new Set(); + for (const entry of source) { + if (fn(entry)) { + result.add(entry); + } + } + return result; +} +function hasNode(input) { + return input.node != null; +} +function hasOwnProperty$1(obj, key) { + return Object.prototype.hasOwnProperty.call(obj, key); +} + +var ErrorSeverity; +(function (ErrorSeverity) { + ErrorSeverity["InvalidJS"] = "InvalidJS"; + ErrorSeverity["InvalidReact"] = "InvalidReact"; + ErrorSeverity["InvalidConfig"] = "InvalidConfig"; + ErrorSeverity["CannotPreserveMemoization"] = "CannotPreserveMemoization"; + ErrorSeverity["Todo"] = "Todo"; + ErrorSeverity["Invariant"] = "Invariant"; +})(ErrorSeverity || (ErrorSeverity = {})); +var CompilerSuggestionOperation; +(function (CompilerSuggestionOperation) { + CompilerSuggestionOperation[CompilerSuggestionOperation["InsertBefore"] = 0] = "InsertBefore"; + CompilerSuggestionOperation[CompilerSuggestionOperation["InsertAfter"] = 1] = "InsertAfter"; + CompilerSuggestionOperation[CompilerSuggestionOperation["Remove"] = 2] = "Remove"; + CompilerSuggestionOperation[CompilerSuggestionOperation["Replace"] = 3] = "Replace"; +})(CompilerSuggestionOperation || (CompilerSuggestionOperation = {})); +class CompilerErrorDetail { + constructor(options) { + this.options = options; + } + get reason() { + return this.options.reason; + } + get description() { + return this.options.description; + } + get severity() { + return this.options.severity; + } + get loc() { + return this.options.loc; + } + get suggestions() { + return this.options.suggestions; + } + printErrorMessage() { + const buffer = [`${this.severity}: ${this.reason}`]; + if (this.description != null) { + buffer.push(`. ${this.description}`); + } + if (this.loc != null && typeof this.loc !== 'symbol') { + buffer.push(` (${this.loc.start.line}:${this.loc.end.line})`); + } + return buffer.join(''); + } + toString() { + return this.printErrorMessage(); + } +} +class CompilerError extends Error { + static invariant(condition, options) { + if (!condition) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.Invariant }))); + throw errors; + } + } + static throwTodo(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.Todo }))); + throw errors; + } + static throwInvalidJS(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidJS }))); + throw errors; + } + static throwInvalidReact(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidReact }))); + throw errors; + } + static throwInvalidConfig(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidConfig }))); + throw errors; + } + static throw(options) { + const errors = new CompilerError(); + errors.pushErrorDetail(new CompilerErrorDetail(options)); + throw errors; + } + constructor(...args) { + super(...args); + this.details = []; + this.name = 'ReactCompilerError'; + this.details = []; + } + get message() { + return this.toString(); + } + set message(_message) { } + toString() { + if (Array.isArray(this.details)) { + return this.details.map(detail => detail.toString()).join('\n\n'); + } + return this.name; + } + push(options) { + var _a; + const detail = new CompilerErrorDetail({ + reason: options.reason, + description: (_a = options.description) !== null && _a !== void 0 ? _a : null, + severity: options.severity, + suggestions: options.suggestions, + loc: typeof options.loc === 'symbol' ? null : options.loc, + }); + return this.pushErrorDetail(detail); + } + pushErrorDetail(detail) { + this.details.push(detail); + return detail; + } + hasErrors() { + return this.details.length > 0; + } + asResult() { + return this.hasErrors() ? Err(this) : Ok(undefined); + } + isCritical() { + return this.details.some(detail => { + switch (detail.severity) { + case ErrorSeverity.Invariant: + case ErrorSeverity.InvalidJS: + case ErrorSeverity.InvalidReact: + case ErrorSeverity.InvalidConfig: + return true; + case ErrorSeverity.CannotPreserveMemoization: + case ErrorSeverity.Todo: + return false; + default: + assertExhaustive$1(detail.severity, 'Unhandled error severity'); + } + }); + } +} + +function insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingFunctionIdentifierName) { + var _a, _b; + const originalFnName = fnPath.node.id; + const originalFnParams = fnPath.node.params; + const compiledParams = fnPath.node.params; + CompilerError.invariant(originalFnName != null && compiled.id != null, { + reason: 'Expected function declarations that are referenced elsewhere to have a named identifier', + loc: (_a = fnPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + CompilerError.invariant(originalFnParams.length === compiledParams.length, { + reason: 'Expected React Compiler optimized function declarations to have the same number of parameters as source', + loc: (_b = fnPath.node.loc) !== null && _b !== void 0 ? _b : null, + }); + const gatingCondition = libExports$1.identifier(programContext.newUid(`${gatingFunctionIdentifierName}_result`)); + const unoptimizedFnName = libExports$1.identifier(programContext.newUid(`${originalFnName.name}_unoptimized`)); + const optimizedFnName = libExports$1.identifier(programContext.newUid(`${originalFnName.name}_optimized`)); + compiled.id.name = optimizedFnName.name; + fnPath.get('id').replaceInline(unoptimizedFnName); + const newParams = []; + const genNewArgs = []; + for (let i = 0; i < originalFnParams.length; i++) { + const argName = `arg${i}`; + if (originalFnParams[i].type === 'RestElement') { + newParams.push(libExports$1.restElement(libExports$1.identifier(argName))); + genNewArgs.push(() => libExports$1.spreadElement(libExports$1.identifier(argName))); + } + else { + newParams.push(libExports$1.identifier(argName)); + genNewArgs.push(() => libExports$1.identifier(argName)); + } + } + fnPath.insertAfter(libExports$1.functionDeclaration(originalFnName, newParams, libExports$1.blockStatement([ + libExports$1.ifStatement(gatingCondition, libExports$1.returnStatement(libExports$1.callExpression(compiled.id, genNewArgs.map(fn => fn()))), libExports$1.returnStatement(libExports$1.callExpression(unoptimizedFnName, genNewArgs.map(fn => fn())))), + ]))); + fnPath.insertBefore(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(gatingCondition, libExports$1.callExpression(libExports$1.identifier(gatingFunctionIdentifierName), [])), + ])); + fnPath.insertBefore(compiled); +} +function insertGatedFunctionDeclaration(fnPath, compiled, programContext, gating, referencedBeforeDeclaration) { + var _a; + const gatingImportedName = programContext.addImportSpecifier(gating).name; + if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) { + CompilerError.invariant(compiled.type === 'FunctionDeclaration', { + reason: 'Expected compiled node type to match input type', + description: `Got ${compiled.type} but expected FunctionDeclaration`, + loc: (_a = fnPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + insertAdditionalFunctionDeclaration(fnPath, compiled, programContext, gatingImportedName); + } + else { + const gatingExpression = libExports$1.conditionalExpression(libExports$1.callExpression(libExports$1.identifier(gatingImportedName), []), buildFunctionExpression(compiled), buildFunctionExpression(fnPath.node)); + if (fnPath.parentPath.node.type !== 'ExportDefaultDeclaration' && + fnPath.node.type === 'FunctionDeclaration' && + fnPath.node.id != null) { + fnPath.replaceWith(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(fnPath.node.id, gatingExpression), + ])); + } + else if (fnPath.parentPath.node.type === 'ExportDefaultDeclaration' && + fnPath.node.type !== 'ArrowFunctionExpression' && + fnPath.node.id != null) { + fnPath.insertAfter(libExports$1.exportDefaultDeclaration(libExports$1.identifier(fnPath.node.id.name))); + fnPath.parentPath.replaceWith(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(libExports$1.identifier(fnPath.node.id.name), gatingExpression), + ])); + } + else { + fnPath.replaceWith(gatingExpression); + } + } +} +function buildFunctionExpression(node) { + var _a, _b; + if (node.type === 'ArrowFunctionExpression' || + node.type === 'FunctionExpression') { + return node; + } + else { + const fn = { + type: 'FunctionExpression', + async: node.async, + generator: node.generator, + loc: (_a = node.loc) !== null && _a !== void 0 ? _a : null, + id: (_b = node.id) !== null && _b !== void 0 ? _b : null, + params: node.params, + body: node.body, + }; + return fn; + } +} + +function makeTypeId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected instruction id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +let typeCounter = 0; +function makeType() { + return { + kind: 'Type', + id: makeTypeId(typeCounter++), + }; +} +function typeEquals(tA, tB) { + if (tA.kind !== tB.kind) + return false; + return (typeVarEquals(tA, tB) || + funcTypeEquals(tA, tB) || + objectTypeEquals(tA, tB) || + primitiveTypeEquals(tA, tB) || + polyTypeEquals(tA, tB) || + phiTypeEquals(tA, tB) || + propTypeEquals(tA, tB) || + objectMethodTypeEquals(tA, tB)); +} +function typeVarEquals(tA, tB) { + if (tA.kind === 'Type' && tB.kind === 'Type') { + return tA.id === tB.id; + } + return false; +} +function typeKindCheck(tA, tb, type) { + return tA.kind === type && tb.kind === type; +} +function objectMethodTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'ObjectMethod'); +} +function propTypeEquals(tA, tB) { + if (tA.kind === 'Property' && tB.kind === 'Property') { + if (!typeEquals(tA.objectType, tB.objectType)) { + return false; + } + return (tA.propertyName === tB.propertyName && tA.objectName === tB.objectName); + } + return false; +} +function primitiveTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'Primitive'); +} +function polyTypeEquals(tA, tB) { + return typeKindCheck(tA, tB, 'Poly'); +} +function objectTypeEquals(tA, tB) { + if (tA.kind === 'Object' && tB.kind == 'Object') { + return tA.shapeId === tB.shapeId; + } + return false; +} +function funcTypeEquals(tA, tB) { + if (tA.kind !== 'Function' || tB.kind !== 'Function') { + return false; + } + return typeEquals(tA.return, tB.return); +} +function phiTypeEquals(tA, tB) { + if (tA.kind === 'Phi' && tB.kind === 'Phi') { + if (tA.operands.length !== tB.operands.length) { + return false; + } + let operands = new Set(tA.operands); + for (let i = 0; i < tB.operands.length; i++) { + if (!operands.has(tB.operands[i])) { + return false; + } + } + } + return false; +} + +const GeneratedSource = Symbol(); +function isStatementBlockKind(kind) { + return kind === 'block' || kind === 'catch'; +} +function isExpressionBlockKind(kind) { + return !isStatementBlockKind(kind); +} +var GotoVariant; +(function (GotoVariant) { + GotoVariant["Break"] = "Break"; + GotoVariant["Continue"] = "Continue"; + GotoVariant["Try"] = "Try"; +})(GotoVariant || (GotoVariant = {})); +var InstructionKind; +(function (InstructionKind) { + InstructionKind["Const"] = "Const"; + InstructionKind["Let"] = "Let"; + InstructionKind["Reassign"] = "Reassign"; + InstructionKind["Catch"] = "Catch"; + InstructionKind["HoistedConst"] = "HoistedConst"; + InstructionKind["HoistedLet"] = "HoistedLet"; + InstructionKind["HoistedFunction"] = "HoistedFunction"; + InstructionKind["Function"] = "Function"; +})(InstructionKind || (InstructionKind = {})); +function convertHoistedLValueKind(kind) { + switch (kind) { + case InstructionKind.HoistedLet: + return InstructionKind.Let; + case InstructionKind.HoistedConst: + return InstructionKind.Const; + case InstructionKind.HoistedFunction: + return InstructionKind.Function; + case InstructionKind.Let: + case InstructionKind.Const: + case InstructionKind.Function: + case InstructionKind.Reassign: + case InstructionKind.Catch: + return null; + default: + assertExhaustive$1(kind, 'Unexpected lvalue kind'); + } +} +function makeTemporaryIdentifier(id, loc) { + return { + id, + name: null, + declarationId: makeDeclarationId(id), + mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) }, + scope: null, + type: makeType(), + loc, + }; +} +function forkTemporaryIdentifier(id, source) { + return Object.assign(Object.assign({}, source), { mutableRange: { start: makeInstructionId(0), end: makeInstructionId(0) }, id }); +} +function makeIdentifierName(name) { + CompilerError.invariant(libExports$1.isValidIdentifier(name), { + reason: `Expected a valid identifier name`, + loc: GeneratedSource, + description: `\`${name}\` is not a valid JavaScript identifier`, + suggestions: null, + }); + return { + kind: 'named', + value: name, + }; +} +function promoteTemporary(identifier) { + CompilerError.invariant(identifier.name === null, { + reason: `Expected a temporary (unnamed) identifier`, + loc: GeneratedSource, + description: `Identifier already has a name, \`${identifier.name}\``, + suggestions: null, + }); + identifier.name = { + kind: 'promoted', + value: `#t${identifier.declarationId}`, + }; +} +function isPromotedTemporary(name) { + return name.startsWith('#t'); +} +function promoteTemporaryJsxTag(identifier) { + CompilerError.invariant(identifier.name === null, { + reason: `Expected a temporary (unnamed) identifier`, + loc: GeneratedSource, + description: `Identifier already has a name, \`${identifier.name}\``, + suggestions: null, + }); + identifier.name = { + kind: 'promoted', + value: `#T${identifier.declarationId}`, + }; +} +function isPromotedJsxTemporary(name) { + return name.startsWith('#T'); +} +var ValueReason; +(function (ValueReason) { + ValueReason["Global"] = "global"; + ValueReason["JsxCaptured"] = "jsx-captured"; + ValueReason["KnownReturnSignature"] = "known-return-signature"; + ValueReason["Context"] = "context"; + ValueReason["State"] = "state"; + ValueReason["ReducerState"] = "reducer-state"; + ValueReason["ReactiveFunctionArgument"] = "reactive-function-argument"; + ValueReason["Other"] = "other"; +})(ValueReason || (ValueReason = {})); +var ValueKind; +(function (ValueKind) { + ValueKind["MaybeFrozen"] = "maybefrozen"; + ValueKind["Frozen"] = "frozen"; + ValueKind["Primitive"] = "primitive"; + ValueKind["Global"] = "global"; + ValueKind["Mutable"] = "mutable"; + ValueKind["Context"] = "context"; +})(ValueKind || (ValueKind = {})); +const ValueKindSchema = zod.z.enum([ + ValueKind.MaybeFrozen, + ValueKind.Frozen, + ValueKind.Primitive, + ValueKind.Global, + ValueKind.Mutable, + ValueKind.Context, +]); +var Effect; +(function (Effect) { + Effect["Unknown"] = ""; + Effect["Freeze"] = "freeze"; + Effect["Read"] = "read"; + Effect["Capture"] = "capture"; + Effect["ConditionallyMutateIterator"] = "mutate-iterator?"; + Effect["ConditionallyMutate"] = "mutate?"; + Effect["Mutate"] = "mutate"; + Effect["Store"] = "store"; +})(Effect || (Effect = {})); +const EffectSchema = zod.z.enum([ + Effect.Read, + Effect.Mutate, + Effect.ConditionallyMutate, + Effect.ConditionallyMutateIterator, + Effect.Capture, + Effect.Store, + Effect.Freeze, +]); +function isMutableEffect(effect, location) { + switch (effect) { + case Effect.Capture: + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + return true; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: location, + suggestions: null, + }); + } + case Effect.Read: + case Effect.Freeze: { + return false; + } + default: { + assertExhaustive$1(effect, `Unexpected effect \`${effect}\``); + } + } +} +function makePropertyLiteral(value) { + return value; +} +function areEqualPaths(a, b) { + return (a.length === b.length && + a.every((item, ix) => item.property === b[ix].property && item.optional === b[ix].optional)); +} +function getPlaceScope(id, place) { + const scope = place.identifier.scope; + if (scope !== null && isScopeActive(scope, id)) { + return scope; + } + return null; +} +function isScopeActive(scope, id) { + return id >= scope.range.start && id < scope.range.end; +} +function makeBlockId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected block id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeScopeId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected block id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeIdentifierId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected identifier id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeDeclarationId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected declaration id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function makeInstructionId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected instruction id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +function isObjectMethodType(id) { + return id.type.kind == 'ObjectMethod'; +} +function isObjectType(id) { + return id.type.kind === 'Object'; +} +function isPrimitiveType(id) { + return id.type.kind === 'Primitive'; +} +function isArrayType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInArray'; +} +function isMapType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInMap'; +} +function isSetType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInSet'; +} +function isPropsType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInProps'; +} +function isRefValueType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInRefValue'; +} +function isUseRefType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInUseRefId'; +} +function isUseStateType(id) { + return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInUseState'; +} +function isRefOrRefValue(id) { + return isUseRefType(id) || isRefValueType(id); +} +function isSetStateType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInSetState'; +} +function isStartTransitionType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInStartTransition'); +} +function isSetActionStateType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInSetActionState'); +} +function isUseReducerType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseReducer'; +} +function isDispatcherType(id) { + return id.type.kind === 'Function' && id.type.shapeId === 'BuiltInDispatch'; +} +function isFireFunctionType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInFireFunction'); +} +function isStableType(id) { + return (isSetStateType(id) || + isSetActionStateType(id) || + isDispatcherType(id) || + isUseRefType(id) || + isStartTransitionType(id)); +} +function isStableTypeContainer(id) { + const type_ = id.type; + if (type_.kind !== 'Object') { + return false; + } + return (isUseStateType(id) || + type_.shapeId === 'BuiltInUseActionState' || + isUseReducerType(id) || + type_.shapeId === 'BuiltInUseTransition'); +} +function evaluatesToStableTypeOrContainer(env, { value }) { + if (value.kind === 'CallExpression' || value.kind === 'MethodCall') { + const callee = value.kind === 'CallExpression' ? value.callee : value.property; + const calleeHookKind = getHookKind(env, callee.identifier); + switch (calleeHookKind) { + case 'useState': + case 'useReducer': + case 'useActionState': + case 'useRef': + case 'useTransition': + return true; + } + } + return false; +} +function isUseEffectHookType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseEffectHook'); +} +function isUseLayoutEffectHookType(id) { + return (id.type.kind === 'Function' && + id.type.shapeId === 'BuiltInUseLayoutEffectHook'); +} +function isUseInsertionEffectHookType(id) { + return (id.type.kind === 'Function' && + id.type.shapeId === 'BuiltInUseInsertionEffectHook'); +} +function isUseContextHookType(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseContextHook'); +} +function getHookKind(env, id) { + return getHookKindForType(env, id.type); +} +function isUseOperator(id) { + return (id.type.kind === 'Function' && id.type.shapeId === 'BuiltInUseOperator'); +} +function getHookKindForType(env, type) { + var _a; + if (type.kind === 'Function') { + const signature = env.getFunctionSignature(type); + return (_a = signature === null || signature === void 0 ? void 0 : signature.hookKind) !== null && _a !== void 0 ? _a : null; + } + return null; +} + +var lib = {}; + +var sourceMap$1 = {}; + +var sourceMap = {}; + +var sourceMapGenerator = {}; + +var base64Vlq = {}; + +var base64 = {}; + +var hasRequiredBase64; + +function requireBase64 () { + if (hasRequiredBase64) return base64; + hasRequiredBase64 = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + base64.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + base64.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; + return base64; +} + +var hasRequiredBase64Vlq; + +function requireBase64Vlq () { + if (hasRequiredBase64Vlq) return base64Vlq; + hasRequiredBase64Vlq = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + var base64 = requireBase64(); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + base64Vlq.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; + return base64Vlq; +} + +var util = {}; + +var hasRequiredUtil; + +function requireUtil () { + if (hasRequiredUtil) return util; + hasRequiredUtil = 1; + (function (exports) { + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port; + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consecutive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + var supportsNullProto = (function () { + var obj = Object.create(null); + return !('__proto__' in obj); + }()); + + function identity (s) { + return s; + } + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + if (isProtoString(aStr)) { + return '$' + aStr; + } + + return aStr; + } + exports.toSetString = supportsNullProto ? identity : toSetString; + + function fromSetString(aStr) { + if (isProtoString(aStr)) { + return aStr.slice(1); + } + + return aStr; + } + exports.fromSetString = supportsNullProto ? identity : fromSetString; + + function isProtoString(s) { + if (!s) { + return false; + } + + var length = s.length; + + if (length < 9 /* "__proto__".length */) { + return false; + } + + if (s.charCodeAt(length - 1) !== 95 /* '_' */ || + s.charCodeAt(length - 2) !== 95 /* '_' */ || + s.charCodeAt(length - 3) !== 111 /* 'o' */ || + s.charCodeAt(length - 4) !== 116 /* 't' */ || + s.charCodeAt(length - 5) !== 111 /* 'o' */ || + s.charCodeAt(length - 6) !== 114 /* 'r' */ || + s.charCodeAt(length - 7) !== 112 /* 'p' */ || + s.charCodeAt(length - 8) !== 95 /* '_' */ || + s.charCodeAt(length - 9) !== 95 /* '_' */) { + return false; + } + + for (var i = length - 10; i >= 0; i--) { + if (s.charCodeAt(i) !== 36 /* '$' */) { + return false; + } + } + + return true; + } + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; +} (util)); + return util; +} + +var arraySet = {}; + +var hasRequiredArraySet; + +function requireArraySet () { + if (hasRequiredArraySet) return arraySet; + hasRequiredArraySet = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + var has = Object.prototype.hasOwnProperty; + var hasNativeMap = typeof Map !== "undefined"; + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = hasNativeMap ? new Map() : Object.create(null); + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = hasNativeMap ? aStr : util.toSetString(aStr); + var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + if (hasNativeMap) { + this._set.set(aStr, idx); + } else { + this._set[sStr] = idx; + } + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + if (hasNativeMap) { + return this._set.has(aStr); + } else { + var sStr = util.toSetString(aStr); + return has.call(this._set, sStr); + } + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + if (hasNativeMap) { + var idx = this._set.get(aStr); + if (idx >= 0) { + return idx; + } + } else { + var sStr = util.toSetString(aStr); + if (has.call(this._set, sStr)) { + return this._set[sStr]; + } + } + + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + arraySet.ArraySet = ArraySet; + return arraySet; +} + +var mappingList = {}; + +var hasRequiredMappingList; + +function requireMappingList () { + if (hasRequiredMappingList) return mappingList; + hasRequiredMappingList = 1; + /* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + mappingList.MappingList = MappingList; + return mappingList; +} + +var hasRequiredSourceMapGenerator; + +function requireSourceMapGenerator () { + if (hasRequiredSourceMapGenerator) return sourceMapGenerator; + hasRequiredSourceMapGenerator = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var base64VLQ = requireBase64Vlq(); + var util = requireUtil(); + var ArraySet = requireArraySet().ArraySet; + var MappingList = requireMappingList().MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null) { + source = String(source); + if (!this._sources.has(source)) { + this._sources.add(source); + } + } + + if (name != null) { + name = String(name); + if (!this._names.has(name)) { + this._names.add(name); + } + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = Object.create(null); + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source); + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + // When aOriginal is truthy but has empty values for .line and .column, + // it is most likely a programmer error. In this case we throw a very + // specific error message to try to guide them the right way. + // For example: https://github.com/Polymer/polymer-bundler/pull/519 + if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { + throw new Error( + 'original.line and original.column are not numbers -- you probably meant to omit ' + + 'the original mapping entirely and only map the generated position. If so, pass ' + + 'null for the original mapping instead of an object with empty or null values.' + ); + } + + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var next; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + next = ''; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + next += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + next += ','; + } + } + + next += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + next += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + next += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + next += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + next += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + + result += next; + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + sourceMapGenerator.SourceMapGenerator = SourceMapGenerator; + return sourceMapGenerator; +} + +var sourceMapConsumer = {}; + +var binarySearch = {}; + +var hasRequiredBinarySearch; + +function requireBinarySearch () { + if (hasRequiredBinarySearch) return binarySearch; + hasRequiredBinarySearch = 1; + (function (exports) { + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; +} (binarySearch)); + return binarySearch; +} + +var quickSort = {}; + +var hasRequiredQuickSort; + +function requireQuickSort () { + if (hasRequiredQuickSort) return quickSort; + hasRequiredQuickSort = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + quickSort.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; + return quickSort; +} + +var hasRequiredSourceMapConsumer; + +function requireSourceMapConsumer () { + if (hasRequiredSourceMapConsumer) return sourceMapConsumer; + hasRequiredSourceMapConsumer = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var util = requireUtil(); + var binarySearch = requireBinarySearch(); + var ArraySet = requireArraySet().ArraySet; + var base64VLQ = requireBase64Vlq(); + var quickSort = requireQuickSort().quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + sourceMapConsumer.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + .map(String) + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names.map(String), true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[j]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.generatedColumn + + (section.generatedOffset.generatedLine === mapping.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer; + return sourceMapConsumer; +} + +var sourceNode = {}; + +var hasRequiredSourceNode; + +function requireSourceNode () { + if (hasRequiredSourceNode) return sourceNode; + hasRequiredSourceNode = 1; + /* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ + + var SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator; + var util = requireUtil(); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are accessed by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var remainingLinesIndex = 0; + var shiftNextLine = function() { + var lineContents = getNextLine(); + // The last line of a file might not have a newline. + var newLine = getNextLine() || ""; + return lineContents + newLine; + + function getNextLine() { + return remainingLinesIndex < remainingLines.length ? + remainingLines[remainingLinesIndex++] : undefined; + } + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[remainingLinesIndex]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[remainingLinesIndex]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLinesIndex < remainingLines.length) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.splice(remainingLinesIndex).join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + sourceNode.SourceNode = SourceNode; + return sourceNode; +} + +var hasRequiredSourceMap$1; + +function requireSourceMap$1 () { + if (hasRequiredSourceMap$1) return sourceMap; + hasRequiredSourceMap$1 = 1; + sourceMap.SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator; + sourceMap.SourceMapConsumer = requireSourceMapConsumer().SourceMapConsumer; + sourceMap.SourceNode = requireSourceNode().SourceNode; + return sourceMap; +} + +var hasRequiredSourceMap; + +function requireSourceMap () { + if (hasRequiredSourceMap) return sourceMap$1; + hasRequiredSourceMap = 1; + + Object.defineProperty(sourceMap$1, "__esModule", { + value: true + }); + sourceMap$1.default = void 0; + + function _sourceMap() { + const data = _interopRequireDefault(requireSourceMap$1()); + + _sourceMap = function () { + return data; + }; + + return data; + } + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + class SourceMap { + constructor(opts, code) { + this._cachedMap = null; + this._code = code; + this._opts = opts; + this._rawMappings = []; + } + + get() { + if (!this._cachedMap) { + const map = this._cachedMap = new (_sourceMap().default.SourceMapGenerator)({ + sourceRoot: this._opts.sourceRoot + }); + const code = this._code; + + if (typeof code === "string") { + map.setSourceContent(this._opts.sourceFileName, code); + } else if (typeof code === "object") { + Object.keys(code).forEach(sourceFileName => { + map.setSourceContent(sourceFileName, code[sourceFileName]); + }); + } + + this._rawMappings.forEach(map.addMapping, map); + } + + return this._cachedMap.toJSON(); + } + + getRawMappings() { + return this._rawMappings.slice(); + } + + mark(generatedLine, generatedColumn, line, column, identifierName, filename, force) { + if (this._lastGenLine !== generatedLine && line === null) return; + + if (!force && this._lastGenLine === generatedLine && this._lastSourceLine === line && this._lastSourceColumn === column) { + return; + } + + this._cachedMap = null; + this._lastGenLine = generatedLine; + this._lastSourceLine = line; + this._lastSourceColumn = column; + + this._rawMappings.push({ + name: identifierName || undefined, + generated: { + line: generatedLine, + column: generatedColumn + }, + source: line == null ? undefined : filename || this._opts.sourceFileName, + original: line == null ? undefined : { + line: line, + column: column + } + }); + } + + } + + sourceMap$1.default = SourceMap; + return sourceMap$1; +} + +var printer = {}; + +var _trimmedEndIndex; +var hasRequired_trimmedEndIndex; + +function require_trimmedEndIndex () { + if (hasRequired_trimmedEndIndex) return _trimmedEndIndex; + hasRequired_trimmedEndIndex = 1; + var reWhitespace = /\s/; + + /** + * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace + * character of `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the index of the last non-whitespace character. + */ + function trimmedEndIndex(string) { + var index = string.length; + + while (index-- && reWhitespace.test(string.charAt(index))) {} + return index; + } + + _trimmedEndIndex = trimmedEndIndex; + return _trimmedEndIndex; +} + +var _baseTrim; +var hasRequired_baseTrim; + +function require_baseTrim () { + if (hasRequired_baseTrim) return _baseTrim; + hasRequired_baseTrim = 1; + var trimmedEndIndex = require_trimmedEndIndex(); + + /** Used to match leading whitespace. */ + var reTrimStart = /^\s+/; + + /** + * The base implementation of `_.trim`. + * + * @private + * @param {string} string The string to trim. + * @returns {string} Returns the trimmed string. + */ + function baseTrim(string) { + return string + ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') + : string; + } + + _baseTrim = baseTrim; + return _baseTrim; +} + +var isObject_1; +var hasRequiredIsObject; + +function requireIsObject () { + if (hasRequiredIsObject) return isObject_1; + hasRequiredIsObject = 1; + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + isObject_1 = isObject; + return isObject_1; +} + +var _freeGlobal; +var hasRequired_freeGlobal; + +function require_freeGlobal () { + if (hasRequired_freeGlobal) return _freeGlobal; + hasRequired_freeGlobal = 1; + var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; + + _freeGlobal = freeGlobal; + return _freeGlobal; +} + +var _root; +var hasRequired_root; + +function require_root () { + if (hasRequired_root) return _root; + hasRequired_root = 1; + var freeGlobal = require_freeGlobal(); + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + + _root = root; + return _root; +} + +var _Symbol; +var hasRequired_Symbol; + +function require_Symbol () { + if (hasRequired_Symbol) return _Symbol; + hasRequired_Symbol = 1; + var root = require_root(); + + /** Built-in value references. */ + var Symbol = root.Symbol; + + _Symbol = Symbol; + return _Symbol; +} + +var _getRawTag; +var hasRequired_getRawTag; + +function require_getRawTag () { + if (hasRequired_getRawTag) return _getRawTag; + hasRequired_getRawTag = 1; + var Symbol = require_Symbol(); + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + _getRawTag = getRawTag; + return _getRawTag; +} + +var _objectToString; +var hasRequired_objectToString; + +function require_objectToString () { + if (hasRequired_objectToString) return _objectToString; + hasRequired_objectToString = 1; + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + + _objectToString = objectToString; + return _objectToString; +} + +var _baseGetTag; +var hasRequired_baseGetTag; + +function require_baseGetTag () { + if (hasRequired_baseGetTag) return _baseGetTag; + hasRequired_baseGetTag = 1; + var Symbol = require_Symbol(), + getRawTag = require_getRawTag(), + objectToString = require_objectToString(); + + /** `Object#toString` result references. */ + var nullTag = '[object Null]', + undefinedTag = '[object Undefined]'; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + return (symToStringTag && symToStringTag in Object(value)) + ? getRawTag(value) + : objectToString(value); + } + + _baseGetTag = baseGetTag; + return _baseGetTag; +} + +var isObjectLike_1; +var hasRequiredIsObjectLike; + +function requireIsObjectLike () { + if (hasRequiredIsObjectLike) return isObjectLike_1; + hasRequiredIsObjectLike = 1; + function isObjectLike(value) { + return value != null && typeof value == 'object'; + } + + isObjectLike_1 = isObjectLike; + return isObjectLike_1; +} + +var isSymbol_1; +var hasRequiredIsSymbol; + +function requireIsSymbol () { + if (hasRequiredIsSymbol) return isSymbol_1; + hasRequiredIsSymbol = 1; + var baseGetTag = require_baseGetTag(), + isObjectLike = requireIsObjectLike(); + + /** `Object#toString` result references. */ + var symbolTag = '[object Symbol]'; + + /** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ + function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && baseGetTag(value) == symbolTag); + } + + isSymbol_1 = isSymbol; + return isSymbol_1; +} + +var toNumber_1; +var hasRequiredToNumber; + +function requireToNumber () { + if (hasRequiredToNumber) return toNumber_1; + hasRequiredToNumber = 1; + var baseTrim = require_baseTrim(), + isObject = requireIsObject(), + isSymbol = requireIsSymbol(); + + /** Used as references for various `Number` constants. */ + var NAN = 0 / 0; + + /** Used to detect bad signed hexadecimal string values. */ + var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + + /** Used to detect binary string values. */ + var reIsBinary = /^0b[01]+$/i; + + /** Used to detect octal string values. */ + var reIsOctal = /^0o[0-7]+$/i; + + /** Built-in method references without a dependency on `root`. */ + var freeParseInt = parseInt; + + /** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */ + function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + if (isObject(value)) { + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; + value = isObject(other) ? (other + '') : other; + } + if (typeof value != 'string') { + return value === 0 ? value : +value; + } + value = baseTrim(value); + var isBinary = reIsBinary.test(value); + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value); + } + + toNumber_1 = toNumber; + return toNumber_1; +} + +var toFinite_1; +var hasRequiredToFinite; + +function requireToFinite () { + if (hasRequiredToFinite) return toFinite_1; + hasRequiredToFinite = 1; + var toNumber = requireToNumber(); + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0, + MAX_INTEGER = 1.7976931348623157e+308; + + /** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ + function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; + } + + toFinite_1 = toFinite; + return toFinite_1; +} + +var toInteger_1; +var hasRequiredToInteger; + +function requireToInteger () { + if (hasRequiredToInteger) return toInteger_1; + hasRequiredToInteger = 1; + var toFinite = requireToFinite(); + + /** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toInteger(3.2); + * // => 3 + * + * _.toInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toInteger(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toInteger('3.2'); + * // => 3 + */ + function toInteger(value) { + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; + } + + toInteger_1 = toInteger; + return toInteger_1; +} + +var isInteger_1; +var hasRequiredIsInteger; + +function requireIsInteger () { + if (hasRequiredIsInteger) return isInteger_1; + hasRequiredIsInteger = 1; + var toInteger = requireToInteger(); + + /** + * Checks if `value` is an integer. + * + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an integer, else `false`. + * @example + * + * _.isInteger(3); + * // => true + * + * _.isInteger(Number.MIN_VALUE); + * // => false + * + * _.isInteger(Infinity); + * // => false + * + * _.isInteger('3'); + * // => false + */ + function isInteger(value) { + return typeof value == 'number' && value == toInteger(value); + } + + isInteger_1 = isInteger; + return isInteger_1; +} + +var _baseRepeat; +var hasRequired_baseRepeat; + +function require_baseRepeat () { + if (hasRequired_baseRepeat) return _baseRepeat; + hasRequired_baseRepeat = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeFloor = Math.floor; + + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + + _baseRepeat = baseRepeat; + return _baseRepeat; +} + +var eq_1; +var hasRequiredEq; + +function requireEq () { + if (hasRequiredEq) return eq_1; + hasRequiredEq = 1; + function eq(value, other) { + return value === other || (value !== value && other !== other); + } + + eq_1 = eq; + return eq_1; +} + +var isFunction_1; +var hasRequiredIsFunction; + +function requireIsFunction () { + if (hasRequiredIsFunction) return isFunction_1; + hasRequiredIsFunction = 1; + var baseGetTag = require_baseGetTag(), + isObject = requireIsObject(); + + /** `Object#toString` result references. */ + var asyncTag = '[object AsyncFunction]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + proxyTag = '[object Proxy]'; + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + if (!isObject(value)) { + return false; + } + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; + } + + isFunction_1 = isFunction; + return isFunction_1; +} + +var isLength_1; +var hasRequiredIsLength; + +function requireIsLength () { + if (hasRequiredIsLength) return isLength_1; + hasRequiredIsLength = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ + function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + } + + isLength_1 = isLength; + return isLength_1; +} + +var isArrayLike_1; +var hasRequiredIsArrayLike; + +function requireIsArrayLike () { + if (hasRequiredIsArrayLike) return isArrayLike_1; + hasRequiredIsArrayLike = 1; + var isFunction = requireIsFunction(), + isLength = requireIsLength(); + + /** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ + function isArrayLike(value) { + return value != null && isLength(value.length) && !isFunction(value); + } + + isArrayLike_1 = isArrayLike; + return isArrayLike_1; +} + +var _isIndex; +var hasRequired_isIndex; + +function require_isIndex () { + if (hasRequired_isIndex) return _isIndex; + hasRequired_isIndex = 1; + var MAX_SAFE_INTEGER = 9007199254740991; + + /** Used to detect unsigned integer values. */ + var reIsUint = /^(?:0|[1-9]\d*)$/; + + /** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ + function isIndex(value, length) { + var type = typeof value; + length = length == null ? MAX_SAFE_INTEGER : length; + + return !!length && + (type == 'number' || + (type != 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length); + } + + _isIndex = isIndex; + return _isIndex; +} + +var _isIterateeCall; +var hasRequired_isIterateeCall; + +function require_isIterateeCall () { + if (hasRequired_isIterateeCall) return _isIterateeCall; + hasRequired_isIterateeCall = 1; + var eq = requireEq(), + isArrayLike = requireIsArrayLike(), + isIndex = require_isIndex(), + isObject = requireIsObject(); + + /** + * Checks if the given arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. + */ + function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { + return eq(object[index], value); + } + return false; + } + + _isIterateeCall = isIterateeCall; + return _isIterateeCall; +} + +var _arrayMap; +var hasRequired_arrayMap; + +function require_arrayMap () { + if (hasRequired_arrayMap) return _arrayMap; + hasRequired_arrayMap = 1; + function arrayMap(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; + } + + _arrayMap = arrayMap; + return _arrayMap; +} + +var isArray_1; +var hasRequiredIsArray; + +function requireIsArray () { + if (hasRequiredIsArray) return isArray_1; + hasRequiredIsArray = 1; + var isArray = Array.isArray; + + isArray_1 = isArray; + return isArray_1; +} + +var _baseToString; +var hasRequired_baseToString; + +function require_baseToString () { + if (hasRequired_baseToString) return _baseToString; + hasRequired_baseToString = 1; + var Symbol = require_Symbol(), + arrayMap = require_arrayMap(), + isArray = requireIsArray(), + isSymbol = requireIsSymbol(); + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0; + + /** Used to convert symbols to primitives and strings. */ + var symbolProto = Symbol ? Symbol.prototype : undefined, + symbolToString = symbolProto ? symbolProto.toString : undefined; + + /** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ + function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return arrayMap(value, baseToString) + ''; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + _baseToString = baseToString; + return _baseToString; +} + +var toString_1; +var hasRequiredToString; + +function requireToString () { + if (hasRequiredToString) return toString_1; + hasRequiredToString = 1; + var baseToString = require_baseToString(); + + /** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ + function toString(value) { + return value == null ? '' : baseToString(value); + } + + toString_1 = toString; + return toString_1; +} + +var repeat_1; +var hasRequiredRepeat; + +function requireRepeat () { + if (hasRequiredRepeat) return repeat_1; + hasRequiredRepeat = 1; + var baseRepeat = require_baseRepeat(), + isIterateeCall = require_isIterateeCall(), + toInteger = requireToInteger(), + toString = requireToString(); + + /** + * Repeats the given string `n` times. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to repeat. + * @param {number} [n=1] The number of times to repeat the string. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the repeated string. + * @example + * + * _.repeat('*', 3); + * // => '***' + * + * _.repeat('abc', 2); + * // => 'abcabc' + * + * _.repeat('abc', 0); + * // => '' + */ + function repeat(string, n, guard) { + if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { + n = 1; + } else { + n = toInteger(n); + } + return baseRepeat(toString(string), n); + } + + repeat_1 = repeat; + return repeat_1; +} + +var buffer = {}; + +var trimRight; +var hasRequiredTrimRight; + +function requireTrimRight () { + if (hasRequiredTrimRight) return trimRight; + hasRequiredTrimRight = 1; + trimRight = function (str) { + var tail = str.length; + + while (/[\s\uFEFF\u00A0]/.test(str[tail - 1])) { + tail--; + } + + return str.slice(0, tail); + }; + return trimRight; +} + +var hasRequiredBuffer; + +function requireBuffer () { + if (hasRequiredBuffer) return buffer; + hasRequiredBuffer = 1; + + Object.defineProperty(buffer, "__esModule", { + value: true + }); + buffer.default = void 0; + + function _trimRight() { + const data = _interopRequireDefault(requireTrimRight()); + + _trimRight = function () { + return data; + }; + + return data; + } + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + const SPACES_RE = /^[ \t]+$/; + + class Buffer { + constructor(map) { + this._map = null; + this._buf = []; + this._last = ""; + this._queue = []; + this._position = { + line: 1, + column: 0 + }; + this._sourcePosition = { + identifierName: null, + line: null, + column: null, + filename: null + }; + this._disallowedPop = null; + this._map = map; + } + + get() { + this._flush(); + + const map = this._map; + const result = { + code: (0, _trimRight().default)(this._buf.join("")), + map: null, + rawMappings: map && map.getRawMappings() + }; + + if (map) { + Object.defineProperty(result, "map", { + configurable: true, + enumerable: true, + + get() { + return this.map = map.get(); + }, + + set(value) { + Object.defineProperty(this, "map", { + value, + writable: true + }); + } + + }); + } + + return result; + } + + append(str) { + this._flush(); + + const { + line, + column, + filename, + identifierName, + force + } = this._sourcePosition; + + this._append(str, line, column, identifierName, filename, force); + } + + queue(str) { + if (str === "\n") { + while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) { + this._queue.shift(); + } + } + + const { + line, + column, + filename, + identifierName, + force + } = this._sourcePosition; + + this._queue.unshift([str, line, column, identifierName, filename, force]); + } + + _flush() { + let item; + + while (item = this._queue.pop()) this._append(...item); + } + + _append(str, line, column, identifierName, filename, force) { + if (this._map && str[0] !== "\n") { + this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force); + } + + this._buf.push(str); + + this._last = str[str.length - 1]; + + for (let i = 0; i < str.length; i++) { + if (str[i] === "\n") { + this._position.line++; + this._position.column = 0; + } else { + this._position.column++; + } + } + } + + removeTrailingNewline() { + if (this._queue.length > 0 && this._queue[0][0] === "\n") { + this._queue.shift(); + } + } + + removeLastSemicolon() { + if (this._queue.length > 0 && this._queue[0][0] === ";") { + this._queue.shift(); + } + } + + endsWith(suffix) { + if (suffix.length === 1) { + let last; + + if (this._queue.length > 0) { + const str = this._queue[0][0]; + last = str[str.length - 1]; + } else { + last = this._last; + } + + return last === suffix; + } + + const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, ""); + + if (suffix.length <= end.length) { + return end.slice(-suffix.length) === suffix; + } + + return false; + } + + hasContent() { + return this._queue.length > 0 || !!this._last; + } + + exactSource(loc, cb) { + this.source("start", loc, true); + cb(); + this.source("end", loc); + + this._disallowPop("start", loc); + } + + source(prop, loc, force) { + if (prop && !loc) return; + + this._normalizePosition(prop, loc, this._sourcePosition, force); + } + + withSource(prop, loc, cb) { + if (!this._map) return cb(); + const originalLine = this._sourcePosition.line; + const originalColumn = this._sourcePosition.column; + const originalFilename = this._sourcePosition.filename; + const originalIdentifierName = this._sourcePosition.identifierName; + this.source(prop, loc); + cb(); + + if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) { + this._sourcePosition.line = originalLine; + this._sourcePosition.column = originalColumn; + this._sourcePosition.filename = originalFilename; + this._sourcePosition.identifierName = originalIdentifierName; + this._sourcePosition.force = false; + this._disallowedPop = null; + } + } + + _disallowPop(prop, loc) { + if (prop && !loc) return; + this._disallowedPop = this._normalizePosition(prop, loc); + } + + _normalizePosition(prop, loc, targetObj, force) { + const pos = loc ? loc[prop] : null; + + if (targetObj === undefined) { + targetObj = { + identifierName: null, + line: null, + column: null, + filename: null, + force: false + }; + } + + const origLine = targetObj.line; + const origColumn = targetObj.column; + const origFilename = targetObj.filename; + targetObj.identifierName = prop === "start" && loc && loc.identifierName || null; + targetObj.line = pos ? pos.line : null; + targetObj.column = pos ? pos.column : null; + targetObj.filename = loc && loc.filename || null; + + if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) { + targetObj.force = force; + } + + return targetObj; + } + + getCurrentColumn() { + const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); + + const lastIndex = extra.lastIndexOf("\n"); + return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex; + } + + getCurrentLine() { + const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); + + let count = 0; + + for (let i = 0; i < extra.length; i++) { + if (extra[i] === "\n") count++; + } + + return this._position.line + count; + } + + } + + buffer.default = Buffer; + return buffer; +} + +var node = {}; + +var whitespace = {}; + +var hasRequiredWhitespace; + +function requireWhitespace () { + if (hasRequiredWhitespace) return whitespace; + hasRequiredWhitespace = 1; + + Object.defineProperty(whitespace, "__esModule", { + value: true + }); + whitespace.list = whitespace.nodes = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function crawl(node, state = {}) { + if (t().isMemberExpression(node)) { + crawl(node.object, state); + if (node.computed) crawl(node.property, state); + } else if (t().isBinary(node) || t().isAssignmentExpression(node)) { + crawl(node.left, state); + crawl(node.right, state); + } else if (t().isCallExpression(node)) { + state.hasCall = true; + crawl(node.callee, state); + } else if (t().isFunction(node)) { + state.hasFunction = true; + } else if (t().isIdentifier(node)) { + state.hasHelper = state.hasHelper || isHelper(node.callee); + } + + return state; + } + + function isHelper(node) { + if (t().isMemberExpression(node)) { + return isHelper(node.object) || isHelper(node.property); + } else if (t().isIdentifier(node)) { + return node.name === "require" || node.name[0] === "_"; + } else if (t().isCallExpression(node)) { + return isHelper(node.callee); + } else if (t().isBinary(node) || t().isAssignmentExpression(node)) { + return t().isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right); + } else { + return false; + } + } + + function isType(node) { + return t().isLiteral(node) || t().isObjectExpression(node) || t().isArrayExpression(node) || t().isIdentifier(node) || t().isMemberExpression(node); + } + + const nodes = { + AssignmentExpression(node) { + const state = crawl(node.right); + + if (state.hasCall && state.hasHelper || state.hasFunction) { + return { + before: state.hasFunction, + after: true + }; + } + }, + + SwitchCase(node, parent) { + return { + before: node.consequent.length || parent.cases[0] === node, + after: !node.consequent.length && parent.cases[parent.cases.length - 1] === node + }; + }, + + LogicalExpression(node) { + if (t().isFunction(node.left) || t().isFunction(node.right)) { + return { + after: true + }; + } + }, + + Literal(node) { + if (node.value === "use strict") { + return { + after: true + }; + } + }, + + CallExpression(node) { + if (t().isFunction(node.callee) || isHelper(node)) { + return { + before: true, + after: true + }; + } + }, + + VariableDeclaration(node) { + for (let i = 0; i < node.declarations.length; i++) { + const declar = node.declarations[i]; + let enabled = isHelper(declar.id) && !isType(declar.init); + + if (!enabled) { + const state = crawl(declar.init); + enabled = isHelper(declar.init) && state.hasCall || state.hasFunction; + } + + if (enabled) { + return { + before: true, + after: true + }; + } + } + }, + + IfStatement(node) { + if (t().isBlockStatement(node.consequent)) { + return { + before: true, + after: true + }; + } + } + + }; + whitespace.nodes = nodes; + + nodes.ObjectProperty = nodes.ObjectTypeProperty = nodes.ObjectMethod = function (node, parent) { + if (parent.properties[0] === node) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeCallProperty = function (node, parent) { + if (parent.callProperties[0] === node && (!parent.properties || !parent.properties.length)) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeIndexer = function (node, parent) { + if (parent.indexers[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length)) { + return { + before: true + }; + } + }; + + nodes.ObjectTypeInternalSlot = function (node, parent) { + if (parent.internalSlots[0] === node && (!parent.properties || !parent.properties.length) && (!parent.callProperties || !parent.callProperties.length) && (!parent.indexers || !parent.indexers.length)) { + return { + before: true + }; + } + }; + + const list = { + VariableDeclaration(node) { + return node.declarations.map(decl => decl.init); + }, + + ArrayExpression(node) { + return node.elements; + }, + + ObjectExpression(node) { + return node.properties; + } + + }; + whitespace.list = list; + [["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) { + if (typeof amounts === "boolean") { + amounts = { + after: amounts, + before: amounts + }; + } + + [type].concat(t().FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { + nodes[type] = function () { + return amounts; + }; + }); + }); + return whitespace; +} + +var parentheses = {}; + +var hasRequiredParentheses; + +function requireParentheses () { + if (hasRequiredParentheses) return parentheses; + hasRequiredParentheses = 1; + + Object.defineProperty(parentheses, "__esModule", { + value: true + }); + parentheses.FunctionTypeAnnotation = parentheses.NullableTypeAnnotation = NullableTypeAnnotation; + parentheses.UpdateExpression = UpdateExpression; + parentheses.ObjectExpression = ObjectExpression; + parentheses.DoExpression = DoExpression; + parentheses.Binary = Binary; + parentheses.IntersectionTypeAnnotation = parentheses.UnionTypeAnnotation = UnionTypeAnnotation; + parentheses.TSAsExpression = TSAsExpression; + parentheses.TSTypeAssertion = TSTypeAssertion; + parentheses.BinaryExpression = BinaryExpression; + parentheses.SequenceExpression = SequenceExpression; + parentheses.AwaitExpression = parentheses.YieldExpression = YieldExpression; + parentheses.ClassExpression = ClassExpression; + parentheses.UnaryLike = UnaryLike; + parentheses.FunctionExpression = FunctionExpression; + parentheses.ArrowFunctionExpression = ArrowFunctionExpression; + parentheses.ConditionalExpression = ConditionalExpression; + parentheses.OptionalMemberExpression = OptionalMemberExpression; + parentheses.AssignmentExpression = AssignmentExpression; + parentheses.NewExpression = NewExpression; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + const PRECEDENCE = { + "||": 0, + "&&": 1, + "|": 2, + "^": 3, + "&": 4, + "==": 5, + "===": 5, + "!=": 5, + "!==": 5, + "<": 6, + ">": 6, + "<=": 6, + ">=": 6, + in: 6, + instanceof: 6, + ">>": 7, + "<<": 7, + ">>>": 7, + "+": 8, + "-": 8, + "*": 9, + "/": 9, + "%": 9, + "**": 10 + }; + + const isClassExtendsClause = (node, parent) => (t().isClassDeclaration(parent) || t().isClassExpression(parent)) && parent.superClass === node; + + function NullableTypeAnnotation(node, parent) { + return t().isArrayTypeAnnotation(parent); + } + + function UpdateExpression(node, parent) { + return t().isMemberExpression(parent, { + object: node + }) || t().isCallExpression(parent, { + callee: node + }) || t().isNewExpression(parent, { + callee: node + }) || isClassExtendsClause(node, parent); + } + + function ObjectExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerArrow: true + }); + } + + function DoExpression(node, parent, printStack) { + return isFirstInStatement(printStack); + } + + function Binary(node, parent) { + if (node.operator === "**" && t().isBinaryExpression(parent, { + operator: "**" + })) { + return parent.left === node; + } + + if (isClassExtendsClause(node, parent)) { + return true; + } + + if ((t().isCallExpression(parent) || t().isNewExpression(parent)) && parent.callee === node || t().isUnaryLike(parent) || t().isMemberExpression(parent) && parent.object === node || t().isAwaitExpression(parent)) { + return true; + } + + if (t().isBinary(parent)) { + const parentOp = parent.operator; + const parentPos = PRECEDENCE[parentOp]; + const nodeOp = node.operator; + const nodePos = PRECEDENCE[nodeOp]; + + if (parentPos === nodePos && parent.right === node && !t().isLogicalExpression(parent) || parentPos > nodePos) { + return true; + } + } + + return false; + } + + function UnionTypeAnnotation(node, parent) { + return t().isArrayTypeAnnotation(parent) || t().isNullableTypeAnnotation(parent) || t().isIntersectionTypeAnnotation(parent) || t().isUnionTypeAnnotation(parent); + } + + function TSAsExpression() { + return true; + } + + function TSTypeAssertion() { + return true; + } + + function BinaryExpression(node, parent) { + return node.operator === "in" && (t().isVariableDeclarator(parent) || t().isFor(parent)); + } + + function SequenceExpression(node, parent) { + if (t().isForStatement(parent) || t().isThrowStatement(parent) || t().isReturnStatement(parent) || t().isIfStatement(parent) && parent.test === node || t().isWhileStatement(parent) && parent.test === node || t().isForInStatement(parent) && parent.right === node || t().isSwitchStatement(parent) && parent.discriminant === node || t().isExpressionStatement(parent) && parent.expression === node) { + return false; + } + + return true; + } + + function YieldExpression(node, parent) { + return t().isBinary(parent) || t().isUnaryLike(parent) || t().isCallExpression(parent) || t().isMemberExpression(parent) || t().isNewExpression(parent) || t().isAwaitExpression(parent) && t().isYieldExpression(node) || t().isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent); + } + + function ClassExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerDefaultExports: true + }); + } + + function UnaryLike(node, parent) { + return t().isMemberExpression(parent, { + object: node + }) || t().isCallExpression(parent, { + callee: node + }) || t().isNewExpression(parent, { + callee: node + }) || t().isBinaryExpression(parent, { + operator: "**", + left: node + }) || isClassExtendsClause(node, parent); + } + + function FunctionExpression(node, parent, printStack) { + return isFirstInStatement(printStack, { + considerDefaultExports: true + }); + } + + function ArrowFunctionExpression(node, parent) { + return t().isExportDeclaration(parent) || ConditionalExpression(node, parent); + } + + function ConditionalExpression(node, parent) { + if (t().isUnaryLike(parent) || t().isBinary(parent) || t().isConditionalExpression(parent, { + test: node + }) || t().isAwaitExpression(parent) || t().isOptionalMemberExpression(parent) || t().isTaggedTemplateExpression(parent) || t().isTSTypeAssertion(parent) || t().isTSAsExpression(parent)) { + return true; + } + + return UnaryLike(node, parent); + } + + function OptionalMemberExpression(node, parent) { + return t().isCallExpression(parent) || t().isMemberExpression(parent); + } + + function AssignmentExpression(node) { + if (t().isObjectPattern(node.left)) { + return true; + } else { + return ConditionalExpression(...arguments); + } + } + + function NewExpression(node, parent) { + return isClassExtendsClause(node, parent); + } + + function isFirstInStatement(printStack, { + considerArrow = false, + considerDefaultExports = false + } = {}) { + let i = printStack.length - 1; + let node = printStack[i]; + i--; + let parent = printStack[i]; + + while (i > 0) { + if (t().isExpressionStatement(parent, { + expression: node + }) || t().isTaggedTemplateExpression(parent) || considerDefaultExports && t().isExportDefaultDeclaration(parent, { + declaration: node + }) || considerArrow && t().isArrowFunctionExpression(parent, { + body: node + })) { + return true; + } + + if (t().isCallExpression(parent, { + callee: node + }) || t().isSequenceExpression(parent) && parent.expressions[0] === node || t().isMemberExpression(parent, { + object: node + }) || t().isConditional(parent, { + test: node + }) || t().isBinary(parent, { + left: node + }) || t().isAssignmentExpression(parent, { + left: node + })) { + node = parent; + i--; + parent = printStack[i]; + } else { + return false; + } + } + + return false; + } + return parentheses; +} + +var hasRequiredNode; + +function requireNode () { + if (hasRequiredNode) return node; + hasRequiredNode = 1; + + Object.defineProperty(node, "__esModule", { + value: true + }); + node.needsWhitespace = needsWhitespace; + node.needsWhitespaceBefore = needsWhitespaceBefore; + node.needsWhitespaceAfter = needsWhitespaceAfter; + node.needsParens = needsParens; + + var whitespace = _interopRequireWildcard(requireWhitespace()); + + var parens = _interopRequireWildcard(requireParentheses()); + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function expandAliases(obj) { + const newObj = {}; + + function add(type, func) { + const fn = newObj[type]; + newObj[type] = fn ? function (node, parent, stack) { + const result = fn(node, parent, stack); + return result == null ? func(node, parent, stack) : result; + } : func; + } + + for (const type of Object.keys(obj)) { + const aliases = t().FLIPPED_ALIAS_KEYS[type]; + + if (aliases) { + for (const alias of aliases) { + add(alias, obj[type]); + } + } else { + add(type, obj[type]); + } + } + + return newObj; + } + + const expandedParens = expandAliases(parens); + const expandedWhitespaceNodes = expandAliases(whitespace.nodes); + const expandedWhitespaceList = expandAliases(whitespace.list); + + function find(obj, node, parent, printStack) { + const fn = obj[node.type]; + return fn ? fn(node, parent, printStack) : null; + } + + function isOrHasCallExpression(node) { + if (t().isCallExpression(node)) { + return true; + } + + if (t().isMemberExpression(node)) { + return isOrHasCallExpression(node.object) || !node.computed && isOrHasCallExpression(node.property); + } else { + return false; + } + } + + function needsWhitespace(node, parent, type) { + if (!node) return 0; + + if (t().isExpressionStatement(node)) { + node = node.expression; + } + + let linesInfo = find(expandedWhitespaceNodes, node, parent); + + if (!linesInfo) { + const items = find(expandedWhitespaceList, node, parent); + + if (items) { + for (let i = 0; i < items.length; i++) { + linesInfo = needsWhitespace(items[i], node, type); + if (linesInfo) break; + } + } + } + + if (typeof linesInfo === "object" && linesInfo !== null) { + return linesInfo[type] || 0; + } + + return 0; + } + + function needsWhitespaceBefore(node, parent) { + return needsWhitespace(node, parent, "before"); + } + + function needsWhitespaceAfter(node, parent) { + return needsWhitespace(node, parent, "after"); + } + + function needsParens(node, parent, printStack) { + if (!parent) return false; + + if (t().isNewExpression(parent) && parent.callee === node) { + if (isOrHasCallExpression(node)) return true; + } + + return find(expandedParens, node, parent, printStack); + } + return node; +} + +var generators = {}; + +var templateLiterals = {}; + +var hasRequiredTemplateLiterals; + +function requireTemplateLiterals () { + if (hasRequiredTemplateLiterals) return templateLiterals; + hasRequiredTemplateLiterals = 1; + + Object.defineProperty(templateLiterals, "__esModule", { + value: true + }); + templateLiterals.TaggedTemplateExpression = TaggedTemplateExpression; + templateLiterals.TemplateElement = TemplateElement; + templateLiterals.TemplateLiteral = TemplateLiteral; + + function TaggedTemplateExpression(node) { + this.print(node.tag, node); + this.print(node.typeParameters, node); + this.print(node.quasi, node); + } + + function TemplateElement(node, parent) { + const isFirst = parent.quasis[0] === node; + const isLast = parent.quasis[parent.quasis.length - 1] === node; + const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); + this.token(value); + } + + function TemplateLiteral(node) { + const quasis = node.quasis; + + for (let i = 0; i < quasis.length; i++) { + this.print(quasis[i], node); + + if (i + 1 < quasis.length) { + this.print(node.expressions[i], node); + } + } + } + return templateLiterals; +} + +var expressions = {}; + +var hasRequiredExpressions; + +function requireExpressions () { + if (hasRequiredExpressions) return expressions; + hasRequiredExpressions = 1; + + Object.defineProperty(expressions, "__esModule", { + value: true + }); + expressions.UnaryExpression = UnaryExpression; + expressions.DoExpression = DoExpression; + expressions.ParenthesizedExpression = ParenthesizedExpression; + expressions.UpdateExpression = UpdateExpression; + expressions.ConditionalExpression = ConditionalExpression; + expressions.NewExpression = NewExpression; + expressions.SequenceExpression = SequenceExpression; + expressions.ThisExpression = ThisExpression; + expressions.Super = Super; + expressions.Decorator = Decorator; + expressions.OptionalMemberExpression = OptionalMemberExpression; + expressions.OptionalCallExpression = OptionalCallExpression; + expressions.CallExpression = CallExpression; + expressions.Import = Import; + expressions.EmptyStatement = EmptyStatement; + expressions.ExpressionStatement = ExpressionStatement; + expressions.AssignmentPattern = AssignmentPattern; + expressions.LogicalExpression = expressions.BinaryExpression = expressions.AssignmentExpression = AssignmentExpression; + expressions.BindExpression = BindExpression; + expressions.MemberExpression = MemberExpression; + expressions.MetaProperty = MetaProperty; + expressions.PrivateName = PrivateName; + expressions.AwaitExpression = expressions.YieldExpression = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + var n = _interopRequireWildcard(requireNode()); + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function UnaryExpression(node) { + if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof" || node.operator === "throw") { + this.word(node.operator); + this.space(); + } else { + this.token(node.operator); + } + + this.print(node.argument, node); + } + + function DoExpression(node) { + this.word("do"); + this.space(); + this.print(node.body, node); + } + + function ParenthesizedExpression(node) { + this.token("("); + this.print(node.expression, node); + this.token(")"); + } + + function UpdateExpression(node) { + if (node.prefix) { + this.token(node.operator); + this.print(node.argument, node); + } else { + this.startTerminatorless(true); + this.print(node.argument, node); + this.endTerminatorless(); + this.token(node.operator); + } + } + + function ConditionalExpression(node) { + this.print(node.test, node); + this.space(); + this.token("?"); + this.space(); + this.print(node.consequent, node); + this.space(); + this.token(":"); + this.space(); + this.print(node.alternate, node); + } + + function NewExpression(node, parent) { + this.word("new"); + this.space(); + this.print(node.callee, node); + + if (this.format.minified && node.arguments.length === 0 && !node.optional && !t().isCallExpression(parent, { + callee: node + }) && !t().isMemberExpression(parent) && !t().isNewExpression(parent)) { + return; + } + + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + + if (node.optional) { + this.token("?."); + } + + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function SequenceExpression(node) { + this.printList(node.expressions, node); + } + + function ThisExpression() { + this.word("this"); + } + + function Super() { + this.word("super"); + } + + function Decorator(node) { + this.token("@"); + this.print(node.expression, node); + this.newline(); + } + + function OptionalMemberExpression(node) { + this.print(node.object, node); + + if (!node.computed && t().isMemberExpression(node.property)) { + throw new TypeError("Got a MemberExpression for MemberExpression property"); + } + + let computed = node.computed; + + if (t().isLiteral(node.property) && typeof node.property.value === "number") { + computed = true; + } + + if (node.optional) { + this.token("?."); + } + + if (computed) { + this.token("["); + this.print(node.property, node); + this.token("]"); + } else { + if (!node.optional) { + this.token("."); + } + + this.print(node.property, node); + } + } + + function OptionalCallExpression(node) { + this.print(node.callee, node); + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + + if (node.optional) { + this.token("?."); + } + + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function CallExpression(node) { + this.print(node.callee, node); + this.print(node.typeArguments, node); + this.print(node.typeParameters, node); + this.token("("); + this.printList(node.arguments, node); + this.token(")"); + } + + function Import() { + this.word("import"); + } + + function buildYieldAwait(keyword) { + return function (node) { + this.word(keyword); + + if (node.delegate) { + this.token("*"); + } + + if (node.argument) { + this.space(); + const terminatorState = this.startTerminatorless(); + this.print(node.argument, node); + this.endTerminatorless(terminatorState); + } + }; + } + + const YieldExpression = buildYieldAwait("yield"); + expressions.YieldExpression = YieldExpression; + const AwaitExpression = buildYieldAwait("await"); + expressions.AwaitExpression = AwaitExpression; + + function EmptyStatement() { + this.semicolon(true); + } + + function ExpressionStatement(node) { + this.print(node.expression, node); + this.semicolon(); + } + + function AssignmentPattern(node) { + this.print(node.left, node); + if (node.left.optional) this.token("?"); + this.print(node.left.typeAnnotation, node); + this.space(); + this.token("="); + this.space(); + this.print(node.right, node); + } + + function AssignmentExpression(node, parent) { + const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); + + if (parens) { + this.token("("); + } + + this.print(node.left, node); + this.space(); + + if (node.operator === "in" || node.operator === "instanceof") { + this.word(node.operator); + } else { + this.token(node.operator); + } + + this.space(); + this.print(node.right, node); + + if (parens) { + this.token(")"); + } + } + + function BindExpression(node) { + this.print(node.object, node); + this.token("::"); + this.print(node.callee, node); + } + + function MemberExpression(node) { + this.print(node.object, node); + + if (!node.computed && t().isMemberExpression(node.property)) { + throw new TypeError("Got a MemberExpression for MemberExpression property"); + } + + let computed = node.computed; + + if (t().isLiteral(node.property) && typeof node.property.value === "number") { + computed = true; + } + + if (computed) { + this.token("["); + this.print(node.property, node); + this.token("]"); + } else { + this.token("."); + this.print(node.property, node); + } + } + + function MetaProperty(node) { + this.print(node.meta, node); + this.token("."); + this.print(node.property, node); + } + + function PrivateName(node) { + this.token("#"); + this.print(node.id, node); + } + return expressions; +} + +var statements = {}; + +var hasRequiredStatements; + +function requireStatements () { + if (hasRequiredStatements) return statements; + hasRequiredStatements = 1; + + Object.defineProperty(statements, "__esModule", { + value: true + }); + statements.WithStatement = WithStatement; + statements.IfStatement = IfStatement; + statements.ForStatement = ForStatement; + statements.WhileStatement = WhileStatement; + statements.DoWhileStatement = DoWhileStatement; + statements.LabeledStatement = LabeledStatement; + statements.TryStatement = TryStatement; + statements.CatchClause = CatchClause; + statements.SwitchStatement = SwitchStatement; + statements.SwitchCase = SwitchCase; + statements.DebuggerStatement = DebuggerStatement; + statements.VariableDeclaration = VariableDeclaration; + statements.VariableDeclarator = VariableDeclarator; + statements.ThrowStatement = statements.BreakStatement = statements.ReturnStatement = statements.ContinueStatement = statements.ForOfStatement = statements.ForInStatement = void 0; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function WithStatement(node) { + this.word("with"); + this.space(); + this.token("("); + this.print(node.object, node); + this.token(")"); + this.printBlock(node); + } + + function IfStatement(node) { + this.word("if"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.space(); + const needsBlock = node.alternate && t().isIfStatement(getLastStatement(node.consequent)); + + if (needsBlock) { + this.token("{"); + this.newline(); + this.indent(); + } + + this.printAndIndentOnComments(node.consequent, node); + + if (needsBlock) { + this.dedent(); + this.newline(); + this.token("}"); + } + + if (node.alternate) { + if (this.endsWith("}")) this.space(); + this.word("else"); + this.space(); + this.printAndIndentOnComments(node.alternate, node); + } + } + + function getLastStatement(statement) { + if (!t().isStatement(statement.body)) return statement; + return getLastStatement(statement.body); + } + + function ForStatement(node) { + this.word("for"); + this.space(); + this.token("("); + this.inForStatementInitCounter++; + this.print(node.init, node); + this.inForStatementInitCounter--; + this.token(";"); + + if (node.test) { + this.space(); + this.print(node.test, node); + } + + this.token(";"); + + if (node.update) { + this.space(); + this.print(node.update, node); + } + + this.token(")"); + this.printBlock(node); + } + + function WhileStatement(node) { + this.word("while"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.printBlock(node); + } + + const buildForXStatement = function (op) { + return function (node) { + this.word("for"); + this.space(); + + if (op === "of" && node.await) { + this.word("await"); + this.space(); + } + + this.token("("); + this.print(node.left, node); + this.space(); + this.word(op); + this.space(); + this.print(node.right, node); + this.token(")"); + this.printBlock(node); + }; + }; + + const ForInStatement = buildForXStatement("in"); + statements.ForInStatement = ForInStatement; + const ForOfStatement = buildForXStatement("of"); + statements.ForOfStatement = ForOfStatement; + + function DoWhileStatement(node) { + this.word("do"); + this.space(); + this.print(node.body, node); + this.space(); + this.word("while"); + this.space(); + this.token("("); + this.print(node.test, node); + this.token(")"); + this.semicolon(); + } + + function buildLabelStatement(prefix, key = "label") { + return function (node) { + this.word(prefix); + const label = node[key]; + + if (label) { + this.space(); + const isLabel = key == "label"; + const terminatorState = this.startTerminatorless(isLabel); + this.print(label, node); + this.endTerminatorless(terminatorState); + } + + this.semicolon(); + }; + } + + const ContinueStatement = buildLabelStatement("continue"); + statements.ContinueStatement = ContinueStatement; + const ReturnStatement = buildLabelStatement("return", "argument"); + statements.ReturnStatement = ReturnStatement; + const BreakStatement = buildLabelStatement("break"); + statements.BreakStatement = BreakStatement; + const ThrowStatement = buildLabelStatement("throw", "argument"); + statements.ThrowStatement = ThrowStatement; + + function LabeledStatement(node) { + this.print(node.label, node); + this.token(":"); + this.space(); + this.print(node.body, node); + } + + function TryStatement(node) { + this.word("try"); + this.space(); + this.print(node.block, node); + this.space(); + + if (node.handlers) { + this.print(node.handlers[0], node); + } else { + this.print(node.handler, node); + } + + if (node.finalizer) { + this.space(); + this.word("finally"); + this.space(); + this.print(node.finalizer, node); + } + } + + function CatchClause(node) { + this.word("catch"); + this.space(); + + if (node.param) { + this.token("("); + this.print(node.param, node); + this.token(")"); + this.space(); + } + + this.print(node.body, node); + } + + function SwitchStatement(node) { + this.word("switch"); + this.space(); + this.token("("); + this.print(node.discriminant, node); + this.token(")"); + this.space(); + this.token("{"); + this.printSequence(node.cases, node, { + indent: true, + + addNewlines(leading, cas) { + if (!leading && node.cases[node.cases.length - 1] === cas) return -1; + } + + }); + this.token("}"); + } + + function SwitchCase(node) { + if (node.test) { + this.word("case"); + this.space(); + this.print(node.test, node); + this.token(":"); + } else { + this.word("default"); + this.token(":"); + } + + if (node.consequent.length) { + this.newline(); + this.printSequence(node.consequent, node, { + indent: true + }); + } + } + + function DebuggerStatement() { + this.word("debugger"); + this.semicolon(); + } + + function variableDeclarationIndent() { + this.token(","); + this.newline(); + if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true); + } + + function constDeclarationIndent() { + this.token(","); + this.newline(); + if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true); + } + + function VariableDeclaration(node, parent) { + if (node.declare) { + this.word("declare"); + this.space(); + } + + this.word(node.kind); + this.space(); + let hasInits = false; + + if (!t().isFor(parent)) { + for (const declar of node.declarations) { + if (declar.init) { + hasInits = true; + } + } + } + + let separator; + + if (hasInits) { + separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent; + } + + this.printList(node.declarations, node, { + separator + }); + + if (t().isFor(parent)) { + if (parent.left === node || parent.init === node) return; + } + + this.semicolon(); + } + + function VariableDeclarator(node) { + this.print(node.id, node); + if (node.definite) this.token("!"); + this.print(node.id.typeAnnotation, node); + + if (node.init) { + this.space(); + this.token("="); + this.space(); + this.print(node.init, node); + } + } + return statements; +} + +var classes = {}; + +var hasRequiredClasses; + +function requireClasses () { + if (hasRequiredClasses) return classes; + hasRequiredClasses = 1; + + Object.defineProperty(classes, "__esModule", { + value: true + }); + classes.ClassExpression = classes.ClassDeclaration = ClassDeclaration; + classes.ClassBody = ClassBody; + classes.ClassProperty = ClassProperty; + classes.ClassPrivateProperty = ClassPrivateProperty; + classes.ClassMethod = ClassMethod; + classes.ClassPrivateMethod = ClassPrivateMethod; + classes._classMethodHead = _classMethodHead; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function ClassDeclaration(node, parent) { + if (!this.format.decoratorsBeforeExport || !t().isExportDefaultDeclaration(parent) && !t().isExportNamedDeclaration(parent)) { + this.printJoin(node.decorators, node); + } + + if (node.declare) { + this.word("declare"); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + this.word("class"); + + if (node.id) { + this.space(); + this.print(node.id, node); + } + + this.print(node.typeParameters, node); + + if (node.superClass) { + this.space(); + this.word("extends"); + this.space(); + this.print(node.superClass, node); + this.print(node.superTypeParameters, node); + } + + if (node.implements) { + this.space(); + this.word("implements"); + this.space(); + this.printList(node.implements, node); + } + + this.space(); + this.print(node.body, node); + } + + function ClassBody(node) { + this.token("{"); + this.printInnerComments(node); + + if (node.body.length === 0) { + this.token("}"); + } else { + this.newline(); + this.indent(); + this.printSequence(node.body, node); + this.dedent(); + if (!this.endsWith("\n")) this.newline(); + this.rightBrace(); + } + } + + function ClassProperty(node) { + this.printJoin(node.decorators, node); + + if (node.accessibility) { + this.word(node.accessibility); + this.space(); + } + + if (node.static) { + this.word("static"); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + if (node.readonly) { + this.word("readonly"); + this.space(); + } + + if (node.computed) { + this.token("["); + this.print(node.key, node); + this.token("]"); + } else { + this._variance(node); + + this.print(node.key, node); + } + + if (node.optional) { + this.token("?"); + } + + if (node.definite) { + this.token("!"); + } + + this.print(node.typeAnnotation, node); + + if (node.value) { + this.space(); + this.token("="); + this.space(); + this.print(node.value, node); + } + + this.semicolon(); + } + + function ClassPrivateProperty(node) { + if (node.static) { + this.word("static"); + this.space(); + } + + this.print(node.key, node); + this.print(node.typeAnnotation, node); + + if (node.value) { + this.space(); + this.token("="); + this.space(); + this.print(node.value, node); + } + + this.semicolon(); + } + + function ClassMethod(node) { + this._classMethodHead(node); + + this.space(); + this.print(node.body, node); + } + + function ClassPrivateMethod(node) { + this._classMethodHead(node); + + this.space(); + this.print(node.body, node); + } + + function _classMethodHead(node) { + this.printJoin(node.decorators, node); + + if (node.accessibility) { + this.word(node.accessibility); + this.space(); + } + + if (node.abstract) { + this.word("abstract"); + this.space(); + } + + if (node.static) { + this.word("static"); + this.space(); + } + + this._methodHead(node); + } + return classes; +} + +var methods = {}; + +var hasRequiredMethods; + +function requireMethods () { + if (hasRequiredMethods) return methods; + hasRequiredMethods = 1; + + Object.defineProperty(methods, "__esModule", { + value: true + }); + methods._params = _params; + methods._parameters = _parameters; + methods._param = _param; + methods._methodHead = _methodHead; + methods._predicate = _predicate; + methods._functionHead = _functionHead; + methods.FunctionDeclaration = methods.FunctionExpression = FunctionExpression; + methods.ArrowFunctionExpression = ArrowFunctionExpression; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function _params(node) { + this.print(node.typeParameters, node); + this.token("("); + + this._parameters(node.params, node); + + this.token(")"); + this.print(node.returnType, node); + } + + function _parameters(parameters, parent) { + for (let i = 0; i < parameters.length; i++) { + this._param(parameters[i], parent); + + if (i < parameters.length - 1) { + this.token(","); + this.space(); + } + } + } + + function _param(parameter, parent) { + this.printJoin(parameter.decorators, parameter); + this.print(parameter, parent); + if (parameter.optional) this.token("?"); + this.print(parameter.typeAnnotation, parameter); + } + + function _methodHead(node) { + const kind = node.kind; + const key = node.key; + + if (kind === "get" || kind === "set") { + this.word(kind); + this.space(); + } + + if (node.async) { + this.word("async"); + this.space(); + } + + if (kind === "method" || kind === "init") { + if (node.generator) { + this.token("*"); + } + } + + if (node.computed) { + this.token("["); + this.print(key, node); + this.token("]"); + } else { + this.print(key, node); + } + + if (node.optional) { + this.token("?"); + } + + this._params(node); + } + + function _predicate(node) { + if (node.predicate) { + if (!node.returnType) { + this.token(":"); + } + + this.space(); + this.print(node.predicate, node); + } + } + + function _functionHead(node) { + if (node.async) { + this.word("async"); + this.space(); + } + + this.word("function"); + if (node.generator) this.token("*"); + this.space(); + + if (node.id) { + this.print(node.id, node); + } + + this._params(node); + + this._predicate(node); + } + + function FunctionExpression(node) { + this._functionHead(node); + + this.space(); + this.print(node.body, node); + } + + function ArrowFunctionExpression(node) { + if (node.async) { + this.word("async"); + this.space(); + } + + const firstParam = node.params[0]; + + if (node.params.length === 1 && t().isIdentifier(firstParam) && !hasTypes(node, firstParam)) { + if (this.format.retainLines && node.loc && node.body.loc && node.loc.start.line < node.body.loc.start.line) { + this.token("("); + + if (firstParam.loc && firstParam.loc.start.line > node.loc.start.line) { + this.indent(); + this.print(firstParam, node); + this.dedent(); + + this._catchUp("start", node.body.loc); + } else { + this.print(firstParam, node); + } + + this.token(")"); + } else { + this.print(firstParam, node); + } + } else { + this._params(node); + } + + this._predicate(node); + + this.space(); + this.token("=>"); + this.space(); + this.print(node.body, node); + } + + function hasTypes(node, param) { + return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments; + } + return methods; +} + +var modules = {}; + +var hasRequiredModules; + +function requireModules () { + if (hasRequiredModules) return modules; + hasRequiredModules = 1; + + Object.defineProperty(modules, "__esModule", { + value: true + }); + modules.ImportSpecifier = ImportSpecifier; + modules.ImportDefaultSpecifier = ImportDefaultSpecifier; + modules.ExportDefaultSpecifier = ExportDefaultSpecifier; + modules.ExportSpecifier = ExportSpecifier; + modules.ExportNamespaceSpecifier = ExportNamespaceSpecifier; + modules.ExportAllDeclaration = ExportAllDeclaration; + modules.ExportNamedDeclaration = ExportNamedDeclaration; + modules.ExportDefaultDeclaration = ExportDefaultDeclaration; + modules.ImportDeclaration = ImportDeclaration; + modules.ImportNamespaceSpecifier = ImportNamespaceSpecifier; + + function t() { + const data = _interopRequireWildcard(requireLib$1()); + + t = function () { + return data; + }; + + return data; + } + + function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } + + function ImportSpecifier(node) { + if (node.importKind === "type" || node.importKind === "typeof") { + this.word(node.importKind); + this.space(); + } + + this.print(node.imported, node); + + if (node.local && node.local.name !== node.imported.name) { + this.space(); + this.word("as"); + this.space(); + this.print(node.local, node); + } + } + + function ImportDefaultSpecifier(node) { + this.print(node.local, node); + } + + function ExportDefaultSpecifier(node) { + this.print(node.exported, node); + } + + function ExportSpecifier(node) { + this.print(node.local, node); + + if (node.exported && node.local.name !== node.exported.name) { + this.space(); + this.word("as"); + this.space(); + this.print(node.exported, node); + } + } + + function ExportNamespaceSpecifier(node) { + this.token("*"); + this.space(); + this.word("as"); + this.space(); + this.print(node.exported, node); + } + + function ExportAllDeclaration(node) { + this.word("export"); + this.space(); + + if (node.exportKind === "type") { + this.word("type"); + this.space(); + } + + this.token("*"); + this.space(); + this.word("from"); + this.space(); + this.print(node.source, node); + this.semicolon(); + } + + function ExportNamedDeclaration(node) { + if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) { + this.printJoin(node.declaration.decorators, node); + } + + this.word("export"); + this.space(); + ExportDeclaration.apply(this, arguments); + } + + function ExportDefaultDeclaration(node) { + if (this.format.decoratorsBeforeExport && t().isClassDeclaration(node.declaration)) { + this.printJoin(node.declaration.decorators, node); + } + + this.word("export"); + this.space(); + this.word("default"); + this.space(); + ExportDeclaration.apply(this, arguments); + } + + function ExportDeclaration(node) { + if (node.declaration) { + const declar = node.declaration; + this.print(declar, node); + if (!t().isStatement(declar)) this.semicolon(); + } else { + if (node.exportKind === "type") { + this.word("type"); + this.space(); + } + + const specifiers = node.specifiers.slice(0); + let hasSpecial = false; + + while (true) { + const first = specifiers[0]; + + if (t().isExportDefaultSpecifier(first) || t().isExportNamespaceSpecifier(first)) { + hasSpecial = true; + this.print(specifiers.shift(), node); + + if (specifiers.length) { + this.token(","); + this.space(); + } + } else { + break; + } + } + + if (specifiers.length || !specifiers.length && !hasSpecial) { + this.token("{"); + + if (specifiers.length) { + this.space(); + this.printList(specifiers, node); + this.space(); + } + + this.token("}"); + } + + if (node.source) { + this.space(); + this.word("from"); + this.space(); + this.print(node.source, node); + } + + this.semicolon(); + } + } + + function ImportDeclaration(node) { + this.word("import"); + this.space(); + + if (node.importKind === "type" || node.importKind === "typeof") { + this.word(node.importKind); + this.space(); + } + + const specifiers = node.specifiers.slice(0); + + if (specifiers && specifiers.length) { + while (true) { + const first = specifiers[0]; + + if (t().isImportDefaultSpecifier(first) || t().isImportNamespaceSpecifier(first)) { + this.print(specifiers.shift(), node); + + if (specifiers.length) { + this.token(","); + this.space(); + } + } else { + break; + } + } + + if (specifiers.length) { + this.token("{"); + this.space(); + this.printList(specifiers, node); + this.space(); + this.token("}"); + } + + this.space(); + this.word("from"); + this.space(); + } + + this.print(node.source, node); + this.semicolon(); + } + + function ImportNamespaceSpecifier(node) { + this.token("*"); + this.space(); + this.word("as"); + this.space(); + this.print(node.local, node); + } + return modules; +} + +var types = {}; + +var jsesc_1; +var hasRequiredJsesc; + +function requireJsesc () { + if (hasRequiredJsesc) return jsesc_1; + hasRequiredJsesc = 1; + + const object = {}; + const hasOwnProperty = object.hasOwnProperty; + const forOwn = (object, callback) => { + for (const key in object) { + if (hasOwnProperty.call(object, key)) { + callback(key, object[key]); + } + } + }; + + const extend = (destination, source) => { + if (!source) { + return destination; + } + forOwn(source, (key, value) => { + destination[key] = value; + }); + return destination; + }; + + const forEach = (array, callback) => { + const length = array.length; + let index = -1; + while (++index < length) { + callback(array[index]); + } + }; + + const toString = object.toString; + const isArray = Array.isArray; + const isBuffer = Buffer.isBuffer; + const isObject = (value) => { + // This is a very simple check, but it’s good enough for what we need. + return toString.call(value) == '[object Object]'; + }; + const isString = (value) => { + return typeof value == 'string' || + toString.call(value) == '[object String]'; + }; + const isNumber = (value) => { + return typeof value == 'number' || + toString.call(value) == '[object Number]'; + }; + const isFunction = (value) => { + return typeof value == 'function'; + }; + const isMap = (value) => { + return toString.call(value) == '[object Map]'; + }; + const isSet = (value) => { + return toString.call(value) == '[object Set]'; + }; + + /*--------------------------------------------------------------------------*/ + + // https://mathiasbynens.be/notes/javascript-escapes#single + const singleEscapes = { + '"': '\\"', + '\'': '\\\'', + '\\': '\\\\', + '\b': '\\b', + '\f': '\\f', + '\n': '\\n', + '\r': '\\r', + '\t': '\\t' + // `\v` is omitted intentionally, because in IE < 9, '\v' == 'v'. + // '\v': '\\x0B' + }; + const regexSingleEscape = /["'\\\b\f\n\r\t]/; + + const regexDigit = /[0-9]/; + const regexWhitelist = /[ !#-&\(-\[\]-_a-~]/; + + const jsesc = (argument, options) => { + const increaseIndentation = () => { + oldIndent = indent; + ++options.indentLevel; + indent = options.indent.repeat(options.indentLevel); + }; + // Handle options + const defaults = { + 'escapeEverything': false, + 'minimal': false, + 'isScriptContext': false, + 'quotes': 'single', + 'wrap': false, + 'es6': false, + 'json': false, + 'compact': true, + 'lowercaseHex': false, + 'numbers': 'decimal', + 'indent': '\t', + 'indentLevel': 0, + '__inline1__': false, + '__inline2__': false + }; + const json = options && options.json; + if (json) { + defaults.quotes = 'double'; + defaults.wrap = true; + } + options = extend(defaults, options); + if ( + options.quotes != 'single' && + options.quotes != 'double' && + options.quotes != 'backtick' + ) { + options.quotes = 'single'; + } + const quote = options.quotes == 'double' ? + '"' : + (options.quotes == 'backtick' ? + '`' : + '\'' + ); + const compact = options.compact; + const lowercaseHex = options.lowercaseHex; + let indent = options.indent.repeat(options.indentLevel); + let oldIndent = ''; + const inline1 = options.__inline1__; + const inline2 = options.__inline2__; + const newLine = compact ? '' : '\n'; + let result; + let isEmpty = true; + const useBinNumbers = options.numbers == 'binary'; + const useOctNumbers = options.numbers == 'octal'; + const useDecNumbers = options.numbers == 'decimal'; + const useHexNumbers = options.numbers == 'hexadecimal'; + + if (json && argument && isFunction(argument.toJSON)) { + argument = argument.toJSON(); + } + + if (!isString(argument)) { + if (isMap(argument)) { + if (argument.size == 0) { + return 'new Map()'; + } + if (!compact) { + options.__inline1__ = true; + options.__inline2__ = false; + } + return 'new Map(' + jsesc(Array.from(argument), options) + ')'; + } + if (isSet(argument)) { + if (argument.size == 0) { + return 'new Set()'; + } + return 'new Set(' + jsesc(Array.from(argument), options) + ')'; + } + if (isBuffer(argument)) { + if (argument.length == 0) { + return 'Buffer.from([])'; + } + return 'Buffer.from(' + jsesc(Array.from(argument), options) + ')'; + } + if (isArray(argument)) { + result = []; + options.wrap = true; + if (inline1) { + options.__inline1__ = false; + options.__inline2__ = true; + } + if (!inline2) { + increaseIndentation(); + } + forEach(argument, (value) => { + isEmpty = false; + if (inline2) { + options.__inline2__ = false; + } + result.push( + (compact || inline2 ? '' : indent) + + jsesc(value, options) + ); + }); + if (isEmpty) { + return '[]'; + } + if (inline2) { + return '[' + result.join(', ') + ']'; + } + return '[' + newLine + result.join(',' + newLine) + newLine + + (compact ? '' : oldIndent) + ']'; + } else if (isNumber(argument)) { + if (json) { + // Some number values (e.g. `Infinity`) cannot be represented in JSON. + return JSON.stringify(argument); + } + if (useDecNumbers) { + return String(argument); + } + if (useHexNumbers) { + let hexadecimal = argument.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + return '0x' + hexadecimal; + } + if (useBinNumbers) { + return '0b' + argument.toString(2); + } + if (useOctNumbers) { + return '0o' + argument.toString(8); + } + } else if (!isObject(argument)) { + if (json) { + // For some values (e.g. `undefined`, `function` objects), + // `JSON.stringify(value)` returns `undefined` (which isn’t valid + // JSON) instead of `'null'`. + return JSON.stringify(argument) || 'null'; + } + return String(argument); + } else { // it’s an object + result = []; + options.wrap = true; + increaseIndentation(); + forOwn(argument, (key, value) => { + isEmpty = false; + result.push( + (compact ? '' : indent) + + jsesc(key, options) + ':' + + (compact ? '' : ' ') + + jsesc(value, options) + ); + }); + if (isEmpty) { + return '{}'; + } + return '{' + newLine + result.join(',' + newLine) + newLine + + (compact ? '' : oldIndent) + '}'; + } + } + + const string = argument; + // Loop over each code unit in the string and escape it + let index = -1; + const length = string.length; + result = ''; + while (++index < length) { + const character = string.charAt(index); + if (options.es6) { + const first = string.charCodeAt(index); + if ( // check if it’s the start of a surrogate pair + first >= 0xD800 && first <= 0xDBFF && // high surrogate + length > index + 1 // there is a next code unit + ) { + const second = string.charCodeAt(index + 1); + if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + const codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; + let hexadecimal = codePoint.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + result += '\\u{' + hexadecimal + '}'; + ++index; + continue; + } + } + } + if (!options.escapeEverything) { + if (regexWhitelist.test(character)) { + // It’s a printable ASCII character that is not `"`, `'` or `\`, + // so don’t escape it. + result += character; + continue; + } + if (character == '"') { + result += quote == character ? '\\"' : character; + continue; + } + if (character == '`') { + result += quote == character ? '\\`' : character; + continue; + } + if (character == '\'') { + result += quote == character ? '\\\'' : character; + continue; + } + } + if ( + character == '\0' && + !json && + !regexDigit.test(string.charAt(index + 1)) + ) { + result += '\\0'; + continue; + } + if (regexSingleEscape.test(character)) { + // no need for a `hasOwnProperty` check here + result += singleEscapes[character]; + continue; + } + const charCode = character.charCodeAt(0); + if (options.minimal && charCode != 0x2028 && charCode != 0x2029) { + result += character; + continue; + } + let hexadecimal = charCode.toString(16); + if (!lowercaseHex) { + hexadecimal = hexadecimal.toUpperCase(); + } + const longhand = hexadecimal.length > 2 || json; + const escaped = '\\' + (longhand ? 'u' : 'x') + + ('0000' + hexadecimal).slice(longhand ? -4 : -2); + result += escaped; + continue; + } + if (options.wrap) { + result = quote + result + quote; + } + if (quote == '`') { + result = result.replace(/\$\{/g, '\\\$\{'); + } + if (options.isScriptContext) { + // https://mathiasbynens.be/notes/etago + return result + .replace(/<\/(script|style)/gi, '<\\/$1') + .replace(/' + + commentColor.close + ); + }; // Separate the functions to format props, children, and element, + // so a plugin could override a particular function, if needed. + // Too bad, so sad: the traditional (but unnecessary) space + // in a self-closing tagColor requires a second test of printedProps. + + markup.printComment = printComment; + + const printElement = ( + type, + printedProps, + printedChildren, + config, + indentation + ) => { + const tagColor = config.colors.tag; + return ( + tagColor.open + + '<' + + type + + (printedProps && + tagColor.close + + printedProps + + config.spacingOuter + + indentation + + tagColor.open) + + (printedChildren + ? '>' + + tagColor.close + + printedChildren + + config.spacingOuter + + indentation + + tagColor.open + + '' + + tagColor.close + ); + }; + + markup.printElement = printElement; + + const printElementAsLeaf = (type, config) => { + const tagColor = config.colors.tag; + return ( + tagColor.open + + '<' + + type + + tagColor.close + + ' …' + + tagColor.open + + ' />' + + tagColor.close + ); + }; + + markup.printElementAsLeaf = printElementAsLeaf; + return markup; +} + +var hasRequiredDOMElement; + +function requireDOMElement () { + if (hasRequiredDOMElement) return DOMElement; + hasRequiredDOMElement = 1; + + Object.defineProperty(DOMElement, '__esModule', { + value: true + }); + DOMElement.default = DOMElement.serialize = DOMElement.test = void 0; + + var _markup = requireMarkup(); + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + const ELEMENT_NODE = 1; + const TEXT_NODE = 3; + const COMMENT_NODE = 8; + const FRAGMENT_NODE = 11; + const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/; + + const testNode = (nodeType, name) => + (nodeType === ELEMENT_NODE && ELEMENT_REGEXP.test(name)) || + (nodeType === TEXT_NODE && name === 'Text') || + (nodeType === COMMENT_NODE && name === 'Comment') || + (nodeType === FRAGMENT_NODE && name === 'DocumentFragment'); + + const test = val => + val && + val.constructor && + val.constructor.name && + testNode(val.nodeType, val.constructor.name); + + DOMElement.test = test; + + function nodeIsText(node) { + return node.nodeType === TEXT_NODE; + } + + function nodeIsComment(node) { + return node.nodeType === COMMENT_NODE; + } + + function nodeIsFragment(node) { + return node.nodeType === FRAGMENT_NODE; + } + + const serialize = (node, config, indentation, depth, refs, printer) => { + if (nodeIsText(node)) { + return (0, _markup.printText)(node.data, config); + } + + if (nodeIsComment(node)) { + return (0, _markup.printComment)(node.data, config); + } + + const type = nodeIsFragment(node) + ? `DocumentFragment` + : node.tagName.toLowerCase(); + + if (++depth > config.maxDepth) { + return (0, _markup.printElementAsLeaf)(type, config); + } + + return (0, _markup.printElement)( + type, + (0, _markup.printProps)( + nodeIsFragment(node) + ? [] + : Array.from(node.attributes) + .map(attr => attr.name) + .sort(), + nodeIsFragment(node) + ? [] + : Array.from(node.attributes).reduce((props, attribute) => { + props[attribute.name] = attribute.value; + return props; + }, {}), + config, + indentation + config.indent, + depth, + refs, + printer + ), + (0, _markup.printChildren)( + Array.prototype.slice.call(node.childNodes || node.children), + config, + indentation + config.indent, + depth, + refs, + printer + ), + config, + indentation + ); + }; + + DOMElement.serialize = serialize; + const plugin = { + serialize, + test + }; + var _default = plugin; + DOMElement.default = _default; + return DOMElement; +} + +var Immutable = {}; + +var hasRequiredImmutable; + +function requireImmutable () { + if (hasRequiredImmutable) return Immutable; + hasRequiredImmutable = 1; + + Object.defineProperty(Immutable, '__esModule', { + value: true + }); + Immutable.default = Immutable.test = Immutable.serialize = void 0; + + var _collections = requireCollections(); + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + // SENTINEL constants are from https://github.com/facebook/immutable-js + const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; + const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@'; + const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; + const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@'; + const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@'; + const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // immutable v4 + + const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@'; + const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@'; + const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@'; + + const getImmutableName = name => 'Immutable.' + name; + + const printAsLeaf = name => '[' + name + ']'; + + const SPACE = ' '; + const LAZY = '…'; // Seq is lazy if it calls a method like filter + + const printImmutableEntries = ( + val, + config, + indentation, + depth, + refs, + printer, + type + ) => + ++depth > config.maxDepth + ? printAsLeaf(getImmutableName(type)) + : getImmutableName(type) + + SPACE + + '{' + + (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer + ) + + '}'; // Record has an entries method because it is a collection in immutable v3. + // Return an iterator for Immutable Record from version v3 or v4. + + const getRecordEntries = val => { + let i = 0; + return { + next() { + if (i < val._keys.length) { + const key = val._keys[i++]; + return { + done: false, + value: [key, val.get(key)] + }; + } + + return { + done: true + }; + } + }; + }; + + const printImmutableRecord = ( + val, + config, + indentation, + depth, + refs, + printer + ) => { + // _name property is defined only for an Immutable Record instance + // which was constructed with a second optional descriptive name arg + const name = getImmutableName(val._name || 'Record'); + return ++depth > config.maxDepth + ? printAsLeaf(name) + : name + + SPACE + + '{' + + (0, _collections.printIteratorEntries)( + getRecordEntries(val), + config, + indentation, + depth, + refs, + printer + ) + + '}'; + }; + + const printImmutableSeq = (val, config, indentation, depth, refs, printer) => { + const name = getImmutableName('Seq'); + + if (++depth > config.maxDepth) { + return printAsLeaf(name); + } + + if (val[IS_KEYED_SENTINEL]) { + return ( + name + + SPACE + + '{' + // from Immutable collection of entries or from ECMAScript object + (val._iter || val._object + ? (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer + ) + : LAZY) + + '}' + ); + } + + return ( + name + + SPACE + + '[' + + (val._iter || // from Immutable collection of values + val._array || // from ECMAScript array + val._collection || // from ECMAScript collection in immutable v4 + val._iterable // from ECMAScript collection in immutable v3 + ? (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + : LAZY) + + ']' + ); + }; + + const printImmutableValues = ( + val, + config, + indentation, + depth, + refs, + printer, + type + ) => + ++depth > config.maxDepth + ? printAsLeaf(getImmutableName(type)) + : getImmutableName(type) + + SPACE + + '[' + + (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + + ']'; + + const serialize = (val, config, indentation, depth, refs, printer) => { + if (val[IS_MAP_SENTINEL]) { + return printImmutableEntries( + val, + config, + indentation, + depth, + refs, + printer, + val[IS_ORDERED_SENTINEL] ? 'OrderedMap' : 'Map' + ); + } + + if (val[IS_LIST_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + 'List' + ); + } + + if (val[IS_SET_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + val[IS_ORDERED_SENTINEL] ? 'OrderedSet' : 'Set' + ); + } + + if (val[IS_STACK_SENTINEL]) { + return printImmutableValues( + val, + config, + indentation, + depth, + refs, + printer, + 'Stack' + ); + } + + if (val[IS_SEQ_SENTINEL]) { + return printImmutableSeq(val, config, indentation, depth, refs, printer); + } // For compatibility with immutable v3 and v4, let record be the default. + + return printImmutableRecord(val, config, indentation, depth, refs, printer); + }; // Explicitly comparing sentinel properties to true avoids false positive + // when mock identity-obj-proxy returns the key as the value for any key. + + Immutable.serialize = serialize; + + const test = val => + val && + (val[IS_ITERABLE_SENTINEL] === true || val[IS_RECORD_SENTINEL] === true); + + Immutable.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + Immutable.default = _default; + return Immutable; +} + +var ReactElement = {}; + +var reactIsExports = {}; +var reactIs = { + get exports(){ return reactIsExports; }, + set exports(v){ reactIsExports = v; }, +}; + +var reactIs_production_min = {}; + +var hasRequiredReactIs_production_min; + +function requireReactIs_production_min () { + if (hasRequiredReactIs_production_min) return reactIs_production_min; + hasRequiredReactIs_production_min = 1; +var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b? + Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119; + function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}reactIs_production_min.AsyncMode=l;reactIs_production_min.ConcurrentMode=m;reactIs_production_min.ContextConsumer=k;reactIs_production_min.ContextProvider=h;reactIs_production_min.Element=c;reactIs_production_min.ForwardRef=n;reactIs_production_min.Fragment=e;reactIs_production_min.Lazy=t;reactIs_production_min.Memo=r;reactIs_production_min.Portal=d; + reactIs_production_min.Profiler=g;reactIs_production_min.StrictMode=f;reactIs_production_min.Suspense=p;reactIs_production_min.isAsyncMode=function(a){return A(a)||z(a)===l};reactIs_production_min.isConcurrentMode=A;reactIs_production_min.isContextConsumer=function(a){return z(a)===k};reactIs_production_min.isContextProvider=function(a){return z(a)===h};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};reactIs_production_min.isForwardRef=function(a){return z(a)===n};reactIs_production_min.isFragment=function(a){return z(a)===e};reactIs_production_min.isLazy=function(a){return z(a)===t}; + reactIs_production_min.isMemo=function(a){return z(a)===r};reactIs_production_min.isPortal=function(a){return z(a)===d};reactIs_production_min.isProfiler=function(a){return z(a)===g};reactIs_production_min.isStrictMode=function(a){return z(a)===f};reactIs_production_min.isSuspense=function(a){return z(a)===p}; + reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};reactIs_production_min.typeOf=z; + return reactIs_production_min; +} + +var hasRequiredReactIs; + +function requireReactIs () { + if (hasRequiredReactIs) return reactIsExports; + hasRequiredReactIs = 1; + (function (module) { + + { + module.exports = requireReactIs_production_min(); + } +} (reactIs)); + return reactIsExports; +} + +var hasRequiredReactElement; + +function requireReactElement () { + if (hasRequiredReactElement) return ReactElement; + hasRequiredReactElement = 1; + + Object.defineProperty(ReactElement, '__esModule', { + value: true + }); + ReactElement.default = ReactElement.test = ReactElement.serialize = void 0; + + var ReactIs = _interopRequireWildcard(requireReactIs()); + + var _markup = requireMarkup(); + + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = + Object.defineProperty && Object.getOwnPropertyDescriptor + ? Object.getOwnPropertyDescriptor(obj, key) + : {}; + if (desc.get || desc.set) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + } + newObj.default = obj; + return newObj; + } + } + + /** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + // Given element.props.children, or subtree during recursive traversal, + // return flattened array of children. + const getChildren = (arg, children = []) => { + if (Array.isArray(arg)) { + arg.forEach(item => { + getChildren(item, children); + }); + } else if (arg != null && arg !== false) { + children.push(arg); + } + + return children; + }; + + const getType = element => { + const type = element.type; + + if (typeof type === 'string') { + return type; + } + + if (typeof type === 'function') { + return type.displayName || type.name || 'Unknown'; + } + + if (ReactIs.isFragment(element)) { + return 'React.Fragment'; + } + + if (ReactIs.isSuspense(element)) { + return 'React.Suspense'; + } + + if (typeof type === 'object' && type !== null) { + if (ReactIs.isContextProvider(element)) { + return 'Context.Provider'; + } + + if (ReactIs.isContextConsumer(element)) { + return 'Context.Consumer'; + } + + if (ReactIs.isForwardRef(element)) { + const functionName = type.render.displayName || type.render.name || ''; + return functionName !== '' + ? 'ForwardRef(' + functionName + ')' + : 'ForwardRef'; + } + + if (ReactIs.isMemo(type)) { + const functionName = + type.displayName || type.type.displayName || type.type.name || ''; + return functionName !== '' ? 'Memo(' + functionName + ')' : 'Memo'; + } + } + + return 'UNDEFINED'; + }; + + const getPropKeys = element => { + const props = element.props; + return Object.keys(props) + .filter(key => key !== 'children' && props[key] !== undefined) + .sort(); + }; + + const serialize = (element, config, indentation, depth, refs, printer) => + ++depth > config.maxDepth + ? (0, _markup.printElementAsLeaf)(getType(element), config) + : (0, _markup.printElement)( + getType(element), + (0, _markup.printProps)( + getPropKeys(element), + element.props, + config, + indentation + config.indent, + depth, + refs, + printer + ), + (0, _markup.printChildren)( + getChildren(element.props.children), + config, + indentation + config.indent, + depth, + refs, + printer + ), + config, + indentation + ); + + ReactElement.serialize = serialize; + + const test = val => val && ReactIs.isElement(val); + + ReactElement.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + ReactElement.default = _default; + return ReactElement; +} + +var ReactTestComponent = {}; + +var hasRequiredReactTestComponent; + +function requireReactTestComponent () { + if (hasRequiredReactTestComponent) return ReactTestComponent; + hasRequiredReactTestComponent = 1; + + Object.defineProperty(ReactTestComponent, '__esModule', { + value: true + }); + ReactTestComponent.default = ReactTestComponent.test = ReactTestComponent.serialize = void 0; + + var _markup = requireMarkup(); + + var Symbol = commonjsGlobal['jest-symbol-do-not-touch'] || commonjsGlobal.Symbol; + const testSymbol = Symbol.for('react.test.json'); + + const getPropKeys = object => { + const props = object.props; + return props + ? Object.keys(props) + .filter(key => props[key] !== undefined) + .sort() + : []; + }; + + const serialize = (object, config, indentation, depth, refs, printer) => + ++depth > config.maxDepth + ? (0, _markup.printElementAsLeaf)(object.type, config) + : (0, _markup.printElement)( + object.type, + object.props + ? (0, _markup.printProps)( + getPropKeys(object), + object.props, + config, + indentation + config.indent, + depth, + refs, + printer + ) + : '', + object.children + ? (0, _markup.printChildren)( + object.children, + config, + indentation + config.indent, + depth, + refs, + printer + ) + : '', + config, + indentation + ); + + ReactTestComponent.serialize = serialize; + + const test = val => val && val.$$typeof === testSymbol; + + ReactTestComponent.test = test; + const plugin = { + serialize, + test + }; + var _default = plugin; + ReactTestComponent.default = _default; + return ReactTestComponent; +} + +var build; +var hasRequiredBuild; + +function requireBuild () { + if (hasRequiredBuild) return build; + hasRequiredBuild = 1; + + var _ansiStyles = _interopRequireDefault(requireAnsiStyles()); + + var _collections = requireCollections(); + + var _AsymmetricMatcher = _interopRequireDefault( + requireAsymmetricMatcher() + ); + + var _ConvertAnsi = _interopRequireDefault(requireConvertAnsi()); + + var _DOMCollection = _interopRequireDefault(requireDOMCollection()); + + var _DOMElement = _interopRequireDefault(requireDOMElement()); + + var _Immutable = _interopRequireDefault(requireImmutable()); + + var _ReactElement = _interopRequireDefault(requireReactElement()); + + var _ReactTestComponent = _interopRequireDefault( + requireReactTestComponent() + ); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : {default: obj}; + } + + var Symbol = commonjsGlobal['jest-symbol-do-not-touch'] || commonjsGlobal.Symbol; + const toString = Object.prototype.toString; + const toISOString = Date.prototype.toISOString; + const errorToString = Error.prototype.toString; + const regExpToString = RegExp.prototype.toString; + const symbolToString = Symbol.prototype.toString; + /** + * Explicitly comparing typeof constructor to function avoids undefined as name + * when mock identity-obj-proxy returns the key as the value for any key. + */ + + const getConstructorName = val => + (typeof val.constructor === 'function' && val.constructor.name) || 'Object'; + /* global window */ + + /** Is val is equal to global window object? Works even if it does not exist :) */ + + const isWindow = val => typeof window !== 'undefined' && val === window; + + const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; + const NEWLINE_REGEXP = /\n/gi; + + class PrettyFormatPluginError extends Error { + constructor(message, stack) { + super(message); + this.stack = stack; + this.name = this.constructor.name; + } + } + + function isToStringedArrayType(toStringed) { + return ( + toStringed === '[object Array]' || + toStringed === '[object ArrayBuffer]' || + toStringed === '[object DataView]' || + toStringed === '[object Float32Array]' || + toStringed === '[object Float64Array]' || + toStringed === '[object Int8Array]' || + toStringed === '[object Int16Array]' || + toStringed === '[object Int32Array]' || + toStringed === '[object Uint8Array]' || + toStringed === '[object Uint8ClampedArray]' || + toStringed === '[object Uint16Array]' || + toStringed === '[object Uint32Array]' + ); + } + + function printNumber(val) { + return Object.is(val, -0) ? '-0' : String(val); + } + + function printBigInt(val) { + return String(`${val}n`); + } + + function printFunction(val, printFunctionName) { + if (!printFunctionName) { + return '[Function]'; + } + + return '[Function ' + (val.name || 'anonymous') + ']'; + } + + function printSymbol(val) { + return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); + } + + function printError(val) { + return '[' + errorToString.call(val) + ']'; + } + /** + * The first port of call for printing an object, handles most of the + * data-types in JS. + */ + + function printBasicValue(val, printFunctionName, escapeRegex, escapeString) { + if (val === true || val === false) { + return '' + val; + } + + if (val === undefined) { + return 'undefined'; + } + + if (val === null) { + return 'null'; + } + + const typeOf = typeof val; + + if (typeOf === 'number') { + return printNumber(val); + } + + if (typeOf === 'bigint') { + return printBigInt(val); + } + + if (typeOf === 'string') { + if (escapeString) { + return '"' + val.replace(/"|\\/g, '\\$&') + '"'; + } + + return '"' + val + '"'; + } + + if (typeOf === 'function') { + return printFunction(val, printFunctionName); + } + + if (typeOf === 'symbol') { + return printSymbol(val); + } + + const toStringed = toString.call(val); + + if (toStringed === '[object WeakMap]') { + return 'WeakMap {}'; + } + + if (toStringed === '[object WeakSet]') { + return 'WeakSet {}'; + } + + if ( + toStringed === '[object Function]' || + toStringed === '[object GeneratorFunction]' + ) { + return printFunction(val, printFunctionName); + } + + if (toStringed === '[object Symbol]') { + return printSymbol(val); + } + + if (toStringed === '[object Date]') { + return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val); + } + + if (toStringed === '[object Error]') { + return printError(val); + } + + if (toStringed === '[object RegExp]') { + if (escapeRegex) { + // https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js + return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); + } + + return regExpToString.call(val); + } + + if (val instanceof Error) { + return printError(val); + } + + return null; + } + /** + * Handles more complex objects ( such as objects with circular references. + * maps and sets etc ) + */ + + function printComplexValue( + val, + config, + indentation, + depth, + refs, + hasCalledToJSON + ) { + if (refs.indexOf(val) !== -1) { + return '[Circular]'; + } + + refs = refs.slice(); + refs.push(val); + const hitMaxDepth = ++depth > config.maxDepth; + const min = config.min; + + if ( + config.callToJSON && + !hitMaxDepth && + val.toJSON && + typeof val.toJSON === 'function' && + !hasCalledToJSON + ) { + return printer(val.toJSON(), config, indentation, depth, refs, true); + } + + const toStringed = toString.call(val); + + if (toStringed === '[object Arguments]') { + return hitMaxDepth + ? '[Arguments]' + : (min ? '' : 'Arguments ') + + '[' + + (0, _collections.printListItems)( + val, + config, + indentation, + depth, + refs, + printer + ) + + ']'; + } + + if (isToStringedArrayType(toStringed)) { + return hitMaxDepth + ? '[' + val.constructor.name + ']' + : (min ? '' : val.constructor.name + ' ') + + '[' + + (0, _collections.printListItems)( + val, + config, + indentation, + depth, + refs, + printer + ) + + ']'; + } + + if (toStringed === '[object Map]') { + return hitMaxDepth + ? '[Map]' + : 'Map {' + + (0, _collections.printIteratorEntries)( + val.entries(), + config, + indentation, + depth, + refs, + printer, + ' => ' + ) + + '}'; + } + + if (toStringed === '[object Set]') { + return hitMaxDepth + ? '[Set]' + : 'Set {' + + (0, _collections.printIteratorValues)( + val.values(), + config, + indentation, + depth, + refs, + printer + ) + + '}'; + } // Avoid failure to serialize global window object in jsdom test environment. + // For example, not even relevant if window is prop of React element. + + return hitMaxDepth || isWindow(val) + ? '[' + getConstructorName(val) + ']' + : (min ? '' : getConstructorName(val) + ' ') + + '{' + + (0, _collections.printObjectProperties)( + val, + config, + indentation, + depth, + refs, + printer + ) + + '}'; + } + + function isNewPlugin(plugin) { + return plugin.serialize != null; + } + + function printPlugin(plugin, val, config, indentation, depth, refs) { + let printed; + + try { + printed = isNewPlugin(plugin) + ? plugin.serialize(val, config, indentation, depth, refs, printer) + : plugin.print( + val, + valChild => printer(valChild, config, indentation, depth, refs), + str => { + const indentationNext = indentation + config.indent; + return ( + indentationNext + + str.replace(NEWLINE_REGEXP, '\n' + indentationNext) + ); + }, + { + edgeSpacing: config.spacingOuter, + min: config.min, + spacing: config.spacingInner + }, + config.colors + ); + } catch (error) { + throw new PrettyFormatPluginError(error.message, error.stack); + } + + if (typeof printed !== 'string') { + throw new Error( + `pretty-format: Plugin must return type "string" but instead returned "${typeof printed}".` + ); + } + + return printed; + } + + function findPlugin(plugins, val) { + for (let p = 0; p < plugins.length; p++) { + try { + if (plugins[p].test(val)) { + return plugins[p]; + } + } catch (error) { + throw new PrettyFormatPluginError(error.message, error.stack); + } + } + + return null; + } + + function printer(val, config, indentation, depth, refs, hasCalledToJSON) { + const plugin = findPlugin(config.plugins, val); + + if (plugin !== null) { + return printPlugin(plugin, val, config, indentation, depth, refs); + } + + const basicResult = printBasicValue( + val, + config.printFunctionName, + config.escapeRegex, + config.escapeString + ); + + if (basicResult !== null) { + return basicResult; + } + + return printComplexValue( + val, + config, + indentation, + depth, + refs, + hasCalledToJSON + ); + } + + const DEFAULT_THEME = { + comment: 'gray', + content: 'reset', + prop: 'yellow', + tag: 'cyan', + value: 'green' + }; + const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME); + const DEFAULT_OPTIONS = { + callToJSON: true, + escapeRegex: false, + escapeString: true, + highlight: false, + indent: 2, + maxDepth: Infinity, + min: false, + plugins: [], + printFunctionName: true, + theme: DEFAULT_THEME + }; + + function validateOptions(options) { + Object.keys(options).forEach(key => { + if (!DEFAULT_OPTIONS.hasOwnProperty(key)) { + throw new Error(`pretty-format: Unknown option "${key}".`); + } + }); + + if (options.min && options.indent !== undefined && options.indent !== 0) { + throw new Error( + 'pretty-format: Options "min" and "indent" cannot be used together.' + ); + } + + if (options.theme !== undefined) { + if (options.theme === null) { + throw new Error(`pretty-format: Option "theme" must not be null.`); + } + + if (typeof options.theme !== 'object') { + throw new Error( + `pretty-format: Option "theme" must be of type "object" but instead received "${typeof options.theme}".` + ); + } + } + } + + const getColorsHighlight = options => + DEFAULT_THEME_KEYS.reduce((colors, key) => { + const value = + options.theme && options.theme[key] !== undefined + ? options.theme[key] + : DEFAULT_THEME[key]; + const color = value && _ansiStyles.default[value]; + + if ( + color && + typeof color.close === 'string' && + typeof color.open === 'string' + ) { + colors[key] = color; + } else { + throw new Error( + `pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.` + ); + } + + return colors; + }, Object.create(null)); + + const getColorsEmpty = () => + DEFAULT_THEME_KEYS.reduce((colors, key) => { + colors[key] = { + close: '', + open: '' + }; + return colors; + }, Object.create(null)); + + const getPrintFunctionName = options => + options && options.printFunctionName !== undefined + ? options.printFunctionName + : DEFAULT_OPTIONS.printFunctionName; + + const getEscapeRegex = options => + options && options.escapeRegex !== undefined + ? options.escapeRegex + : DEFAULT_OPTIONS.escapeRegex; + + const getEscapeString = options => + options && options.escapeString !== undefined + ? options.escapeString + : DEFAULT_OPTIONS.escapeString; + + const getConfig = options => ({ + callToJSON: + options && options.callToJSON !== undefined + ? options.callToJSON + : DEFAULT_OPTIONS.callToJSON, + colors: + options && options.highlight + ? getColorsHighlight(options) + : getColorsEmpty(), + escapeRegex: getEscapeRegex(options), + escapeString: getEscapeString(options), + indent: + options && options.min + ? '' + : createIndent( + options && options.indent !== undefined + ? options.indent + : DEFAULT_OPTIONS.indent + ), + maxDepth: + options && options.maxDepth !== undefined + ? options.maxDepth + : DEFAULT_OPTIONS.maxDepth, + min: options && options.min !== undefined ? options.min : DEFAULT_OPTIONS.min, + plugins: + options && options.plugins !== undefined + ? options.plugins + : DEFAULT_OPTIONS.plugins, + printFunctionName: getPrintFunctionName(options), + spacingInner: options && options.min ? ' ' : '\n', + spacingOuter: options && options.min ? '' : '\n' + }); + + function createIndent(indent) { + return new Array(indent + 1).join(' '); + } + /** + * Returns a presentation string of your `val` object + * @param val any potential JavaScript object + * @param options Custom settings + */ + + function prettyFormat(val, options) { + if (options) { + validateOptions(options); + + if (options.plugins) { + const plugin = findPlugin(options.plugins, val); + + if (plugin !== null) { + return printPlugin(plugin, val, getConfig(options), '', 0, []); + } + } + } + + const basicResult = printBasicValue( + val, + getPrintFunctionName(options), + getEscapeRegex(options), + getEscapeString(options) + ); + + if (basicResult !== null) { + return basicResult; + } + + return printComplexValue(val, getConfig(options), '', 0, []); + } + + prettyFormat.plugins = { + AsymmetricMatcher: _AsymmetricMatcher.default, + ConvertAnsi: _ConvertAnsi.default, + DOMCollection: _DOMCollection.default, + DOMElement: _DOMElement.default, + Immutable: _Immutable.default, + ReactElement: _ReactElement.default, + ReactTestComponent: _ReactTestComponent.default + }; + /* eslint-disable-next-line no-redeclare */ + + build = prettyFormat; + return build; +} + +var buildExports = requireBuild(); +var prettyFormat = /*@__PURE__*/getDefaultExportFromCjs(buildExports); + +var _PostDominator_exit, _PostDominator_nodes; +function computePostDominatorTree(fn, options) { + const graph = buildReverseGraph(fn, options.includeThrowsAsExitNode); + const nodes = computeImmediateDominators(graph); + if (!options.includeThrowsAsExitNode) { + for (const [id] of fn.body.blocks) { + if (!nodes.has(id)) { + nodes.set(id, id); + } + } + } + return new PostDominator(graph.entry, nodes); +} +class PostDominator { + constructor(exit, nodes) { + _PostDominator_exit.set(this, void 0); + _PostDominator_nodes.set(this, void 0); + __classPrivateFieldSet(this, _PostDominator_exit, exit, "f"); + __classPrivateFieldSet(this, _PostDominator_nodes, nodes, "f"); + } + get exit() { + return __classPrivateFieldGet(this, _PostDominator_exit, "f"); + } + get(id) { + const dominator = __classPrivateFieldGet(this, _PostDominator_nodes, "f").get(id); + CompilerError.invariant(dominator !== undefined, { + reason: 'Unknown node', + description: null, + loc: null, + suggestions: null, + }); + return dominator === id ? null : dominator; + } + debug() { + const postDominators = new Map(); + for (const [key, value] of __classPrivateFieldGet(this, _PostDominator_nodes, "f")) { + postDominators.set(`bb${key}`, `bb${value}`); + } + return prettyFormat({ + exit: `bb${this.exit}`, + postDominators, + }); + } +} +_PostDominator_exit = new WeakMap(), _PostDominator_nodes = new WeakMap(); +function computeImmediateDominators(graph) { + const nodes = new Map(); + nodes.set(graph.entry, graph.entry); + let changed = true; + while (changed) { + changed = false; + for (const [id, node] of graph.nodes) { + if (node.id === graph.entry) { + continue; + } + let newIdom = null; + for (const pred of node.preds) { + if (nodes.has(pred)) { + newIdom = pred; + break; + } + } + CompilerError.invariant(newIdom !== null, { + reason: `At least one predecessor must have been visited for block ${id}`, + description: null, + loc: null, + suggestions: null, + }); + for (const pred of node.preds) { + if (pred === newIdom) { + continue; + } + const predDom = nodes.get(pred); + if (predDom !== undefined) { + newIdom = intersect(pred, newIdom, graph, nodes); + } + } + if (nodes.get(id) !== newIdom) { + nodes.set(id, newIdom); + changed = true; + } + } + } + return nodes; +} +function intersect(a, b, graph, nodes) { + let block1 = graph.nodes.get(a); + let block2 = graph.nodes.get(b); + while (block1 !== block2) { + while (block1.index > block2.index) { + const dom = nodes.get(block1.id); + block1 = graph.nodes.get(dom); + } + while (block2.index > block1.index) { + const dom = nodes.get(block2.id); + block2 = graph.nodes.get(dom); + } + } + return block1.id; +} +function buildReverseGraph(fn, includeThrowsAsExitNode) { + const nodes = new Map(); + const exitId = fn.env.nextBlockId; + const exit = { + id: exitId, + index: 0, + preds: new Set(), + succs: new Set(), + }; + nodes.set(exitId, exit); + for (const [id, block] of fn.body.blocks) { + const node = { + id, + index: 0, + preds: new Set(eachTerminalSuccessor(block.terminal)), + succs: new Set(block.preds), + }; + if (block.terminal.kind === 'return') { + node.preds.add(exitId); + exit.succs.add(id); + } + else if (block.terminal.kind === 'throw' && includeThrowsAsExitNode) { + node.preds.add(exitId); + exit.succs.add(id); + } + nodes.set(id, node); + } + const visited = new Set(); + const postorder = []; + function visit(id) { + if (visited.has(id)) { + return; + } + visited.add(id); + const node = nodes.get(id); + for (const successor of node.succs) { + visit(successor); + } + postorder.push(id); + } + visit(exitId); + const rpo = { entry: exitId, nodes: new Map() }; + let index = 0; + for (const id of postorder.reverse()) { + const node = nodes.get(id); + node.index = index++; + rpo.nodes.set(id, node); + } + return rpo; +} + +const DEFAULT_SHAPES = new Map(BUILTIN_SHAPES); +const UNTYPED_GLOBALS = new Set([ + 'Object', + 'Function', + 'RegExp', + 'Date', + 'Error', + 'TypeError', + 'RangeError', + 'ReferenceError', + 'SyntaxError', + 'URIError', + 'EvalError', + 'DataView', + 'Float32Array', + 'Float64Array', + 'Int8Array', + 'Int16Array', + 'Int32Array', + 'WeakMap', + 'Uint8Array', + 'Uint8ClampedArray', + 'Uint16Array', + 'Uint32Array', + 'ArrayBuffer', + 'JSON', + 'console', + 'eval', +]); +const TYPED_GLOBALS = [ + [ + 'Object', + addObject(DEFAULT_SHAPES, 'Object', [ + [ + 'keys', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.Read], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'fromEntries', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutate], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInObjectId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), + ], + [ + 'Array', + addObject(DEFAULT_SHAPES, 'Array', [ + [ + 'isArray', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.Read], + restParam: null, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'from', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [ + Effect.ConditionallyMutateIterator, + Effect.ConditionallyMutate, + Effect.ConditionallyMutate, + ], + restParam: Effect.Read, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'of', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Object', shapeId: BuiltInArrayId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), + ], + [ + 'performance', + addObject(DEFAULT_SHAPES, 'performance', [ + [ + 'now', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'performance.now', + }), + ], + ]), + ], + [ + 'Date', + addObject(DEFAULT_SHAPES, 'Date', [ + [ + 'now', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'Date.now', + }), + ], + ]), + ], + [ + 'Math', + addObject(DEFAULT_SHAPES, 'Math', [ + ['PI', { kind: 'Primitive' }], + [ + 'max', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'min', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'trunc', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'ceil', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'floor', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'pow', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'random', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + impure: true, + canonicalName: 'Math.random', + }), + ], + ]), + ], + ['Infinity', { kind: 'Primitive' }], + ['NaN', { kind: 'Primitive' }], + [ + 'console', + addObject(DEFAULT_SHAPES, 'console', [ + [ + 'error', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'info', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'log', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'table', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'trace', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'warn', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + ]), + ], + [ + 'Boolean', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'Number', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'String', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'parseInt', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'parseFloat', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'isNaN', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'isFinite', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'encodeURI', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'encodeURIComponent', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'decodeURI', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'decodeURIComponent', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Primitive, + }), + ], + [ + 'Map', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutateIterator], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInMapId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }, null, true), + ], + [ + 'Set', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [Effect.ConditionallyMutateIterator], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInSetId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }, null, true), + ], +]; +const REACT_APIS = [ + [ + 'useContext', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useContext', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.Context, + }, BuiltInUseContextHookId), + ], + [ + 'useState', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseStateId }, + calleeEffect: Effect.Read, + hookKind: 'useState', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.State, + }), + ], + [ + 'useActionState', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseActionStateId }, + calleeEffect: Effect.Read, + hookKind: 'useActionState', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.State, + }), + ], + [ + 'useReducer', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Object', shapeId: BuiltInUseReducerId }, + calleeEffect: Effect.Read, + hookKind: 'useReducer', + returnValueKind: ValueKind.Frozen, + returnValueReason: ValueReason.ReducerState, + }), + ], + [ + 'useRef', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Capture, + returnType: { kind: 'Object', shapeId: BuiltInUseRefId }, + calleeEffect: Effect.Read, + hookKind: 'useRef', + returnValueKind: ValueKind.Mutable, + }), + ], + [ + 'useImperativeHandle', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + hookKind: 'useImperativeHandle', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useMemo', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useMemo', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useCallback', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useCallback', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'useEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Primitive' }, + calleeEffect: Effect.Read, + hookKind: 'useEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseEffectHookId), + ], + [ + 'useLayoutEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useLayoutEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseLayoutEffectHookId), + ], + [ + 'useInsertionEffect', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + hookKind: 'useInsertionEffect', + returnValueKind: ValueKind.Frozen, + }, BuiltInUseInsertionEffectHookId), + ], + [ + 'useTransition', + addHook(DEFAULT_SHAPES, { + positionalParams: [], + restParam: null, + returnType: { kind: 'Object', shapeId: BuiltInUseTransitionId }, + calleeEffect: Effect.Read, + hookKind: 'useTransition', + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'use', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }, BuiltInUseOperatorId), + ], + [ + 'fire', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: null, + returnType: { + kind: 'Function', + return: { kind: 'Poly' }, + shapeId: BuiltInFireFunctionId, + isConstructor: false, + }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }, BuiltInFireId), + ], +]; +TYPED_GLOBALS.push([ + 'React', + addObject(DEFAULT_SHAPES, null, [ + ...REACT_APIS, + [ + 'createElement', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'cloneElement', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), + ], + [ + 'createRef', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Capture, + returnType: { kind: 'Object', shapeId: BuiltInUseRefId }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + }), + ], + ]), +], [ + '_jsx', + addFunction(DEFAULT_SHAPES, [], { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Frozen, + }), +]); +const DEFAULT_GLOBALS = new Map(REACT_APIS); +for (const name of UNTYPED_GLOBALS) { + DEFAULT_GLOBALS.set(name, { + kind: 'Poly', + }); +} +for (const [name, type_] of TYPED_GLOBALS) { + DEFAULT_GLOBALS.set(name, type_); +} +DEFAULT_GLOBALS.set('globalThis', addObject(DEFAULT_SHAPES, 'globalThis', TYPED_GLOBALS)); +DEFAULT_GLOBALS.set('global', addObject(DEFAULT_SHAPES, 'global', TYPED_GLOBALS)); +function installTypeConfig(globals, shapes, typeConfig, moduleName, loc) { + var _a, _b, _c, _d; + switch (typeConfig.kind) { + case 'type': { + switch (typeConfig.name) { + case 'Array': { + return { kind: 'Object', shapeId: BuiltInArrayId }; + } + case 'MixedReadonly': { + return { kind: 'Object', shapeId: BuiltInMixedReadonlyId }; + } + case 'Primitive': { + return { kind: 'Primitive' }; + } + case 'Ref': { + return { kind: 'Object', shapeId: BuiltInUseRefId }; + } + case 'Any': { + return { kind: 'Poly' }; + } + default: { + assertExhaustive$1(typeConfig.name, `Unexpected type '${typeConfig.name}'`); + } + } + } + case 'function': { + return addFunction(shapes, [], { + positionalParams: typeConfig.positionalParams, + restParam: typeConfig.restParam, + calleeEffect: typeConfig.calleeEffect, + returnType: installTypeConfig(globals, shapes, typeConfig.returnType, moduleName, loc), + returnValueKind: typeConfig.returnValueKind, + noAlias: typeConfig.noAlias === true, + mutableOnlyIfOperandsAreMutable: typeConfig.mutableOnlyIfOperandsAreMutable === true, + }); + } + case 'hook': { + return addHook(shapes, { + hookKind: 'Custom', + positionalParams: (_a = typeConfig.positionalParams) !== null && _a !== void 0 ? _a : [], + restParam: (_b = typeConfig.restParam) !== null && _b !== void 0 ? _b : Effect.Freeze, + calleeEffect: Effect.Read, + returnType: installTypeConfig(globals, shapes, typeConfig.returnType, moduleName, loc), + returnValueKind: (_c = typeConfig.returnValueKind) !== null && _c !== void 0 ? _c : ValueKind.Frozen, + noAlias: typeConfig.noAlias === true, + }); + } + case 'object': { + return addObject(shapes, null, Object.entries((_d = typeConfig.properties) !== null && _d !== void 0 ? _d : {}).map(([key, value]) => { + var _a; + const type = installTypeConfig(globals, shapes, value, moduleName, loc); + const expectHook = isHookName$2(key); + let isHook = false; + if (type.kind === 'Function' && type.shapeId !== null) { + const functionType = shapes.get(type.shapeId); + if (((_a = functionType === null || functionType === void 0 ? void 0 : functionType.functionType) === null || _a === void 0 ? void 0 : _a.hookKind) !== null) { + isHook = true; + } + } + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for object property '${key}' from module '${moduleName}' ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the property name`, + loc, + }); + } + return [key, type]; + })); + } + default: { + assertExhaustive$1(typeConfig, `Unexpected type kind '${typeConfig.kind}'`); + } + } +} +function getReanimatedModuleType(registry) { + const frozenHooks = [ + 'useFrameCallback', + 'useAnimatedStyle', + 'useAnimatedProps', + 'useAnimatedScrollHandler', + 'useAnimatedReaction', + 'useWorkletCallback', + ]; + const reanimatedType = []; + for (const hook of frozenHooks) { + reanimatedType.push([ + hook, + addHook(registry, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + returnValueKind: ValueKind.Frozen, + noAlias: true, + calleeEffect: Effect.Read, + hookKind: 'Custom', + }), + ]); + } + const mutableHooks = ['useSharedValue', 'useDerivedValue']; + for (const hook of mutableHooks) { + reanimatedType.push([ + hook, + addHook(registry, { + positionalParams: [], + restParam: Effect.Freeze, + returnType: { kind: 'Poly' }, + returnValueKind: ValueKind.Mutable, + noAlias: true, + calleeEffect: Effect.Read, + hookKind: 'Custom', + }), + ]); + } + const funcs = [ + 'withTiming', + 'withSpring', + 'createAnimatedPropAdapter', + 'withDecay', + 'withRepeat', + 'runOnUI', + 'executeOnUIRuntimeSync', + ]; + for (const fn of funcs) { + reanimatedType.push([ + fn, + addFunction(registry, [], { + positionalParams: [], + restParam: Effect.Read, + returnType: { kind: 'Poly' }, + calleeEffect: Effect.Read, + returnValueKind: ValueKind.Mutable, + noAlias: true, + }), + ]); + } + return addObject(registry, null, reanimatedType); +} + +const ObjectPropertiesSchema = zod.z + .record(zod.z.string(), zod.z.lazy(() => TypeSchema)) + .refine(record => { + return Object.keys(record).every(key => key === '*' || key === 'default' || libExports$1.isValidIdentifier(key)); +}, 'Expected all "object" property names to be valid identifier, `*` to match any property, of `default` to define a module default export'); +const ObjectTypeSchema = zod.z.object({ + kind: zod.z.literal('object'), + properties: ObjectPropertiesSchema.nullable(), +}); +const FunctionTypeSchema = zod.z.object({ + kind: zod.z.literal('function'), + positionalParams: zod.z.array(EffectSchema), + restParam: EffectSchema.nullable(), + calleeEffect: EffectSchema, + returnType: zod.z.lazy(() => TypeSchema), + returnValueKind: ValueKindSchema, + noAlias: zod.z.boolean().nullable().optional(), + mutableOnlyIfOperandsAreMutable: zod.z.boolean().nullable().optional(), + impure: zod.z.boolean().nullable().optional(), + canonicalName: zod.z.string().nullable().optional(), +}); +const HookTypeSchema = zod.z.object({ + kind: zod.z.literal('hook'), + positionalParams: zod.z.array(EffectSchema).nullable().optional(), + restParam: EffectSchema.nullable().optional(), + returnType: zod.z.lazy(() => TypeSchema), + returnValueKind: ValueKindSchema.nullable().optional(), + noAlias: zod.z.boolean().nullable().optional(), +}); +const BuiltInTypeSchema = zod.z.union([ + zod.z.literal('Any'), + zod.z.literal('Ref'), + zod.z.literal('Array'), + zod.z.literal('Primitive'), + zod.z.literal('MixedReadonly'), +]); +const TypeReferenceSchema = zod.z.object({ + kind: zod.z.literal('type'), + name: BuiltInTypeSchema, +}); +const TypeSchema = zod.z.union([ + ObjectTypeSchema, + FunctionTypeSchema, + HookTypeSchema, + TypeReferenceSchema, +]); + +var _Environment_instances, _Environment_globals, _Environment_shapes, _Environment_moduleTypes, _Environment_nextIdentifer, _Environment_nextBlock, _Environment_nextScope, _Environment_scope, _Environment_outlinedFunctions, _Environment_contextIdentifiers, _Environment_hoistedIdentifiers, _Environment_resolveModuleType, _Environment_isKnownReactModule, _Environment_getCustomHookType; +const ReactElementSymbolSchema = zod.z.object({ + elementSymbol: zod.z.union([ + zod.z.literal('react.element'), + zod.z.literal('react.transitional.element'), + ]), + globalDevVar: zod.z.string(), +}); +const ExternalFunctionSchema = zod.z.object({ + source: zod.z.string(), + importSpecifierName: zod.z.string(), +}); +const InstrumentationSchema = zod.z + .object({ + fn: ExternalFunctionSchema, + gating: ExternalFunctionSchema.nullable(), + globalGating: zod.z.string().nullable(), +}) + .refine(opts => opts.gating != null || opts.globalGating != null, 'Expected at least one of gating or globalGating'); +const USE_FIRE_FUNCTION_NAME = 'useFire'; +const EMIT_FREEZE_GLOBAL_GATING = 'false'; +const MacroMethodSchema = zod.z.union([ + zod.z.object({ type: zod.z.literal('wildcard') }), + zod.z.object({ type: zod.z.literal('name'), name: zod.z.string() }), +]); +const MacroSchema = zod.z.union([ + zod.z.string(), + zod.z.tuple([zod.z.string(), zod.z.array(MacroMethodSchema)]), +]); +const HookSchema = zod.z.object({ + effectKind: zod.z.nativeEnum(Effect), + valueKind: zod.z.nativeEnum(ValueKind), + noAlias: zod.z.boolean().default(false), + transitiveMixedData: zod.z.boolean().default(false), +}); +const EnvironmentConfigSchema = zod.z.object({ + customHooks: zod.z.map(zod.z.string(), HookSchema).default(new Map()), + moduleTypeProvider: zod.z.nullable(zod.z.function().args(zod.z.string())).default(null), + customMacros: zod.z.nullable(zod.z.array(MacroSchema)).default(null), + enableResetCacheOnSourceFileChanges: zod.z.nullable(zod.z.boolean()).default(null), + enablePreserveExistingMemoizationGuarantees: zod.z.boolean().default(false), + validatePreserveExistingMemoizationGuarantees: zod.z.boolean().default(true), + enablePreserveExistingManualUseMemo: zod.z.boolean().default(false), + enableForest: zod.z.boolean().default(false), + enableUseTypeAnnotations: zod.z.boolean().default(false), + enableOptionalDependencies: zod.z.boolean().default(true), + enableFire: zod.z.boolean().default(false), + inferEffectDependencies: zod.z + .nullable(zod.z.array(zod.z.object({ + function: ExternalFunctionSchema, + numRequiredArgs: zod.z.number().min(1, 'numRequiredArgs must be > 0'), + }))) + .default(null), + inlineJsxTransform: ReactElementSymbolSchema.nullable().default(null), + validateHooksUsage: zod.z.boolean().default(true), + validateRefAccessDuringRender: zod.z.boolean().default(true), + validateNoSetStateInRender: zod.z.boolean().default(true), + validateNoSetStateInPassiveEffects: zod.z.boolean().default(false), + validateNoJSXInTryStatements: zod.z.boolean().default(false), + validateStaticComponents: zod.z.boolean().default(false), + validateMemoizedEffectDependencies: zod.z.boolean().default(false), + validateNoCapitalizedCalls: zod.z.nullable(zod.z.array(zod.z.string())).default(null), + validateBlocklistedImports: zod.z.nullable(zod.z.array(zod.z.string())).default(null), + validateNoImpureFunctionsInRender: zod.z.boolean().default(false), + enableAssumeHooksFollowRulesOfReact: zod.z.boolean().default(true), + enableTransitivelyFreezeFunctionExpressions: zod.z.boolean().default(true), + enableEmitFreeze: ExternalFunctionSchema.nullable().default(null), + enableEmitHookGuards: ExternalFunctionSchema.nullable().default(null), + enableInstructionReordering: zod.z.boolean().default(false), + enableFunctionOutlining: zod.z.boolean().default(true), + enableJsxOutlining: zod.z.boolean().default(false), + enableEmitInstrumentForget: InstrumentationSchema.nullable().default(null), + assertValidMutableRanges: zod.z.boolean().default(false), + enableChangeVariableCodegen: zod.z.boolean().default(false), + enableMemoizationComments: zod.z.boolean().default(false), + throwUnknownException__testonly: zod.z.boolean().default(false), + enableTreatFunctionDepsAsConditional: zod.z.boolean().default(false), + disableMemoizationForDebugging: zod.z.boolean().default(false), + enableChangeDetectionForDebugging: ExternalFunctionSchema.nullable().default(null), + enableCustomTypeDefinitionForReanimated: zod.z.boolean().default(false), + hookPattern: zod.z.string().nullable().default(null), + enableTreatRefLikeIdentifiersAsRefs: zod.z.boolean().default(false), + lowerContextAccess: ExternalFunctionSchema.nullable().default(null), +}); +class Environment { + constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, programContext) { + _Environment_instances.add(this); + _Environment_globals.set(this, void 0); + _Environment_shapes.set(this, void 0); + _Environment_moduleTypes.set(this, new Map()); + _Environment_nextIdentifer.set(this, 0); + _Environment_nextBlock.set(this, 0); + _Environment_nextScope.set(this, 0); + _Environment_scope.set(this, void 0); + _Environment_outlinedFunctions.set(this, []); + this.inferredEffectLocations = new Set(); + _Environment_contextIdentifiers.set(this, void 0); + _Environment_hoistedIdentifiers.set(this, void 0); + __classPrivateFieldSet(this, _Environment_scope, scope, "f"); + this.fnType = fnType; + this.compilerMode = compilerMode; + this.config = config; + this.filename = filename; + this.code = code; + this.logger = logger; + this.programContext = programContext; + __classPrivateFieldSet(this, _Environment_shapes, new Map(DEFAULT_SHAPES), "f"); + __classPrivateFieldSet(this, _Environment_globals, new Map(DEFAULT_GLOBALS), "f"); + this.hasFireRewrite = false; + this.hasInferredEffect = false; + if (config.disableMemoizationForDebugging && + config.enableChangeDetectionForDebugging != null) { + CompilerError.throwInvalidConfig({ + reason: `Invalid environment config: the 'disableMemoizationForDebugging' and 'enableChangeDetectionForDebugging' options cannot be used together`, + description: null, + loc: null, + suggestions: null, + }); + } + for (const [hookName, hook] of this.config.customHooks) { + CompilerError.invariant(!__classPrivateFieldGet(this, _Environment_globals, "f").has(hookName), { + reason: `[Globals] Found existing definition in global registry for custom hook ${hookName}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Environment_globals, "f").set(hookName, addHook(__classPrivateFieldGet(this, _Environment_shapes, "f"), { + positionalParams: [], + restParam: hook.effectKind, + returnType: hook.transitiveMixedData + ? { kind: 'Object', shapeId: BuiltInMixedReadonlyId } + : { kind: 'Poly' }, + returnValueKind: hook.valueKind, + calleeEffect: Effect.Read, + hookKind: 'Custom', + noAlias: hook.noAlias, + })); + } + if (config.enableCustomTypeDefinitionForReanimated) { + const reanimatedModuleType = getReanimatedModuleType(__classPrivateFieldGet(this, _Environment_shapes, "f")); + __classPrivateFieldGet(this, _Environment_moduleTypes, "f").set(REANIMATED_MODULE_NAME, reanimatedModuleType); + } + __classPrivateFieldSet(this, _Environment_contextIdentifiers, contextIdentifiers, "f"); + __classPrivateFieldSet(this, _Environment_hoistedIdentifiers, new Set(), "f"); + } + get isInferredMemoEnabled() { + return this.compilerMode !== 'no_inferred_memo'; + } + get nextIdentifierId() { + var _a, _b; + return makeIdentifierId((__classPrivateFieldSet(this, _Environment_nextIdentifer, (_b = __classPrivateFieldGet(this, _Environment_nextIdentifer, "f"), _a = _b++, _b), "f"), _a)); + } + get nextBlockId() { + var _a, _b; + return makeBlockId((__classPrivateFieldSet(this, _Environment_nextBlock, (_b = __classPrivateFieldGet(this, _Environment_nextBlock, "f"), _a = _b++, _b), "f"), _a)); + } + get nextScopeId() { + var _a, _b; + return makeScopeId((__classPrivateFieldSet(this, _Environment_nextScope, (_b = __classPrivateFieldGet(this, _Environment_nextScope, "f"), _a = _b++, _b), "f"), _a)); + } + get scope() { + return __classPrivateFieldGet(this, _Environment_scope, "f"); + } + logErrors(errors) { + if (errors.isOk() || this.logger == null) { + return; + } + for (const error of errors.unwrapErr().details) { + this.logger.logEvent(this.filename, { + kind: 'CompileError', + detail: error, + fnLoc: null, + }); + } + } + isContextIdentifier(node) { + return __classPrivateFieldGet(this, _Environment_contextIdentifiers, "f").has(node); + } + isHoistedIdentifier(node) { + return __classPrivateFieldGet(this, _Environment_hoistedIdentifiers, "f").has(node); + } + generateGloballyUniqueIdentifierName(name) { + const identifierNode = __classPrivateFieldGet(this, _Environment_scope, "f").generateUidIdentifier(name !== null && name !== void 0 ? name : undefined); + return makeIdentifierName(identifierNode.name); + } + outlineFunction(fn, type) { + __classPrivateFieldGet(this, _Environment_outlinedFunctions, "f").push({ fn, type }); + } + getOutlinedFunctions() { + return __classPrivateFieldGet(this, _Environment_outlinedFunctions, "f"); + } + getGlobalDeclaration(binding, loc) { + var _a, _b, _c, _d; + if (this.config.hookPattern != null) { + const match = new RegExp(this.config.hookPattern).exec(binding.name); + if (match != null && + typeof match[1] === 'string' && + isHookName$2(match[1])) { + const resolvedName = match[1]; + return (_a = __classPrivateFieldGet(this, _Environment_globals, "f").get(resolvedName)) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this); + } + } + switch (binding.kind) { + case 'ModuleLocal': { + return isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null; + } + case 'Global': { + return ((_b = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.name)) !== null && _b !== void 0 ? _b : (isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + case 'ImportSpecifier': { + if (__classPrivateFieldGet(this, _Environment_instances, "m", _Environment_isKnownReactModule).call(this, binding.module)) { + return ((_c = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.imported)) !== null && _c !== void 0 ? _c : (isHookName$2(binding.imported) || isHookName$2(binding.name) + ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) + : null)); + } + else { + const moduleType = __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_resolveModuleType).call(this, binding.module, loc); + if (moduleType !== null) { + const importedType = this.getPropertyType(moduleType, binding.imported); + if (importedType != null) { + const expectHook = isHookName$2(binding.imported); + const isHook = getHookKindForType(this, importedType) != null; + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for \`import {${binding.imported}} from '${binding.module}'\` ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the exported name`, + loc, + }); + } + return importedType; + } + } + return isHookName$2(binding.imported) || isHookName$2(binding.name) + ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) + : null; + } + } + case 'ImportDefault': + case 'ImportNamespace': { + if (__classPrivateFieldGet(this, _Environment_instances, "m", _Environment_isKnownReactModule).call(this, binding.module)) { + return ((_d = __classPrivateFieldGet(this, _Environment_globals, "f").get(binding.name)) !== null && _d !== void 0 ? _d : (isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + else { + const moduleType = __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_resolveModuleType).call(this, binding.module, loc); + if (moduleType !== null) { + let importedType = null; + if (binding.kind === 'ImportDefault') { + const defaultType = this.getPropertyType(moduleType, 'default'); + if (defaultType !== null) { + importedType = defaultType; + } + } + else { + importedType = moduleType; + } + if (importedType !== null) { + const expectHook = isHookName$2(binding.module); + const isHook = getHookKindForType(this, importedType) != null; + if (expectHook !== isHook) { + CompilerError.throwInvalidConfig({ + reason: `Invalid type configuration for module`, + description: `Expected type for \`import ... from '${binding.module}'\` ${expectHook ? 'to be a hook' : 'not to be a hook'} based on the module name`, + loc, + }); + } + return importedType; + } + } + return isHookName$2(binding.name) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null; + } + } + } + } + getFallthroughPropertyType(receiver, _property) { + var _a; + let shapeId = null; + if (receiver.kind === 'Object' || receiver.kind === 'Function') { + shapeId = receiver.shapeId; + } + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + return (_a = shape.properties.get('*')) !== null && _a !== void 0 ? _a : null; + } + return null; + } + getPropertyType(receiver, property) { + var _a, _b, _c; + let shapeId = null; + if (receiver.kind === 'Object' || receiver.kind === 'Function') { + shapeId = receiver.shapeId; + } + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + if (typeof property === 'string') { + return ((_b = (_a = shape.properties.get(property)) !== null && _a !== void 0 ? _a : shape.properties.get('*')) !== null && _b !== void 0 ? _b : (isHookName$2(property) ? __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this) : null)); + } + else { + return (_c = shape.properties.get('*')) !== null && _c !== void 0 ? _c : null; + } + } + else if (typeof property === 'string' && isHookName$2(property)) { + return __classPrivateFieldGet(this, _Environment_instances, "m", _Environment_getCustomHookType).call(this); + } + return null; + } + getFunctionSignature(type) { + const { shapeId } = type; + if (shapeId !== null) { + const shape = __classPrivateFieldGet(this, _Environment_shapes, "f").get(shapeId); + CompilerError.invariant(shape !== undefined, { + reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`, + description: null, + loc: null, + suggestions: null, + }); + return shape.functionType; + } + return null; + } + addHoistedIdentifier(node) { + __classPrivateFieldGet(this, _Environment_contextIdentifiers, "f").add(node); + __classPrivateFieldGet(this, _Environment_hoistedIdentifiers, "f").add(node); + } +} +_Environment_globals = new WeakMap(), _Environment_shapes = new WeakMap(), _Environment_moduleTypes = new WeakMap(), _Environment_nextIdentifer = new WeakMap(), _Environment_nextBlock = new WeakMap(), _Environment_nextScope = new WeakMap(), _Environment_scope = new WeakMap(), _Environment_outlinedFunctions = new WeakMap(), _Environment_contextIdentifiers = new WeakMap(), _Environment_hoistedIdentifiers = new WeakMap(), _Environment_instances = new WeakSet(), _Environment_resolveModuleType = function _Environment_resolveModuleType(moduleName, loc) { + let moduleType = __classPrivateFieldGet(this, _Environment_moduleTypes, "f").get(moduleName); + if (moduleType === undefined) { + if (this.config.moduleTypeProvider == null) { + return null; + } + const unparsedModuleConfig = this.config.moduleTypeProvider(moduleName); + if (unparsedModuleConfig != null) { + const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig); + if (!parsedModuleConfig.success) { + CompilerError.throwInvalidConfig({ + reason: `Could not parse module type, the configured \`moduleTypeProvider\` function returned an invalid module description`, + description: parsedModuleConfig.error.toString(), + loc, + }); + } + const moduleConfig = parsedModuleConfig.data; + moduleType = installTypeConfig(__classPrivateFieldGet(this, _Environment_globals, "f"), __classPrivateFieldGet(this, _Environment_shapes, "f"), moduleConfig, moduleName, loc); + } + else { + moduleType = null; + } + __classPrivateFieldGet(this, _Environment_moduleTypes, "f").set(moduleName, moduleType); + } + return moduleType; +}, _Environment_isKnownReactModule = function _Environment_isKnownReactModule(moduleName) { + return (moduleName.toLowerCase() === 'react' || + moduleName.toLowerCase() === 'react-dom'); +}, _Environment_getCustomHookType = function _Environment_getCustomHookType() { + if (this.config.enableAssumeHooksFollowRulesOfReact) { + return DefaultNonmutatingHook; + } + else { + return DefaultMutatingHook; + } +}; +Environment.knownReactModules = ['react', 'react-dom']; +const REANIMATED_MODULE_NAME = 'react-native-reanimated'; +function isHookName$2(name) { + return /^use[A-Z0-9]/.test(name); +} +function parseEnvironmentConfig(partialConfig) { + const config = EnvironmentConfigSchema.safeParse(partialConfig); + if (config.success) { + return Ok(config.data); + } + else { + return Err(config.error); + } +} +function validateEnvironmentConfig(partialConfig) { + const config = EnvironmentConfigSchema.safeParse(partialConfig); + if (config.success) { + return config.data; + } + CompilerError.throwInvalidConfig({ + reason: 'Could not validate environment config. Update React Compiler config to fix the error', + description: `${zodValidationError.fromZodError(config.error)}`, + loc: null, + suggestions: null, + }); +} +function tryParseExternalFunction(maybeExternalFunction) { + const externalFunction = ExternalFunctionSchema.safeParse(maybeExternalFunction); + if (externalFunction.success) { + return externalFunction.data; + } + CompilerError.throwInvalidConfig({ + reason: 'Could not parse external function. Update React Compiler config to fix the error', + description: `${zodValidationError.fromZodError(externalFunction.error)}`, + loc: null, + suggestions: null, + }); +} +const DEFAULT_EXPORT = 'default'; + +var _MergedBlocks_map; +function mergeConsecutiveBlocks(fn) { + const merged = new MergedBlocks(); + const fallthroughBlocks = new Set(); + for (const [, block] of fn.body.blocks) { + const fallthrough = terminalFallthrough(block.terminal); + if (fallthrough !== null) { + fallthroughBlocks.add(fallthrough); + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + mergeConsecutiveBlocks(instr.value.loweredFunc.func); + } + } + if (block.preds.size !== 1 || + block.kind !== 'block' || + fallthroughBlocks.has(block.id)) { + continue; + } + const originalPredecessorId = Array.from(block.preds)[0]; + const predecessorId = merged.get(originalPredecessorId); + const predecessor = fn.body.blocks.get(predecessorId); + CompilerError.invariant(predecessor !== undefined, { + reason: `Expected predecessor ${predecessorId} to exist`, + description: null, + loc: null, + suggestions: null, + }); + if (predecessor.terminal.kind !== 'goto' || predecessor.kind !== 'block') { + continue; + } + for (const phi of block.phis) { + CompilerError.invariant(phi.operands.size === 1, { + reason: `Found a block with a single predecessor but where a phi has multiple (${phi.operands.size}) operands`, + description: null, + loc: null, + suggestions: null, + }); + const operand = Array.from(phi.operands.values())[0]; + const instr = { + id: predecessor.terminal.id, + lvalue: { + kind: 'Identifier', + identifier: phi.place.identifier, + effect: Effect.ConditionallyMutate, + reactive: false, + loc: GeneratedSource, + }, + value: { + kind: 'LoadLocal', + place: Object.assign({}, operand), + loc: GeneratedSource, + }, + loc: GeneratedSource, + }; + predecessor.instructions.push(instr); + } + predecessor.instructions.push(...block.instructions); + predecessor.terminal = block.terminal; + merged.merge(block.id, predecessorId); + fn.body.blocks.delete(block.id); + } + markPredecessors(fn.body); + for (const [, { terminal }] of fn.body.blocks) { + if (terminalHasFallthrough(terminal)) { + terminal.fallthrough = merged.get(terminal.fallthrough); + } + } +} +class MergedBlocks { + constructor() { + _MergedBlocks_map.set(this, new Map()); + } + merge(block, into) { + const target = this.get(into); + __classPrivateFieldGet(this, _MergedBlocks_map, "f").set(block, target); + } + get(block) { + var _a; + let current = block; + while (__classPrivateFieldGet(this, _MergedBlocks_map, "f").has(current)) { + current = (_a = __classPrivateFieldGet(this, _MergedBlocks_map, "f").get(current)) !== null && _a !== void 0 ? _a : current; + } + return current; + } +} +_MergedBlocks_map = new WeakMap(); + +var _DisjointSet_entries; +class DisjointSet { + constructor() { + _DisjointSet_entries.set(this, new Map()); + } + union(items) { + const first = items.shift(); + CompilerError.invariant(first != null, { + reason: 'Expected set to be non-empty', + description: null, + loc: null, + suggestions: null, + }); + let root = this.find(first); + if (root == null) { + root = first; + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(first, first); + } + for (const item of items) { + let itemParent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(item); + if (itemParent == null) { + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(item, root); + continue; + } + else if (itemParent === root) { + continue; + } + else { + let current = item; + while (itemParent !== root) { + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(current, root); + current = itemParent; + itemParent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(current); + } + } + } + } + find(item) { + if (!__classPrivateFieldGet(this, _DisjointSet_entries, "f").has(item)) { + return null; + } + const parent = __classPrivateFieldGet(this, _DisjointSet_entries, "f").get(item); + if (parent === item) { + return item; + } + const root = this.find(parent); + __classPrivateFieldGet(this, _DisjointSet_entries, "f").set(item, root); + return root; + } + canonicalize() { + const entries = new Map(); + for (const item of __classPrivateFieldGet(this, _DisjointSet_entries, "f").keys()) { + const root = this.find(item); + entries.set(item, root); + } + return entries; + } + forEach(fn) { + for (const item of __classPrivateFieldGet(this, _DisjointSet_entries, "f").keys()) { + const group = this.find(item); + fn(item, group); + } + } + buildSets() { + const ids = new Map(); + const sets = new Map(); + this.forEach((identifier, groupIdentifier) => { + let id = ids.get(groupIdentifier); + if (id == null) { + id = ids.size; + ids.set(groupIdentifier, id); + } + let set = sets.get(id); + if (set === undefined) { + set = new Set(); + sets.set(id, set); + } + set.add(identifier); + }); + return [...sets.values()]; + } + get size() { + return __classPrivateFieldGet(this, _DisjointSet_entries, "f").size; + } +} +_DisjointSet_entries = new WeakMap(); + +function inferReactiveScopeVariables(fn) { + var _a, _b; + const scopeIdentifiers = findDisjointMutableValues(fn); + const scopes = new Map(); + scopeIdentifiers.forEach((identifier, groupIdentifier) => { + let scope = scopes.get(groupIdentifier); + if (scope === undefined) { + scope = { + id: fn.env.nextScopeId, + range: identifier.mutableRange, + dependencies: new Set(), + declarations: new Map(), + reassignments: new Set(), + earlyReturnValue: null, + merged: new Set(), + loc: identifier.loc, + }; + scopes.set(groupIdentifier, scope); + } + else { + if (scope.range.start === 0) { + scope.range.start = identifier.mutableRange.start; + } + else if (identifier.mutableRange.start !== 0) { + scope.range.start = makeInstructionId(Math.min(scope.range.start, identifier.mutableRange.start)); + } + scope.range.end = makeInstructionId(Math.max(scope.range.end, identifier.mutableRange.end)); + scope.loc = mergeLocation(scope.loc, identifier.loc); + } + identifier.scope = scope; + identifier.mutableRange = scope.range; + }); + let maxInstruction = 0; + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + maxInstruction = makeInstructionId(Math.max(maxInstruction, instr.id)); + } + maxInstruction = makeInstructionId(Math.max(maxInstruction, block.terminal.id)); + } + for (const [, scope] of scopes) { + if (scope.range.start === 0 || + scope.range.end === 0 || + maxInstruction === 0 || + scope.range.end > maxInstruction + 1) { + (_b = (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'hir', + name: 'InferReactiveScopeVariables (invalid scope)', + value: fn, + }); + CompilerError.invariant(false, { + reason: `Invalid mutable range for scope`, + loc: GeneratedSource, + description: `Scope @${scope.id} has range [${scope.range.start}:${scope.range.end}] but the valid range is [1:${maxInstruction + 1}]`, + }); + } + } +} +function mergeLocation(l, r) { + if (l === GeneratedSource) { + return r; + } + else if (r === GeneratedSource) { + return l; + } + else { + return { + filename: l.filename, + identifierName: l.identifierName, + start: { + index: Math.min(l.start.index, r.start.index), + line: Math.min(l.start.line, r.start.line), + column: Math.min(l.start.column, r.start.column), + }, + end: { + index: Math.max(l.end.index, r.end.index), + line: Math.max(l.end.line, r.end.line), + column: Math.max(l.end.column, r.end.column), + }, + }; + } +} +function isMutable(instr, place) { + return inRange(instr, place.identifier.mutableRange); +} +function inRange({ id }, range) { + return id >= range.start && id < range.end; +} +function mayAllocate(_env, instruction) { + const { value } = instruction; + switch (value.kind) { + case 'Destructure': { + return doesPatternContainSpreadElement(value.lvalue.pattern); + } + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'Await': + case 'DeclareLocal': + case 'DeclareContext': + case 'StoreLocal': + case 'LoadGlobal': + case 'MetaProperty': + case 'TypeCastExpression': + case 'LoadLocal': + case 'LoadContext': + case 'StoreContext': + case 'PropertyDelete': + case 'ComputedLoad': + case 'ComputedDelete': + case 'JSXText': + case 'TemplateLiteral': + case 'Primitive': + case 'GetIterator': + case 'IteratorNext': + case 'NextPropertyOf': + case 'Debugger': + case 'StartMemoize': + case 'FinishMemoize': + case 'UnaryExpression': + case 'BinaryExpression': + case 'PropertyLoad': + case 'StoreGlobal': { + return false; + } + case 'TaggedTemplateExpression': + case 'CallExpression': + case 'MethodCall': { + return instruction.lvalue.identifier.type.kind !== 'Primitive'; + } + case 'RegExpLiteral': + case 'PropertyStore': + case 'ComputedStore': + case 'ArrayExpression': + case 'JsxExpression': + case 'JsxFragment': + case 'NewExpression': + case 'ObjectExpression': + case 'UnsupportedNode': + case 'ObjectMethod': + case 'FunctionExpression': { + return true; + } + default: { + assertExhaustive$1(value, `Unexpected value kind \`${value.kind}\``); + } + } +} +function findDisjointMutableValues(fn) { + var _a, _b; + const scopeIdentifiers = new DisjointSet(); + const declarations = new Map(); + function declareIdentifier(lvalue) { + if (!declarations.has(lvalue.identifier.declarationId)) { + declarations.set(lvalue.identifier.declarationId, lvalue.identifier); + } + } + for (const [_, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (phi.place.identifier.mutableRange.start + 1 !== + phi.place.identifier.mutableRange.end && + phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id)) { + const operands = [phi.place.identifier]; + const declaration = declarations.get(phi.place.identifier.declarationId); + if (declaration !== undefined) { + operands.push(declaration); + } + for (const [_, phiId] of phi.operands) { + operands.push(phiId.identifier); + } + scopeIdentifiers.union(operands); + } + else if (fn.env.config.enableForest) { + for (const [, phiId] of phi.operands) { + scopeIdentifiers.union([phi.place.identifier, phiId.identifier]); + } + } + } + for (const instr of block.instructions) { + const operands = []; + const range = instr.lvalue.identifier.mutableRange; + if (range.end > range.start + 1 || mayAllocate(fn.env, instr)) { + operands.push(instr.lvalue.identifier); + } + if (instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + declareIdentifier(instr.value.lvalue.place); + } + else if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext') { + declareIdentifier(instr.value.lvalue.place); + if (instr.value.lvalue.place.identifier.mutableRange.end > + instr.value.lvalue.place.identifier.mutableRange.start + 1) { + operands.push(instr.value.lvalue.place.identifier); + } + if (isMutable(instr, instr.value.value) && + instr.value.value.identifier.mutableRange.start > 0) { + operands.push(instr.value.value.identifier); + } + } + else if (instr.value.kind === 'Destructure') { + for (const place of eachPatternOperand(instr.value.lvalue.pattern)) { + declareIdentifier(place); + if (place.identifier.mutableRange.end > + place.identifier.mutableRange.start + 1) { + operands.push(place.identifier); + } + } + if (isMutable(instr, instr.value.value) && + instr.value.value.identifier.mutableRange.start > 0) { + operands.push(instr.value.value.identifier); + } + } + else if (instr.value.kind === 'MethodCall') { + for (const operand of eachInstructionOperand(instr)) { + if (isMutable(instr, operand) && + operand.identifier.mutableRange.start > 0) { + operands.push(operand.identifier); + } + } + operands.push(instr.value.property.identifier); + } + else { + for (const operand of eachInstructionOperand(instr)) { + if (isMutable(instr, operand) && + operand.identifier.mutableRange.start > 0) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + if (operand.identifier.type.kind === 'Primitive') { + continue; + } + } + operands.push(operand.identifier); + } + } + } + if (operands.length !== 0) { + scopeIdentifiers.union(operands); + } + } + } + return scopeIdentifiers; +} + +function mergeOverlappingReactiveScopesHIR(fn) { + const scopesInfo = collectScopeInfo(fn); + const joinedScopes = getOverlappingReactiveScopes(fn, scopesInfo); + joinedScopes.forEach((scope, groupScope) => { + if (scope !== groupScope) { + groupScope.range.start = makeInstructionId(Math.min(groupScope.range.start, scope.range.start)); + groupScope.range.end = makeInstructionId(Math.max(groupScope.range.end, scope.range.end)); + } + }); + for (const [place, originalScope] of scopesInfo.placeScopes) { + const nextScope = joinedScopes.find(originalScope); + if (nextScope !== null && nextScope !== originalScope) { + place.identifier.scope = nextScope; + } + } +} +function collectScopeInfo(fn) { + const scopeStarts = new Map(); + const scopeEnds = new Map(); + const placeScopes = new Map(); + function collectPlaceScope(place) { + const scope = place.identifier.scope; + if (scope != null) { + placeScopes.set(place, scope); + if (scope.range.start !== scope.range.end) { + getOrInsertDefault(scopeStarts, scope.range.start, new Set()).add(scope); + getOrInsertDefault(scopeEnds, scope.range.end, new Set()).add(scope); + } + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + collectPlaceScope(operand); + } + for (const operand of eachInstructionOperand(instr)) { + collectPlaceScope(operand); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + collectPlaceScope(operand); + } + } + return { + scopeStarts: [...scopeStarts.entries()] + .map(([id, scopes]) => ({ id, scopes })) + .sort((a, b) => b.id - a.id), + scopeEnds: [...scopeEnds.entries()] + .map(([id, scopes]) => ({ id, scopes })) + .sort((a, b) => b.id - a.id), + placeScopes, + }; +} +function visitInstructionId(id, { scopeEnds, scopeStarts }, { activeScopes, joined }) { + const scopeEndTop = scopeEnds.at(-1); + if (scopeEndTop != null && scopeEndTop.id <= id) { + scopeEnds.pop(); + const scopesSortedStartDescending = [...scopeEndTop.scopes].sort((a, b) => b.range.start - a.range.start); + for (const scope of scopesSortedStartDescending) { + const idx = activeScopes.indexOf(scope); + if (idx !== -1) { + if (idx !== activeScopes.length - 1) { + joined.union([scope, ...activeScopes.slice(idx + 1)]); + } + activeScopes.splice(idx, 1); + } + } + } + const scopeStartTop = scopeStarts.at(-1); + if (scopeStartTop != null && scopeStartTop.id <= id) { + scopeStarts.pop(); + const scopesSortedEndDescending = [...scopeStartTop.scopes].sort((a, b) => b.range.end - a.range.end); + activeScopes.push(...scopesSortedEndDescending); + for (let i = 1; i < scopesSortedEndDescending.length; i++) { + const prev = scopesSortedEndDescending[i - 1]; + const curr = scopesSortedEndDescending[i]; + if (prev.range.end === curr.range.end) { + joined.union([prev, curr]); + } + } + } +} +function visitPlace(id, place, { activeScopes, joined }) { + const placeScope = getPlaceScope(id, place); + if (placeScope != null && isMutable({ id }, place)) { + const placeScopeIdx = activeScopes.indexOf(placeScope); + if (placeScopeIdx !== -1 && placeScopeIdx !== activeScopes.length - 1) { + joined.union([placeScope, ...activeScopes.slice(placeScopeIdx + 1)]); + } + } +} +function getOverlappingReactiveScopes(fn, context) { + const state = { + joined: new DisjointSet(), + activeScopes: [], + }; + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + visitInstructionId(instr.id, context, state); + for (const place of eachInstructionOperand(instr)) { + if ((instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') && + place.identifier.type.kind === 'Primitive') { + continue; + } + visitPlace(instr.id, place, state); + } + for (const place of eachInstructionLValue(instr)) { + visitPlace(instr.id, place, state); + } + } + visitInstructionId(block.terminal.id, context, state); + for (const place of eachTerminalOperand(block.terminal)) { + visitPlace(block.terminal.id, place, state); + } + } + return state.joined; +} + +function pruneUnusedLabelsHIR(fn) { + var _a; + const merged = []; + const rewrites = new Map(); + for (const [blockId, block] of fn.body.blocks) { + const terminal = block.terminal; + if (terminal.kind === 'label') { + const { block: nextId, fallthrough: fallthroughId } = terminal; + const next = fn.body.blocks.get(nextId); + const fallthrough = fn.body.blocks.get(fallthroughId); + if (next.terminal.kind === 'goto' && + next.terminal.variant === GotoVariant.Break && + next.terminal.block === fallthroughId) { + if (next.kind === 'block' && fallthrough.kind === 'block') { + merged.push({ + label: blockId, + next: nextId, + fallthrough: fallthroughId, + }); + } + } + } + } + for (const { label: originalLabelId, next: nextId, fallthrough: fallthroughId, } of merged) { + const labelId = (_a = rewrites.get(originalLabelId)) !== null && _a !== void 0 ? _a : originalLabelId; + const label = fn.body.blocks.get(labelId); + const next = fn.body.blocks.get(nextId); + const fallthrough = fn.body.blocks.get(fallthroughId); + CompilerError.invariant(next.phis.size === 0 && fallthrough.phis.size === 0, { + reason: 'Unexpected phis when merging label blocks', + loc: label.terminal.loc, + }); + CompilerError.invariant(next.preds.size === 1 && + fallthrough.preds.size === 1 && + next.preds.has(originalLabelId) && + fallthrough.preds.has(nextId), { + reason: 'Unexpected block predecessors when merging label blocks', + loc: label.terminal.loc, + }); + label.instructions.push(...next.instructions, ...fallthrough.instructions); + label.terminal = fallthrough.terminal; + fn.body.blocks.delete(nextId); + fn.body.blocks.delete(fallthroughId); + rewrites.set(fallthroughId, labelId); + } + for (const [_, block] of fn.body.blocks) { + for (const pred of block.preds) { + const rewritten = rewrites.get(pred); + if (rewritten != null) { + block.preds.delete(pred); + block.preds.add(rewritten); + } + } + } +} + +function isComponentDeclaration(node) { + return Object.prototype.hasOwnProperty.call(node, '__componentDeclaration'); +} + +function isHookDeclaration(node) { + return Object.prototype.hasOwnProperty.call(node, '__hookDeclaration'); +} + +const DEFAULT_IDENTIFIER_INFO = { + reassigned: false, + reassignedByInnerFn: false, + referencedByInnerFn: false, +}; +const withFunctionScope = { + enter: function (path, state) { + state.currentFn.push(path); + }, + exit: function (_, state) { + state.currentFn.pop(); + }, +}; +function findContextIdentifiers(func) { + const state = { + currentFn: [], + identifiers: new Map(), + }; + func.traverse({ + FunctionDeclaration: withFunctionScope, + FunctionExpression: withFunctionScope, + ArrowFunctionExpression: withFunctionScope, + ObjectMethod: withFunctionScope, + AssignmentExpression(path, state) { + var _a, _b; + const left = path.get('left'); + if (left.isLVal()) { + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + handleAssignment(currentFn, state.identifiers, left); + } + else { + CompilerError.throwTodo({ + reason: `Unsupported syntax on the left side of an AssignmentExpression`, + description: `Expected an LVal, got: ${left.type}`, + loc: (_b = left.node.loc) !== null && _b !== void 0 ? _b : null, + }); + } + }, + UpdateExpression(path, state) { + var _a; + const argument = path.get('argument'); + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + if (argument.isLVal()) { + handleAssignment(currentFn, state.identifiers, argument); + } + }, + Identifier(path, state) { + var _a; + const currentFn = (_a = state.currentFn.at(-1)) !== null && _a !== void 0 ? _a : null; + if (path.isReferencedIdentifier()) { + handleIdentifier$1(currentFn, state.identifiers, path); + } + }, + }, state); + const result = new Set(); + for (const [id, info] of state.identifiers.entries()) { + if (info.reassignedByInnerFn) { + result.add(id); + } + else if (info.reassigned && info.referencedByInnerFn) { + result.add(id); + } + } + return result; +} +function handleIdentifier$1(currentFn, identifiers, path) { + const name = path.node.name; + const binding = path.scope.getBinding(name); + if (binding == null) { + return; + } + const identifier = getOrInsertDefault(identifiers, binding.identifier, Object.assign({}, DEFAULT_IDENTIFIER_INFO)); + if (currentFn != null) { + const bindingAboveLambdaScope = currentFn.scope.parent.getBinding(name); + if (binding === bindingAboveLambdaScope) { + identifier.referencedByInnerFn = true; + } + } +} +function handleAssignment(currentFn, identifiers, lvalPath) { + var _a, _b, _c; + const lvalNode = lvalPath.node; + switch (lvalNode.type) { + case 'Identifier': { + const path = lvalPath; + const name = path.node.name; + const binding = path.scope.getBinding(name); + if (binding == null) { + break; + } + const state = getOrInsertDefault(identifiers, binding.identifier, Object.assign({}, DEFAULT_IDENTIFIER_INFO)); + state.reassigned = true; + if (currentFn != null) { + const bindingAboveLambdaScope = currentFn.scope.parent.getBinding(name); + if (binding === bindingAboveLambdaScope) { + state.reassignedByInnerFn = true; + } + } + break; + } + case 'ArrayPattern': { + const path = lvalPath; + for (const element of path.get('elements')) { + if (nonNull(element)) { + handleAssignment(currentFn, identifiers, element); + } + } + break; + } + case 'ObjectPattern': { + const path = lvalPath; + for (const property of path.get('properties')) { + if (property.isObjectProperty()) { + const valuePath = property.get('value'); + CompilerError.invariant(valuePath.isLVal(), { + reason: `[FindContextIdentifiers] Expected object property value to be an LVal, got: ${valuePath.type}`, + description: null, + loc: (_a = valuePath.node.loc) !== null && _a !== void 0 ? _a : GeneratedSource, + suggestions: null, + }); + handleAssignment(currentFn, identifiers, valuePath); + } + else { + CompilerError.invariant(property.isRestElement(), { + reason: `[FindContextIdentifiers] Invalid assumptions for babel types.`, + description: null, + loc: (_b = property.node.loc) !== null && _b !== void 0 ? _b : GeneratedSource, + suggestions: null, + }); + handleAssignment(currentFn, identifiers, property); + } + } + break; + } + case 'AssignmentPattern': { + const path = lvalPath; + const left = path.get('left'); + handleAssignment(currentFn, identifiers, left); + break; + } + case 'RestElement': { + const path = lvalPath; + handleAssignment(currentFn, identifiers, path.get('argument')); + break; + } + case 'MemberExpression': { + break; + } + default: { + CompilerError.throwTodo({ + reason: `[FindContextIdentifiers] Cannot handle Object destructuring assignment target ${lvalNode.type}`, + description: null, + loc: (_c = lvalNode.loc) !== null && _c !== void 0 ? _c : GeneratedSource, + suggestions: null, + }); + } + } +} +function nonNull(t) { + return t.node != null; +} + +function eliminateRedundantPhi(fn, sharedRewrites) { + const ir = fn.body; + const rewrites = sharedRewrites != null ? sharedRewrites : new Map(); + let hasBackEdge = false; + const visited = new Set(); + let size = rewrites.size; + do { + size = rewrites.size; + for (const [blockId, block] of ir.blocks) { + if (!hasBackEdge) { + for (const predId of block.preds) { + if (!visited.has(predId)) { + hasBackEdge = true; + } + } + } + visited.add(blockId); + phis: for (const phi of block.phis) { + phi.operands.forEach((place, _) => rewritePlace(place, rewrites)); + let same = null; + for (const [_, operand] of phi.operands) { + if ((same !== null && operand.identifier.id === same.id) || + operand.identifier.id === phi.place.identifier.id) { + continue; + } + else if (same !== null) { + continue phis; + } + else { + same = operand.identifier; + } + } + CompilerError.invariant(same !== null, { + reason: 'Expected phis to be non-empty', + description: null, + loc: null, + suggestions: null, + }); + rewrites.set(phi.place.identifier, same); + block.phis.delete(phi); + } + for (const instr of block.instructions) { + for (const place of eachInstructionLValue(instr)) { + rewritePlace(place, rewrites); + } + for (const place of eachInstructionOperand(instr)) { + rewritePlace(place, rewrites); + } + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + const { context } = instr.value.loweredFunc.func; + for (const place of context) { + rewritePlace(place, rewrites); + } + eliminateRedundantPhi(instr.value.loweredFunc.func, rewrites); + } + } + const { terminal } = block; + for (const place of eachTerminalOperand(terminal)) { + rewritePlace(place, rewrites); + } + } + } while (rewrites.size > size && hasBackEdge); +} +function rewritePlace(place, rewrites) { + const rewrite = rewrites.get(place.identifier); + if (rewrite != null) { + place.identifier = rewrite; + } +} + +var _SSABuilder_states, _SSABuilder_current, _SSABuilder_blocks, _SSABuilder_env, _SSABuilder_unknown, _SSABuilder_context; +class SSABuilder { + constructor(env, blocks) { + _SSABuilder_states.set(this, new Map()); + _SSABuilder_current.set(this, null); + this.unsealedPreds = new Map(); + _SSABuilder_blocks.set(this, void 0); + _SSABuilder_env.set(this, void 0); + _SSABuilder_unknown.set(this, new Set()); + _SSABuilder_context.set(this, new Set()); + __classPrivateFieldSet(this, _SSABuilder_blocks, new Map(blocks), "f"); + __classPrivateFieldSet(this, _SSABuilder_env, env, "f"); + } + get nextSsaId() { + return __classPrivateFieldGet(this, _SSABuilder_env, "f").nextIdentifierId; + } + defineFunction(func) { + for (const [id, block] of func.body.blocks) { + __classPrivateFieldGet(this, _SSABuilder_blocks, "f").set(id, block); + } + } + enter(fn) { + const current = __classPrivateFieldGet(this, _SSABuilder_current, "f"); + fn(); + __classPrivateFieldSet(this, _SSABuilder_current, current, "f"); + } + state() { + CompilerError.invariant(__classPrivateFieldGet(this, _SSABuilder_current, "f") !== null, { + reason: 'we need to be in a block to access state!', + description: null, + loc: null, + suggestions: null, + }); + return __classPrivateFieldGet(this, _SSABuilder_states, "f").get(__classPrivateFieldGet(this, _SSABuilder_current, "f")); + } + makeId(oldId) { + return { + id: this.nextSsaId, + declarationId: oldId.declarationId, + name: oldId.name, + mutableRange: { + start: makeInstructionId(0), + end: makeInstructionId(0), + }, + scope: null, + type: makeType(), + loc: oldId.loc, + }; + } + defineContext(oldPlace) { + const newPlace = this.definePlace(oldPlace); + __classPrivateFieldGet(this, _SSABuilder_context, "f").add(oldPlace.identifier); + return newPlace; + } + definePlace(oldPlace) { + const oldId = oldPlace.identifier; + if (__classPrivateFieldGet(this, _SSABuilder_unknown, "f").has(oldId)) { + CompilerError.throwTodo({ + reason: `[hoisting] EnterSSA: Expected identifier to be defined before being used`, + description: `Identifier ${printIdentifier(oldId)} is undefined`, + loc: oldPlace.loc, + suggestions: null, + }); + } + if (__classPrivateFieldGet(this, _SSABuilder_context, "f").has(oldId)) { + return this.getPlace(oldPlace); + } + const newId = this.makeId(oldId); + this.state().defs.set(oldId, newId); + return Object.assign(Object.assign({}, oldPlace), { identifier: newId }); + } + getPlace(oldPlace) { + const newId = this.getIdAt(oldPlace, __classPrivateFieldGet(this, _SSABuilder_current, "f").id); + return Object.assign(Object.assign({}, oldPlace), { identifier: newId }); + } + getIdAt(oldPlace, blockId) { + const block = __classPrivateFieldGet(this, _SSABuilder_blocks, "f").get(blockId); + const state = __classPrivateFieldGet(this, _SSABuilder_states, "f").get(block); + if (state.defs.has(oldPlace.identifier)) { + return state.defs.get(oldPlace.identifier); + } + if (block.preds.size == 0) { + __classPrivateFieldGet(this, _SSABuilder_unknown, "f").add(oldPlace.identifier); + return oldPlace.identifier; + } + if (this.unsealedPreds.get(block) > 0) { + const newId = this.makeId(oldPlace.identifier); + state.incompletePhis.push({ + oldPlace, + newPlace: Object.assign(Object.assign({}, oldPlace), { identifier: newId }), + }); + state.defs.set(oldPlace.identifier, newId); + return newId; + } + if (block.preds.size == 1) { + const [pred] = block.preds; + const newId = this.getIdAt(oldPlace, pred); + state.defs.set(oldPlace.identifier, newId); + return newId; + } + const newId = this.makeId(oldPlace.identifier); + state.defs.set(oldPlace.identifier, newId); + return this.addPhi(block, oldPlace, Object.assign(Object.assign({}, oldPlace), { identifier: newId })); + } + addPhi(block, oldPlace, newPlace) { + const predDefs = new Map(); + for (const predBlockId of block.preds) { + const predId = this.getIdAt(oldPlace, predBlockId); + predDefs.set(predBlockId, Object.assign(Object.assign({}, oldPlace), { identifier: predId })); + } + const phi = { + kind: 'Phi', + place: newPlace, + operands: predDefs, + }; + block.phis.add(phi); + return newPlace.identifier; + } + fixIncompletePhis(block) { + const state = __classPrivateFieldGet(this, _SSABuilder_states, "f").get(block); + for (const phi of state.incompletePhis) { + this.addPhi(block, phi.oldPlace, phi.newPlace); + } + } + startBlock(block) { + __classPrivateFieldSet(this, _SSABuilder_current, block, "f"); + __classPrivateFieldGet(this, _SSABuilder_states, "f").set(block, { + defs: new Map(), + incompletePhis: [], + }); + } + print() { + var _a; + const text = []; + for (const [block, state] of __classPrivateFieldGet(this, _SSABuilder_states, "f")) { + text.push(`bb${block.id}:`); + for (const [oldId, newId] of state.defs) { + text.push(` \$${printIdentifier(oldId)}: \$${printIdentifier(newId)}`); + } + for (const incompletePhi of state.incompletePhis) { + text.push(` iphi \$${printPlace(incompletePhi.newPlace)} = \$${printPlace(incompletePhi.oldPlace)}`); + } + } + text.push(`current block: bb${(_a = __classPrivateFieldGet(this, _SSABuilder_current, "f")) === null || _a === void 0 ? void 0 : _a.id}`); + console.log(text.join('\n')); + } +} +_SSABuilder_states = new WeakMap(), _SSABuilder_current = new WeakMap(), _SSABuilder_blocks = new WeakMap(), _SSABuilder_env = new WeakMap(), _SSABuilder_unknown = new WeakMap(), _SSABuilder_context = new WeakMap(); +function enterSSA(func) { + const builder = new SSABuilder(func.env, func.body.blocks); + enterSSAImpl(func, builder, func.body.entry); +} +function enterSSAImpl(func, builder, rootEntry) { + const visitedBlocks = new Set(); + for (const [blockId, block] of func.body.blocks) { + CompilerError.invariant(!visitedBlocks.has(block), { + reason: `found a cycle! visiting bb${block.id} again`, + description: null, + loc: null, + suggestions: null, + }); + visitedBlocks.add(block); + builder.startBlock(block); + if (blockId === rootEntry) { + CompilerError.invariant(func.context.length === 0, { + reason: `Expected function context to be empty for outer function declarations`, + description: null, + loc: func.loc, + suggestions: null, + }); + func.params = func.params.map(param => { + if (param.kind === 'Identifier') { + return builder.definePlace(param); + } + else { + return { + kind: 'Spread', + place: builder.definePlace(param.place), + }; + } + }); + } + for (const instr of block.instructions) { + mapInstructionOperands(instr, place => builder.getPlace(place)); + mapInstructionLValues(instr, lvalue => builder.definePlace(lvalue)); + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + const loweredFunc = instr.value.loweredFunc.func; + const entry = loweredFunc.body.blocks.get(loweredFunc.body.entry); + CompilerError.invariant(entry.preds.size === 0, { + reason: 'Expected function expression entry block to have zero predecessors', + description: null, + loc: null, + suggestions: null, + }); + entry.preds.add(blockId); + builder.defineFunction(loweredFunc); + builder.enter(() => { + loweredFunc.params = loweredFunc.params.map(param => { + if (param.kind === 'Identifier') { + return builder.definePlace(param); + } + else { + return { + kind: 'Spread', + place: builder.definePlace(param.place), + }; + } + }); + enterSSAImpl(loweredFunc, builder, rootEntry); + }); + entry.preds.clear(); + } + } + mapTerminalOperands(block.terminal, place => builder.getPlace(place)); + for (const outputId of eachTerminalSuccessor(block.terminal)) { + const output = func.body.blocks.get(outputId); + let count; + if (builder.unsealedPreds.has(output)) { + count = builder.unsealedPreds.get(output) - 1; + } + else { + count = output.preds.size - 1; + } + builder.unsealedPreds.set(output, count); + if (count === 0 && visitedBlocks.has(output)) { + builder.fixIncompletePhis(output); + } + } + } +} + +function rewriteInstructionKindsBasedOnReassignment(fn) { + const declarations = new Map(); + for (const param of fn.params) { + let place = param.kind === 'Identifier' ? param : param.place; + if (place.identifier.name !== null) { + declarations.set(place.identifier.declarationId, { + kind: InstructionKind.Let, + place, + }); + } + } + for (const place of fn.context) { + if (place.identifier.name !== null) { + declarations.set(place.identifier.declarationId, { + kind: InstructionKind.Let, + place, + }); + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'DeclareLocal': { + const lvalue = value.lvalue; + CompilerError.invariant(!declarations.has(lvalue.place.identifier.declarationId), { + reason: `Expected variable not to be defined prior to declaration`, + description: `${printPlace(lvalue.place)} was already defined`, + loc: lvalue.place.loc, + }); + declarations.set(lvalue.place.identifier.declarationId, lvalue); + break; + } + case 'StoreLocal': { + const lvalue = value.lvalue; + if (lvalue.place.identifier.name !== null) { + const declaration = declarations.get(lvalue.place.identifier.declarationId); + if (declaration === undefined) { + CompilerError.invariant(!declarations.has(lvalue.place.identifier.declarationId), { + reason: `Expected variable not to be defined prior to declaration`, + description: `${printPlace(lvalue.place)} was already defined`, + loc: lvalue.place.loc, + }); + declarations.set(lvalue.place.identifier.declarationId, lvalue); + lvalue.kind = InstructionKind.Const; + } + else { + declaration.kind = InstructionKind.Let; + lvalue.kind = InstructionKind.Reassign; + } + } + break; + } + case 'Destructure': { + const lvalue = value.lvalue; + let kind = null; + for (const place of eachPatternOperand(lvalue.pattern)) { + if (place.identifier.name === null) { + CompilerError.invariant(kind === null || kind === InstructionKind.Const, { + reason: `Expected consistent kind for destructuring`, + description: `other places were \`${kind}\` but '${printPlace(place)}' is const`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Const; + } + else { + const declaration = declarations.get(place.identifier.declarationId); + if (declaration === undefined) { + CompilerError.invariant(block.kind !== 'value', { + reason: `TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE)`, + description: null, + loc: place.loc, + suggestions: null, + }); + declarations.set(place.identifier.declarationId, lvalue); + CompilerError.invariant(kind === null || kind === InstructionKind.Const, { + reason: `Expected consistent kind for destructuring`, + description: `Other places were \`${kind}\` but '${printPlace(place)}' is const`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Const; + } + else { + CompilerError.invariant(kind === null || kind === InstructionKind.Reassign, { + reason: `Expected consistent kind for destructuring`, + description: `Other places were \`${kind}\` but '${printPlace(place)}' is reassigned`, + loc: place.loc, + suggestions: null, + }); + kind = InstructionKind.Reassign; + declaration.kind = InstructionKind.Let; + } + } + } + CompilerError.invariant(kind !== null, { + reason: 'Expected at least one operand', + description: null, + loc: null, + suggestions: null, + }); + lvalue.kind = kind; + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + const lvalue = value.lvalue; + const declaration = declarations.get(lvalue.identifier.declarationId); + CompilerError.invariant(declaration !== undefined, { + reason: `Expected variable to have been defined`, + description: `No declaration for ${printPlace(lvalue)}`, + loc: lvalue.loc, + }); + declaration.kind = InstructionKind.Let; + break; + } + } + } + } +} + +function constantPropagation(fn) { + const constants = new Map(); + constantPropagationImpl(fn, constants); +} +function constantPropagationImpl(fn, constants) { + while (true) { + const haveTerminalsChanged = applyConstantPropagation(fn, constants); + if (!haveTerminalsChanged) { + break; + } + reversePostorderBlocks(fn.body); + removeUnreachableForUpdates(fn.body); + removeDeadDoWhileStatements(fn.body); + removeUnnecessaryTryCatch(fn.body); + markInstructionIds(fn.body); + markPredecessors(fn.body); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const [predecessor] of phi.operands) { + if (!block.preds.has(predecessor)) { + phi.operands.delete(predecessor); + } + } + } + } + eliminateRedundantPhi(fn); + mergeConsecutiveBlocks(fn); + assertConsistentIdentifiers(fn); + assertTerminalSuccessorsExist(fn); + } +} +function applyConstantPropagation(fn, constants) { + let hasChanges = false; + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + let value = evaluatePhi(phi, constants); + if (value !== null) { + constants.set(phi.place.identifier.id, value); + } + } + for (let i = 0; i < block.instructions.length; i++) { + if (block.kind === 'sequence' && i === block.instructions.length - 1) { + continue; + } + const instr = block.instructions[i]; + const value = evaluateInstruction(constants, instr); + if (value !== null) { + constants.set(instr.lvalue.identifier.id, value); + } + } + const terminal = block.terminal; + switch (terminal.kind) { + case 'if': { + const testValue = read(constants, terminal.test); + if (testValue !== null && testValue.kind === 'Primitive') { + hasChanges = true; + const targetBlockId = testValue.value + ? terminal.consequent + : terminal.alternate; + block.terminal = { + kind: 'goto', + variant: GotoVariant.Break, + block: targetBlockId, + id: terminal.id, + loc: terminal.loc, + }; + } + break; + } + } + } + return hasChanges; +} +function evaluatePhi(phi, constants) { + var _a; + let value = null; + for (const [, operand] of phi.operands) { + const operandValue = (_a = constants.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : null; + if (operandValue === null) { + return null; + } + if (value === null) { + value = operandValue; + continue; + } + if (operandValue.kind !== value.kind) { + return null; + } + switch (operandValue.kind) { + case 'Primitive': { + CompilerError.invariant(value.kind === 'Primitive', { + reason: 'value kind expected to be Primitive', + loc: null, + suggestions: null, + }); + if (operandValue.value !== value.value) { + return null; + } + break; + } + case 'LoadGlobal': { + CompilerError.invariant(value.kind === 'LoadGlobal', { + reason: 'value kind expected to be LoadGlobal', + loc: null, + suggestions: null, + }); + if (operandValue.binding.name !== value.binding.name) { + return null; + } + break; + } + default: + return null; + } + } + return value; +} +function evaluateInstruction(constants, instr) { + const value = instr.value; + switch (value.kind) { + case 'Primitive': { + return value; + } + case 'LoadGlobal': { + return value; + } + case 'ComputedLoad': { + const property = read(constants, value.property); + if (property !== null && + property.kind === 'Primitive' && + ((typeof property.value === 'string' && + libExports$1.isValidIdentifier(property.value)) || + typeof property.value === 'number')) { + const nextValue = { + kind: 'PropertyLoad', + loc: value.loc, + property: makePropertyLiteral(property.value), + object: value.object, + }; + instr.value = nextValue; + } + return null; + } + case 'ComputedStore': { + const property = read(constants, value.property); + if (property !== null && + property.kind === 'Primitive' && + ((typeof property.value === 'string' && + libExports$1.isValidIdentifier(property.value)) || + typeof property.value === 'number')) { + const nextValue = { + kind: 'PropertyStore', + loc: value.loc, + property: makePropertyLiteral(property.value), + object: value.object, + value: value.value, + }; + instr.value = nextValue; + } + return null; + } + case 'PostfixUpdate': { + const previous = read(constants, value.value); + if (previous !== null && + previous.kind === 'Primitive' && + typeof previous.value === 'number') { + const next = value.operation === '++' ? previous.value + 1 : previous.value - 1; + constants.set(value.lvalue.identifier.id, { + kind: 'Primitive', + value: next, + loc: value.loc, + }); + return previous; + } + return null; + } + case 'PrefixUpdate': { + const previous = read(constants, value.value); + if (previous !== null && + previous.kind === 'Primitive' && + typeof previous.value === 'number') { + const next = { + kind: 'Primitive', + value: value.operation === '++' ? previous.value + 1 : previous.value - 1, + loc: value.loc, + }; + constants.set(value.lvalue.identifier.id, next); + return next; + } + return null; + } + case 'UnaryExpression': { + switch (value.operator) { + case '!': { + const operand = read(constants, value.value); + if (operand !== null && operand.kind === 'Primitive') { + const result = { + kind: 'Primitive', + value: !operand.value, + loc: value.loc, + }; + instr.value = result; + return result; + } + return null; + } + default: + return null; + } + } + case 'BinaryExpression': { + const lhsValue = read(constants, value.left); + const rhsValue = read(constants, value.right); + if (lhsValue !== null && + rhsValue !== null && + lhsValue.kind === 'Primitive' && + rhsValue.kind === 'Primitive') { + const lhs = lhsValue.value; + const rhs = rhsValue.value; + let result = null; + switch (value.operator) { + case '+': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs + rhs, loc: value.loc }; + } + else if (typeof lhs === 'string' && typeof rhs === 'string') { + result = { kind: 'Primitive', value: lhs + rhs, loc: value.loc }; + } + break; + } + case '-': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs - rhs, loc: value.loc }; + } + break; + } + case '*': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs * rhs, loc: value.loc }; + } + break; + } + case '/': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs / rhs, loc: value.loc }; + } + break; + } + case '|': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs | rhs, loc: value.loc }; + } + break; + } + case '&': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs & rhs, loc: value.loc }; + } + break; + } + case '^': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs ^ rhs, loc: value.loc }; + } + break; + } + case '<<': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs << rhs, loc: value.loc }; + } + break; + } + case '>>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs >> rhs, loc: value.loc }; + } + break; + } + case '>>>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { + kind: 'Primitive', + value: lhs >>> rhs, + loc: value.loc, + }; + } + break; + } + case '%': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs % rhs, loc: value.loc }; + } + break; + } + case '**': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: Math.pow(lhs, rhs), loc: value.loc }; + } + break; + } + case '<': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs < rhs, loc: value.loc }; + } + break; + } + case '<=': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs <= rhs, loc: value.loc }; + } + break; + } + case '>': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs > rhs, loc: value.loc }; + } + break; + } + case '>=': { + if (typeof lhs === 'number' && typeof rhs === 'number') { + result = { kind: 'Primitive', value: lhs >= rhs, loc: value.loc }; + } + break; + } + case '==': { + result = { kind: 'Primitive', value: lhs == rhs, loc: value.loc }; + break; + } + case '===': { + result = { kind: 'Primitive', value: lhs === rhs, loc: value.loc }; + break; + } + case '!=': { + result = { kind: 'Primitive', value: lhs != rhs, loc: value.loc }; + break; + } + case '!==': { + result = { kind: 'Primitive', value: lhs !== rhs, loc: value.loc }; + break; + } + } + if (result !== null) { + instr.value = result; + return result; + } + } + return null; + } + case 'PropertyLoad': { + const objectValue = read(constants, value.object); + if (objectValue !== null) { + if (objectValue.kind === 'Primitive' && + typeof objectValue.value === 'string' && + value.property === 'length') { + const result = { + kind: 'Primitive', + value: objectValue.value.length, + loc: value.loc, + }; + instr.value = result; + return result; + } + } + return null; + } + case 'LoadLocal': { + const placeValue = read(constants, value.place); + if (placeValue !== null) { + instr.value = placeValue; + } + return placeValue; + } + case 'StoreLocal': { + const placeValue = read(constants, value.value); + if (placeValue !== null) { + constants.set(value.lvalue.place.identifier.id, placeValue); + } + return placeValue; + } + case 'ObjectMethod': + case 'FunctionExpression': { + constantPropagationImpl(value.loweredFunc.func, constants); + return null; + } + default: { + return null; + } + } +} +function read(constants, place) { + var _a; + return (_a = constants.get(place.identifier.id)) !== null && _a !== void 0 ? _a : null; +} + +function deadCodeElimination(fn) { + const state = findReferencedIdentifiers(fn); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (!state.isIdOrNameUsed(phi.place.identifier)) { + block.phis.delete(phi); + } + } + retainWhere(block.instructions, instr => state.isIdOrNameUsed(instr.lvalue.identifier)); + for (let i = 0; i < block.instructions.length; i++) { + const isBlockValue = block.kind !== 'block' && i === block.instructions.length - 1; + if (!isBlockValue) { + rewriteInstruction(block.instructions[i], state); + } + } + } + retainWhere(fn.context, contextVar => state.isIdOrNameUsed(contextVar.identifier)); +} +let State$2 = class State { + constructor() { + this.named = new Set(); + this.identifiers = new Set(); + } + reference(identifier) { + this.identifiers.add(identifier.id); + if (identifier.name !== null) { + this.named.add(identifier.name.value); + } + } + isIdOrNameUsed(identifier) { + return (this.identifiers.has(identifier.id) || + (identifier.name !== null && this.named.has(identifier.name.value))); + } + isIdUsed(identifier) { + return this.identifiers.has(identifier.id); + } + get count() { + return this.identifiers.size; + } +}; +function findReferencedIdentifiers(fn) { + const hasLoop = hasBackEdge(fn); + const reversedBlocks = [...fn.body.blocks.values()].reverse(); + const state = new State$2(); + let size = state.count; + do { + size = state.count; + for (const block of reversedBlocks) { + for (const operand of eachTerminalOperand(block.terminal)) { + state.reference(operand.identifier); + } + for (let i = block.instructions.length - 1; i >= 0; i--) { + const instr = block.instructions[i]; + const isBlockValue = block.kind !== 'block' && i === block.instructions.length - 1; + if (isBlockValue) { + state.reference(instr.lvalue.identifier); + for (const place of eachInstructionValueOperand(instr.value)) { + state.reference(place.identifier); + } + } + else if (state.isIdOrNameUsed(instr.lvalue.identifier) || + !pruneableValue(instr.value, state)) { + state.reference(instr.lvalue.identifier); + if (instr.value.kind === 'StoreLocal') { + if (instr.value.lvalue.kind === InstructionKind.Reassign || + state.isIdUsed(instr.value.lvalue.place.identifier)) { + state.reference(instr.value.value.identifier); + } + } + else { + for (const operand of eachInstructionValueOperand(instr.value)) { + state.reference(operand.identifier); + } + } + } + } + for (const phi of block.phis) { + if (state.isIdOrNameUsed(phi.place.identifier)) { + for (const [_pred, operand] of phi.operands) { + state.reference(operand.identifier); + } + } + } + } + } while (state.count > size && hasLoop); + return state; +} +function rewriteInstruction(instr, state) { + if (instr.value.kind === 'Destructure') { + switch (instr.value.lvalue.pattern.kind) { + case 'ArrayPattern': { + let lastEntryIndex = 0; + const items = instr.value.lvalue.pattern.items; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (item.kind === 'Identifier') { + if (!state.isIdOrNameUsed(item.identifier)) { + items[i] = { kind: 'Hole' }; + } + else { + lastEntryIndex = i; + } + } + else if (item.kind === 'Spread') { + if (!state.isIdOrNameUsed(item.place.identifier)) { + items[i] = { kind: 'Hole' }; + } + else { + lastEntryIndex = i; + } + } + } + items.length = lastEntryIndex + 1; + break; + } + case 'ObjectPattern': { + let nextProperties = null; + for (const property of instr.value.lvalue.pattern.properties) { + if (property.kind === 'ObjectProperty') { + if (state.isIdOrNameUsed(property.place.identifier)) { + nextProperties !== null && nextProperties !== void 0 ? nextProperties : (nextProperties = []); + nextProperties.push(property); + } + } + else { + if (state.isIdOrNameUsed(property.place.identifier)) { + nextProperties = null; + break; + } + } + } + if (nextProperties !== null) { + instr.value.lvalue.pattern.properties = nextProperties; + } + break; + } + default: { + assertExhaustive$1(instr.value.lvalue.pattern, `Unexpected pattern kind '${instr.value.lvalue.pattern.kind}'`); + } + } + } + else if (instr.value.kind === 'StoreLocal') { + if (instr.value.lvalue.kind !== InstructionKind.Reassign && + !state.isIdUsed(instr.value.lvalue.place.identifier)) { + instr.value = { + kind: 'DeclareLocal', + lvalue: instr.value.lvalue, + type: instr.value.type, + loc: instr.value.loc, + }; + } + } +} +function pruneableValue(value, state) { + switch (value.kind) { + case 'DeclareLocal': { + return !state.isIdOrNameUsed(value.lvalue.place.identifier); + } + case 'StoreLocal': { + if (value.lvalue.kind === InstructionKind.Reassign) { + return !state.isIdUsed(value.lvalue.place.identifier); + } + return !state.isIdOrNameUsed(value.lvalue.place.identifier); + } + case 'Destructure': { + let isIdOrNameUsed = false; + let isIdUsed = false; + for (const place of eachPatternOperand(value.lvalue.pattern)) { + if (state.isIdUsed(place.identifier)) { + isIdOrNameUsed = true; + isIdUsed = true; + } + else if (state.isIdOrNameUsed(place.identifier)) { + isIdOrNameUsed = true; + } + } + if (value.lvalue.kind === InstructionKind.Reassign) { + return !isIdUsed; + } + else { + return !isIdOrNameUsed; + } + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + return !state.isIdUsed(value.lvalue.identifier); + } + case 'Debugger': { + return false; + } + case 'Await': + case 'CallExpression': + case 'ComputedDelete': + case 'ComputedStore': + case 'PropertyDelete': + case 'MethodCall': + case 'PropertyStore': + case 'StoreGlobal': { + return false; + } + case 'NewExpression': + case 'UnsupportedNode': + case 'TaggedTemplateExpression': { + return false; + } + case 'GetIterator': + case 'NextPropertyOf': + case 'IteratorNext': { + return false; + } + case 'LoadContext': + case 'DeclareContext': + case 'StoreContext': { + return false; + } + case 'StartMemoize': + case 'FinishMemoize': { + return false; + } + case 'RegExpLiteral': + case 'MetaProperty': + case 'LoadGlobal': + case 'ArrayExpression': + case 'BinaryExpression': + case 'ComputedLoad': + case 'ObjectMethod': + case 'FunctionExpression': + case 'LoadLocal': + case 'JsxExpression': + case 'JsxFragment': + case 'JSXText': + case 'ObjectExpression': + case 'Primitive': + case 'PropertyLoad': + case 'TemplateLiteral': + case 'TypeCastExpression': + case 'UnaryExpression': { + return true; + } + default: { + assertExhaustive$1(value, `Unexepcted value kind \`${value.kind}\``); + } + } +} +function hasBackEdge(fn) { + return findBlocksWithBackEdges(fn).size > 0; +} +function findBlocksWithBackEdges(fn) { + const visited = new Set(); + const blocks = new Set(); + for (const [blockId, block] of fn.body.blocks) { + for (const predId of block.preds) { + if (!visited.has(predId)) { + blocks.add(blockId); + } + } + visited.add(blockId); + } + return blocks; +} + +function pruneMaybeThrows(fn) { + const terminalMapping = pruneMaybeThrowsImpl(fn); + if (terminalMapping) { + reversePostorderBlocks(fn.body); + removeUnreachableForUpdates(fn.body); + removeDeadDoWhileStatements(fn.body); + removeUnnecessaryTryCatch(fn.body); + markInstructionIds(fn.body); + mergeConsecutiveBlocks(fn); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const [predecessor, operand] of phi.operands) { + if (!block.preds.has(predecessor)) { + const mappedTerminal = terminalMapping.get(predecessor); + CompilerError.invariant(mappedTerminal != null, { + reason: `Expected non-existing phi operand's predecessor to have been mapped to a new terminal`, + loc: GeneratedSource, + description: `Could not find mapping for predecessor bb${predecessor} in block bb${block.id} for phi ${printPlace(phi.place)}`, + suggestions: null, + }); + phi.operands.delete(predecessor); + phi.operands.set(mappedTerminal, operand); + } + } + } + } + assertConsistentIdentifiers(fn); + assertTerminalSuccessorsExist(fn); + } +} +function pruneMaybeThrowsImpl(fn) { + var _a; + const terminalMapping = new Map(); + for (const [_, block] of fn.body.blocks) { + const terminal = block.terminal; + if (terminal.kind !== 'maybe-throw') { + continue; + } + const canThrow = block.instructions.some(instr => instructionMayThrow(instr)); + if (!canThrow) { + const source = (_a = terminalMapping.get(block.id)) !== null && _a !== void 0 ? _a : block.id; + terminalMapping.set(terminal.continuation, source); + block.terminal = { + kind: 'goto', + block: terminal.continuation, + variant: GotoVariant.Break, + id: terminal.id, + loc: terminal.loc, + }; + } + } + return terminalMapping.size > 0 ? terminalMapping : null; +} +function instructionMayThrow(instr) { + switch (instr.value.kind) { + case 'Primitive': + case 'ArrayExpression': + case 'ObjectExpression': { + return false; + } + default: { + return true; + } + } +} + +function inlineJsxTransform(fn, inlineJsxTransformConfig) { + var _a; + const inlinedJsxDeclarations = new Map(); + for (const [_, currentBlock] of [...fn.body.blocks]) { + let fallthroughBlockInstructions = null; + const instructionCount = currentBlock.instructions.length; + for (let i = 0; i < instructionCount; i++) { + const instr = currentBlock.instructions[i]; + if (currentBlock.kind === 'value') { + (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.logEvent(fn.env.filename, { + kind: 'CompileDiagnostic', + fnLoc: null, + detail: { + reason: 'JSX Inlining is not supported on value blocks', + loc: instr.loc, + }, + }); + continue; + } + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + const currentBlockInstructions = currentBlock.instructions.slice(0, i); + const thenBlockInstructions = currentBlock.instructions.slice(i, i + 1); + const elseBlockInstructions = []; + fallthroughBlockInstructions !== null && fallthroughBlockInstructions !== void 0 ? fallthroughBlockInstructions : (fallthroughBlockInstructions = currentBlock.instructions.slice(i + 1)); + const fallthroughBlockId = fn.env.nextBlockId; + const fallthroughBlock = { + kind: currentBlock.kind, + id: fallthroughBlockId, + instructions: fallthroughBlockInstructions, + terminal: currentBlock.terminal, + preds: new Set(), + phis: new Set(), + }; + const varPlace = createTemporaryPlace(fn.env, instr.value.loc); + promoteTemporary(varPlace.identifier); + const varLValuePlace = createTemporaryPlace(fn.env, instr.value.loc); + const thenVarPlace = Object.assign(Object.assign({}, varPlace), { identifier: forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier) }); + const elseVarPlace = Object.assign(Object.assign({}, varPlace), { identifier: forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier) }); + const varInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, varLValuePlace), + value: { + kind: 'DeclareLocal', + lvalue: { place: Object.assign({}, varPlace), kind: InstructionKind.Let }, + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + currentBlockInstructions.push(varInstruction); + const devGlobalPlace = createTemporaryPlace(fn.env, instr.value.loc); + const devGlobalInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, devGlobalPlace), { effect: Effect.Mutate }), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: inlineJsxTransformConfig.globalDevVar, + }, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + currentBlockInstructions.push(devGlobalInstruction); + const thenBlockId = fn.env.nextBlockId; + const elseBlockId = fn.env.nextBlockId; + const ifTerminal = { + kind: 'if', + test: Object.assign(Object.assign({}, devGlobalPlace), { effect: Effect.Read }), + consequent: thenBlockId, + alternate: elseBlockId, + fallthrough: fallthroughBlockId, + loc: instr.loc, + id: makeInstructionId(0), + }; + currentBlock.instructions = currentBlockInstructions; + currentBlock.terminal = ifTerminal; + const thenBlock = { + id: thenBlockId, + instructions: thenBlockInstructions, + kind: 'block', + phis: new Set(), + preds: new Set(), + terminal: { + kind: 'goto', + block: fallthroughBlockId, + variant: GotoVariant.Break, + id: makeInstructionId(0), + loc: instr.loc, + }, + }; + fn.body.blocks.set(thenBlockId, thenBlock); + const resassignElsePlace = createTemporaryPlace(fn.env, instr.value.loc); + const reassignElseInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, resassignElsePlace), + value: { + kind: 'StoreLocal', + lvalue: { + place: elseVarPlace, + kind: InstructionKind.Reassign, + }, + value: Object.assign({}, instr.lvalue), + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + thenBlockInstructions.push(reassignElseInstruction); + const elseBlockTerminal = { + kind: 'goto', + block: fallthroughBlockId, + variant: GotoVariant.Break, + id: makeInstructionId(0), + loc: instr.loc, + }; + const elseBlock = { + id: elseBlockId, + instructions: elseBlockInstructions, + kind: 'block', + phis: new Set(), + preds: new Set(), + terminal: elseBlockTerminal, + }; + fn.body.blocks.set(elseBlockId, elseBlock); + const { refProperty, keyProperty, propsProperty } = createPropsProperties(fn, instr, elseBlockInstructions, instr.value.kind === 'JsxExpression' ? instr.value.props : [], instr.value.children); + const reactElementInstructionPlace = createTemporaryPlace(fn.env, instr.value.loc); + const reactElementInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, reactElementInstructionPlace), { effect: Effect.Store }), + value: { + kind: 'ObjectExpression', + properties: [ + createSymbolProperty(fn, instr, elseBlockInstructions, '$$typeof', inlineJsxTransformConfig.elementSymbol), + instr.value.kind === 'JsxExpression' + ? createTagProperty(fn, instr, elseBlockInstructions, instr.value.tag) + : createSymbolProperty(fn, instr, elseBlockInstructions, 'type', 'react.fragment'), + refProperty, + keyProperty, + propsProperty, + ], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + elseBlockInstructions.push(reactElementInstruction); + const reassignConditionalInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign({}, createTemporaryPlace(fn.env, instr.value.loc)), + value: { + kind: 'StoreLocal', + lvalue: { + place: Object.assign({}, elseVarPlace), + kind: InstructionKind.Reassign, + }, + value: Object.assign({}, reactElementInstruction.lvalue), + type: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + elseBlockInstructions.push(reassignConditionalInstruction); + const operands = new Map(); + operands.set(thenBlockId, Object.assign({}, elseVarPlace)); + operands.set(elseBlockId, Object.assign({}, thenVarPlace)); + const phiIdentifier = forkTemporaryIdentifier(fn.env.nextIdentifierId, varPlace.identifier); + const phiPlace = Object.assign(Object.assign({}, createTemporaryPlace(fn.env, instr.value.loc)), { identifier: phiIdentifier }); + const phis = new Set([ + { + kind: 'Phi', + operands, + place: phiPlace, + }, + ]); + fallthroughBlock.phis = phis; + fn.body.blocks.set(fallthroughBlockId, fallthroughBlock); + inlinedJsxDeclarations.set(instr.lvalue.identifier.declarationId, { + identifier: phiIdentifier, + blockIdsToIgnore: new Set([thenBlockId, elseBlockId]), + }); + break; + } + case 'FunctionExpression': + case 'ObjectMethod': { + inlineJsxTransform(instr.value.loweredFunc.func, inlineJsxTransformConfig); + break; + } + } + } + } + for (const [blockId, block] of fn.body.blocks) { + for (const instr of block.instructions) { + mapInstructionOperands(instr, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + mapInstructionLValues(instr, lvalue => handlelValue(lvalue, blockId, inlinedJsxDeclarations)); + mapInstructionValueOperands(instr.value, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + } + mapTerminalOperands(block.terminal, place => handlePlace(place, blockId, inlinedJsxDeclarations)); + if (block.terminal.kind === 'scope') { + const scope = block.terminal.scope; + for (const dep of scope.dependencies) { + dep.identifier = handleIdentifier(dep.identifier, inlinedJsxDeclarations); + } + for (const [origId, decl] of [...scope.declarations]) { + const newDecl = handleIdentifier(decl.identifier, inlinedJsxDeclarations); + if (newDecl.id !== origId) { + scope.declarations.delete(origId); + scope.declarations.set(decl.identifier.id, { + identifier: newDecl, + scope: decl.scope, + }); + } + } + } + } + reversePostorderBlocks(fn.body); + markPredecessors(fn.body); + markInstructionIds(fn.body); + fixScopeAndIdentifierRanges(fn.body); +} +function createSymbolProperty(fn, instr, nextInstructions, propertyName, symbolName) { + const symbolPlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolPlace), { effect: Effect.Mutate }), + value: { + kind: 'LoadGlobal', + binding: { kind: 'Global', name: 'Symbol' }, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolInstruction); + const symbolForPlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolForInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolForPlace), { effect: Effect.Read }), + value: { + kind: 'PropertyLoad', + object: Object.assign({}, symbolInstruction.lvalue), + property: makePropertyLiteral('for'), + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolForInstruction); + const symbolValuePlace = createTemporaryPlace(fn.env, instr.value.loc); + const symbolValueInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, symbolValuePlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: symbolName, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(symbolValueInstruction); + const $$typeofPlace = createTemporaryPlace(fn.env, instr.value.loc); + const $$typeofInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, $$typeofPlace), { effect: Effect.Mutate }), + value: { + kind: 'MethodCall', + receiver: symbolInstruction.lvalue, + property: symbolForInstruction.lvalue, + args: [symbolValueInstruction.lvalue], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + const $$typeofProperty = { + kind: 'ObjectProperty', + key: { name: propertyName, kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, $$typeofPlace), { effect: Effect.Capture }), + }; + nextInstructions.push($$typeofInstruction); + return $$typeofProperty; +} +function createTagProperty(fn, instr, nextInstructions, componentTag) { + let tagProperty; + switch (componentTag.kind) { + case 'BuiltinTag': { + const tagPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const tagInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, tagPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: componentTag.name, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + tagProperty = { + kind: 'ObjectProperty', + key: { name: 'type', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, tagPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(tagInstruction); + break; + } + case 'Identifier': { + tagProperty = { + kind: 'ObjectProperty', + key: { name: 'type', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, componentTag), { effect: Effect.Capture }), + }; + break; + } + } + return tagProperty; +} +function createPropsProperties(fn, instr, nextInstructions, propAttributes, children) { + let refProperty; + let keyProperty; + const props = []; + const jsxAttributesWithoutKey = propAttributes.filter(p => p.kind === 'JsxAttribute' && p.name !== 'key'); + const jsxSpreadAttributes = propAttributes.filter(p => p.kind === 'JsxSpreadAttribute'); + const spreadPropsOnly = jsxAttributesWithoutKey.length === 0 && jsxSpreadAttributes.length === 1; + propAttributes.forEach(prop => { + switch (prop.kind) { + case 'JsxAttribute': { + switch (prop.name) { + case 'key': { + keyProperty = { + kind: 'ObjectProperty', + key: { name: 'key', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + break; + } + case 'ref': { + refProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + const refPropProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + props.push(refPropProperty); + break; + } + default: { + const attributeProperty = { + kind: 'ObjectProperty', + key: { name: prop.name, kind: 'string' }, + type: 'property', + place: Object.assign({}, prop.place), + }; + props.push(attributeProperty); + } + } + break; + } + case 'JsxSpreadAttribute': { + props.push({ + kind: 'Spread', + place: Object.assign({}, prop.argument), + }); + break; + } + } + }); + const propsPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + if (children) { + let childrenPropProperty; + if (children.length === 1) { + childrenPropProperty = { + kind: 'ObjectProperty', + key: { name: 'children', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, children[0]), { effect: Effect.Capture }), + }; + } + else { + const childrenPropPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const childrenPropInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, childrenPropPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'ArrayExpression', + elements: [...children], + loc: instr.value.loc, + }, + loc: instr.loc, + }; + nextInstructions.push(childrenPropInstruction); + childrenPropProperty = { + kind: 'ObjectProperty', + key: { name: 'children', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, childrenPropPropertyPlace), { effect: Effect.Capture }), + }; + } + props.push(childrenPropProperty); + } + if (refProperty == null) { + const refPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const refInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, refPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + refProperty = { + kind: 'ObjectProperty', + key: { name: 'ref', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, refPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(refInstruction); + } + if (keyProperty == null) { + const keyPropertyPlace = createTemporaryPlace(fn.env, instr.value.loc); + const keyInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, keyPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'Primitive', + value: null, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + keyProperty = { + kind: 'ObjectProperty', + key: { name: 'key', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, keyPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(keyInstruction); + } + let propsProperty; + if (spreadPropsOnly) { + const spreadProp = jsxSpreadAttributes[0]; + CompilerError.invariant(spreadProp.kind === 'JsxSpreadAttribute', { + reason: 'Spread prop attribute must be of kind JSXSpreadAttribute', + loc: instr.loc, + }); + propsProperty = { + kind: 'ObjectProperty', + key: { name: 'props', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, spreadProp.argument), { effect: Effect.Mutate }), + }; + } + else { + const propsInstruction = { + id: makeInstructionId(0), + lvalue: Object.assign(Object.assign({}, propsPropertyPlace), { effect: Effect.Mutate }), + value: { + kind: 'ObjectExpression', + properties: props, + loc: instr.value.loc, + }, + loc: instr.loc, + }; + propsProperty = { + kind: 'ObjectProperty', + key: { name: 'props', kind: 'string' }, + type: 'property', + place: Object.assign(Object.assign({}, propsPropertyPlace), { effect: Effect.Capture }), + }; + nextInstructions.push(propsInstruction); + } + return { refProperty, keyProperty, propsProperty }; +} +function handlePlace(place, blockId, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(place.identifier.declarationId); + if (inlinedJsxDeclaration == null || + inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)) { + return place; + } + return Object.assign(Object.assign({}, place), { identifier: inlinedJsxDeclaration.identifier }); +} +function handlelValue(lvalue, blockId, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(lvalue.identifier.declarationId); + if (inlinedJsxDeclaration == null || + inlinedJsxDeclaration.blockIdsToIgnore.has(blockId)) { + return lvalue; + } + return Object.assign(Object.assign({}, lvalue), { identifier: inlinedJsxDeclaration.identifier }); +} +function handleIdentifier(identifier, inlinedJsxDeclarations) { + const inlinedJsxDeclaration = inlinedJsxDeclarations.get(identifier.declarationId); + return inlinedJsxDeclaration == null + ? identifier + : inlinedJsxDeclaration.identifier; +} + +function findScopesToMerge(fn) { + const objectMethodDecls = new Set(); + const mergeScopesBuilder = new DisjointSet(); + for (const [_, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'ObjectMethod') { + objectMethodDecls.add(lvalue.identifier); + } + else if (value.kind === 'ObjectExpression') { + for (const operand of eachInstructionValueOperand(value)) { + if (objectMethodDecls.has(operand.identifier)) { + const operandScope = operand.identifier.scope; + const lvalueScope = lvalue.identifier.scope; + CompilerError.invariant(operandScope != null && lvalueScope != null, { + reason: 'Internal error: Expected all ObjectExpressions and ObjectMethods to have non-null scope.', + suggestions: null, + loc: GeneratedSource, + }); + mergeScopesBuilder.union([operandScope, lvalueScope]); + } + } + } + } + } + return mergeScopesBuilder; +} +function alignObjectMethodScopes(fn) { + for (const [_, block] of fn.body.blocks) { + for (const { value } of block.instructions) { + if (value.kind === 'ObjectMethod' || + value.kind === 'FunctionExpression') { + alignObjectMethodScopes(value.loweredFunc.func); + } + } + } + const scopeGroupsMap = findScopesToMerge(fn).canonicalize(); + for (const [scope, root] of scopeGroupsMap) { + if (scope !== root) { + root.range.start = makeInstructionId(Math.min(scope.range.start, root.range.start)); + root.range.end = makeInstructionId(Math.max(scope.range.end, root.range.end)); + } + } + for (const [_, block] of fn.body.blocks) { + for (const { lvalue: { identifier }, } of block.instructions) { + if (identifier.scope != null) { + const root = scopeGroupsMap.get(identifier.scope); + if (root != null) { + identifier.scope = root; + } + } + } + } +} + +function visitReactiveFunction(fn, visitor, state) { + visitor.visitBlock(fn.body, state); +} +class ReactiveFunctionVisitor { + visitID(_id, _state) { } + visitParam(_place, _state) { } + visitLValue(_id, _lvalue, _state) { } + visitPlace(_id, _place, _state) { } + visitReactiveFunctionValue(_id, _dependencies, _fn, _state) { } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + } + traverseValue(id, value, state) { + switch (value.kind) { + case 'OptionalExpression': { + this.visitValue(id, value.value, state); + break; + } + case 'LogicalExpression': { + this.visitValue(id, value.left, state); + this.visitValue(id, value.right, state); + break; + } + case 'ConditionalExpression': { + this.visitValue(id, value.test, state); + this.visitValue(id, value.consequent, state); + this.visitValue(id, value.alternate, state); + break; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + this.visitValue(value.id, value.value, state); + break; + } + default: { + for (const place of eachInstructionValueOperand(value)) { + this.visitPlace(id, place, state); + } + } + } + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + } + traverseInstruction(instruction, state) { + this.visitID(instruction.id, state); + for (const operand of eachInstructionLValue(instruction)) { + this.visitLValue(instruction.id, operand, state); + } + this.visitValue(instruction.id, instruction.value, state); + } + visitTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + } + traverseTerminal(stmt, state) { + const { terminal } = stmt; + if (terminal.id !== null) { + this.visitID(terminal.id, state); + } + switch (terminal.kind) { + case 'break': + case 'continue': { + break; + } + case 'return': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'throw': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'for': { + this.visitValue(terminal.id, terminal.init, state); + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + if (terminal.update !== null) { + this.visitValue(terminal.id, terminal.update, state); + } + break; + } + case 'for-of': { + this.visitValue(terminal.id, terminal.init, state); + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'for-in': { + this.visitValue(terminal.id, terminal.init, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'do-while': { + this.visitBlock(terminal.loop, state); + this.visitValue(terminal.id, terminal.test, state); + break; + } + case 'while': { + this.visitValue(terminal.id, terminal.test, state); + this.visitBlock(terminal.loop, state); + break; + } + case 'if': { + this.visitPlace(terminal.id, terminal.test, state); + this.visitBlock(terminal.consequent, state); + if (terminal.alternate !== null) { + this.visitBlock(terminal.alternate, state); + } + break; + } + case 'switch': { + this.visitPlace(terminal.id, terminal.test, state); + for (const case_ of terminal.cases) { + if (case_.test !== null) { + this.visitPlace(terminal.id, case_.test, state); + } + if (case_.block !== undefined) { + this.visitBlock(case_.block, state); + } + } + break; + } + case 'label': { + this.visitBlock(terminal.block, state); + break; + } + case 'try': { + this.visitBlock(terminal.block, state); + this.visitBlock(terminal.handler, state); + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } + visitScope(scope, state) { + this.traverseScope(scope, state); + } + traverseScope(scope, state) { + this.visitBlock(scope.instructions, state); + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + } + traversePrunedScope(scopeBlock, state) { + this.visitBlock(scopeBlock.instructions, state); + } + visitBlock(block, state) { + this.traverseBlock(block, state); + } + traverseBlock(block, state) { + for (const instr of block) { + switch (instr.kind) { + case 'instruction': { + this.visitInstruction(instr.instruction, state); + break; + } + case 'scope': { + this.visitScope(instr, state); + break; + } + case 'pruned-scope': { + this.visitPrunedScope(instr, state); + break; + } + case 'terminal': { + this.visitTerminal(instr, state); + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + } + } + visitHirFunction(fn, state) { + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + this.visitParam(place, state); + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + this.visitInstruction(instr, state); + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + this.visitHirFunction(instr.value.loweredFunc.func, state); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + this.visitPlace(block.terminal.id, operand, state); + } + } + } +} +class ReactiveFunctionTransform extends ReactiveFunctionVisitor { + traverseBlock(block, state) { + let nextBlock = null; + for (let i = 0; i < block.length; i++) { + const instr = block[i]; + let transformed; + switch (instr.kind) { + case 'instruction': { + transformed = this.transformInstruction(instr.instruction, state); + break; + } + case 'scope': { + transformed = this.transformScope(instr, state); + break; + } + case 'pruned-scope': { + transformed = this.transformPrunedScope(instr, state); + break; + } + case 'terminal': { + transformed = this.transformTerminal(instr, state); + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + switch (transformed.kind) { + case 'keep': { + if (nextBlock !== null) { + nextBlock.push(instr); + } + break; + } + case 'remove': { + if (nextBlock === null) { + nextBlock = block.slice(0, i); + } + break; + } + case 'replace': { + nextBlock !== null && nextBlock !== void 0 ? nextBlock : (nextBlock = block.slice(0, i)); + nextBlock.push(transformed.value); + break; + } + case 'replace-many': { + nextBlock !== null && nextBlock !== void 0 ? nextBlock : (nextBlock = block.slice(0, i)); + nextBlock.push(...transformed.value); + break; + } + } + } + if (nextBlock !== null) { + block.length = 0; + block.push(...nextBlock); + } + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + return { kind: 'keep' }; + } + transformTerminal(stmt, state) { + this.visitTerminal(stmt, state); + return { kind: 'keep' }; + } + transformScope(scope, state) { + this.visitScope(scope, state); + return { kind: 'keep' }; + } + transformPrunedScope(scope, state) { + this.visitPrunedScope(scope, state); + return { kind: 'keep' }; + } + transformValue(id, value, state) { + this.visitValue(id, value, state); + return { kind: 'keep' }; + } + transformReactiveFunctionValue(id, dependencies, fn, state) { + this.visitReactiveFunctionValue(id, dependencies, fn, state); + return { kind: 'keep' }; + } + traverseValue(id, value, state) { + switch (value.kind) { + case 'OptionalExpression': { + const nextValue = this.transformValue(id, value.value, state); + if (nextValue.kind === 'replace') { + value.value = nextValue.value; + } + break; + } + case 'LogicalExpression': { + const left = this.transformValue(id, value.left, state); + if (left.kind === 'replace') { + value.left = left.value; + } + const right = this.transformValue(id, value.right, state); + if (right.kind === 'replace') { + value.right = right.value; + } + break; + } + case 'ConditionalExpression': { + const test = this.transformValue(id, value.test, state); + if (test.kind === 'replace') { + value.test = test.value; + } + const consequent = this.transformValue(id, value.consequent, state); + if (consequent.kind === 'replace') { + value.consequent = consequent.value; + } + const alternate = this.transformValue(id, value.alternate, state); + if (alternate.kind === 'replace') { + value.alternate = alternate.value; + } + break; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + const nextValue = this.transformValue(value.id, value.value, state); + if (nextValue.kind === 'replace') { + value.value = nextValue.value; + } + break; + } + default: { + for (const place of eachInstructionValueOperand(value)) { + this.visitPlace(id, place, state); + } + } + } + } + traverseInstruction(instruction, state) { + this.visitID(instruction.id, state); + for (const operand of eachInstructionLValue(instruction)) { + this.visitLValue(instruction.id, operand, state); + } + const nextValue = this.transformValue(instruction.id, instruction.value, state); + if (nextValue.kind === 'replace') { + instruction.value = nextValue.value; + } + } + traverseTerminal(stmt, state) { + const { terminal } = stmt; + if (terminal.id !== null) { + this.visitID(terminal.id, state); + } + switch (terminal.kind) { + case 'break': + case 'continue': { + break; + } + case 'return': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'throw': { + this.visitPlace(terminal.id, terminal.value, state); + break; + } + case 'for': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + if (terminal.update !== null) { + const update = this.transformValue(terminal.id, terminal.update, state); + if (update.kind === 'replace') { + terminal.update = update.value; + } + } + this.visitBlock(terminal.loop, state); + break; + } + case 'for-of': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'for-in': { + const init = this.transformValue(terminal.id, terminal.init, state); + if (init.kind === 'replace') { + terminal.init = init.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'do-while': { + this.visitBlock(terminal.loop, state); + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + break; + } + case 'while': { + const test = this.transformValue(terminal.id, terminal.test, state); + if (test.kind === 'replace') { + terminal.test = test.value; + } + this.visitBlock(terminal.loop, state); + break; + } + case 'if': { + this.visitPlace(terminal.id, terminal.test, state); + this.visitBlock(terminal.consequent, state); + if (terminal.alternate !== null) { + this.visitBlock(terminal.alternate, state); + } + break; + } + case 'switch': { + this.visitPlace(terminal.id, terminal.test, state); + for (const case_ of terminal.cases) { + if (case_.test !== null) { + this.visitPlace(terminal.id, case_.test, state); + } + if (case_.block !== undefined) { + this.visitBlock(case_.block, state); + } + } + break; + } + case 'label': { + this.visitBlock(terminal.block, state); + break; + } + case 'try': { + this.visitBlock(terminal.block, state); + if (terminal.handlerBinding !== null) { + this.visitPlace(terminal.id, terminal.handlerBinding, state); + } + this.visitBlock(terminal.handler, state); + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } +} +function* eachReactiveValueOperand(instrValue) { + switch (instrValue.kind) { + case 'OptionalExpression': { + yield* eachReactiveValueOperand(instrValue.value); + break; + } + case 'LogicalExpression': { + yield* eachReactiveValueOperand(instrValue.left); + yield* eachReactiveValueOperand(instrValue.right); + break; + } + case 'SequenceExpression': { + for (const instr of instrValue.instructions) { + yield* eachReactiveValueOperand(instr.value); + } + yield* eachReactiveValueOperand(instrValue.value); + break; + } + case 'ConditionalExpression': { + yield* eachReactiveValueOperand(instrValue.test); + yield* eachReactiveValueOperand(instrValue.consequent); + yield* eachReactiveValueOperand(instrValue.alternate); + break; + } + default: { + yield* eachInstructionValueOperand(instrValue); + } + } +} + +function assertScopeInstructionsWithinScopes(fn) { + const existingScopes = new Set(); + visitReactiveFunction(fn, new FindAllScopesVisitor(), existingScopes); + visitReactiveFunction(fn, new CheckInstructionsAgainstScopesVisitor(), existingScopes); +} +class FindAllScopesVisitor extends ReactiveFunctionVisitor { + visitScope(block, state) { + this.traverseScope(block, state); + state.add(block.scope.id); + } +} +class CheckInstructionsAgainstScopesVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.activeScopes = new Set(); + } + visitPlace(id, place, state) { + const scope = getPlaceScope(id, place); + if (scope !== null && + state.has(scope.id) && + !this.activeScopes.has(scope.id)) { + CompilerError.invariant(false, { + description: `Instruction [${id}] is part of scope @${scope.id}, but that scope has already completed.`, + loc: place.loc, + reason: 'Encountered an instruction that should be part of a scope, but where that scope has already completed', + suggestions: null, + }); + } + } + visitScope(block, state) { + this.activeScopes.add(block.scope.id); + this.traverseScope(block, state); + this.activeScopes.delete(block.scope.id); + } +} + +function assertWellFormedBreakTargets(fn) { + visitReactiveFunction(fn, new Visitor$a(), new Set()); +} +let Visitor$a = class Visitor extends ReactiveFunctionVisitor { + visitTerminal(stmt, seenLabels) { + if (stmt.label != null) { + seenLabels.add(stmt.label.id); + } + const terminal = stmt.terminal; + if (terminal.kind === 'break' || terminal.kind === 'continue') { + CompilerError.invariant(seenLabels.has(terminal.target), { + reason: 'Unexpected break to invalid label', + loc: stmt.terminal.loc, + }); + } + } +}; + +var _Context_nextScheduleId, _Context_scheduled, _Context_catchHandlers, _Context_controlFlowStack; +function buildReactiveFunction(fn) { + const cx = new Context$2(fn.body); + const driver = new Driver(cx); + const body = driver.traverseBlock(cx.block(fn.body.entry)); + return { + loc: fn.loc, + id: fn.id, + params: fn.params, + generator: fn.generator, + async: fn.async, + body, + env: fn.env, + directives: fn.directives, + }; +} +class Driver { + constructor(cx) { + this.cx = cx; + } + traverseBlock(block) { + const blockValue = []; + this.visitBlock(block, blockValue); + return blockValue; + } + visitBlock(block, blockValue) { + var _a; + CompilerError.invariant(!this.cx.emitted.has(block.id), { + reason: `Cannot emit the same block twice: bb${block.id}`, + description: null, + loc: null, + suggestions: null, + }); + this.cx.emitted.add(block.id); + for (const instruction of block.instructions) { + blockValue.push({ + kind: 'instruction', + instruction, + }); + } + const terminal = block.terminal; + const scheduleIds = []; + switch (terminal.kind) { + case 'return': { + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'return', + loc: terminal.loc, + value: terminal.value, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'throw': { + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'throw', + loc: terminal.loc, + value: terminal.value, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'if': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const alternateId = terminal.alternate !== terminal.fallthrough + ? terminal.alternate + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + let consequent = null; + if (this.cx.isScheduled(terminal.consequent)) { + CompilerError.invariant(false, { + reason: `Unexpected 'if' where the consequent is already scheduled`, + loc: terminal.loc, + }); + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(terminal.consequent)); + } + let alternate = null; + if (alternateId !== null) { + if (this.cx.isScheduled(alternateId)) { + CompilerError.invariant(false, { + reason: `Unexpected 'if' where the alternate is already scheduled`, + loc: terminal.loc, + }); + } + else { + alternate = this.traverseBlock(this.cx.ir.blocks.get(alternateId)); + } + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'if', + loc: terminal.loc, + test: terminal.test, + consequent: consequent !== null && consequent !== void 0 ? consequent : this.emptyBlock(), + alternate: alternate, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'switch': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'switch'); + scheduleIds.push(scheduleId); + } + const cases = []; + [...terminal.cases].reverse().forEach((case_, _index) => { + const test = case_.test; + let consequent; + if (this.cx.isScheduled(case_.block)) { + CompilerError.invariant(case_.block === terminal.fallthrough, { + reason: `Unexpected 'switch' where a case is already scheduled and block is not the fallthrough`, + loc: terminal.loc, + }); + return; + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(case_.block)); + const scheduleId = this.cx.schedule(case_.block, 'case'); + scheduleIds.push(scheduleId); + } + cases.push({ test, block: consequent }); + }); + cases.reverse(); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'switch', + loc: terminal.loc, + test: terminal.test, + cases, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'do-while': { + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'do-while' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'do-while', + loc: terminal.loc, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'while': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'while' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'while', + loc: terminal.loc, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null + ? null + : { + id: fallthroughId, + implicit: false, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, (_a = terminal.update) !== null && _a !== void 0 ? _a : terminal.test, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + const testValue = this.visitValueBlock(terminal.test, terminal.loc).value; + const updateValue = terminal.update !== null + ? this.visitValueBlock(terminal.update, terminal.loc).value + : null; + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for', + loc: terminal.loc, + init: initValue, + test: testValue, + update: updateValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for-of': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.init, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + let testValue = test.value; + if (testValue.kind === 'SequenceExpression') { + const last = testBlock.instructions.at(-1); + testValue.instructions.push(last); + testValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + testValue = { + kind: 'SequenceExpression', + instructions: [testBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for-of' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for-of', + loc: terminal.loc, + init: initValue, + test: testValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'for-in': { + const loopId = !this.cx.isScheduled(terminal.loop) && + terminal.loop !== terminal.fallthrough + ? terminal.loop + : null; + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + const scheduleId = this.cx.scheduleLoop(terminal.fallthrough, terminal.init, terminal.loop); + scheduleIds.push(scheduleId); + const init = this.visitValueBlock(terminal.init, terminal.loc); + const initBlock = this.cx.ir.blocks.get(init.block); + let initValue = init.value; + if (initValue.kind === 'SequenceExpression') { + const last = initBlock.instructions.at(-1); + initValue.instructions.push(last); + initValue.value = { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }; + } + else { + initValue = { + kind: 'SequenceExpression', + instructions: [initBlock.instructions.at(-1)], + id: terminal.id, + loc: terminal.loc, + value: { + kind: 'Primitive', + value: undefined, + loc: terminal.loc, + }, + }; + } + let loopBody; + if (loopId) { + loopBody = this.traverseBlock(this.cx.ir.blocks.get(loopId)); + } + else { + CompilerError.invariant(false, { + reason: `Unexpected 'for-in' where the loop is already scheduled`, + loc: terminal.loc, + }); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'for-in', + loc: terminal.loc, + init: initValue, + loop: loopBody, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'branch': { + let consequent = null; + if (this.cx.isScheduled(terminal.consequent)) { + const break_ = this.visitBreak(terminal.consequent, terminal.id, terminal.loc); + if (break_ !== null) { + consequent = [break_]; + } + } + else { + consequent = this.traverseBlock(this.cx.ir.blocks.get(terminal.consequent)); + } + let alternate = null; + if (this.cx.isScheduled(terminal.alternate)) { + CompilerError.invariant(false, { + reason: `Unexpected 'branch' where the alternate is already scheduled`, + loc: terminal.loc, + }); + } + else { + alternate = this.traverseBlock(this.cx.ir.blocks.get(terminal.alternate)); + } + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'if', + loc: terminal.loc, + test: terminal.test, + consequent: consequent !== null && consequent !== void 0 ? consequent : this.emptyBlock(), + alternate: alternate, + id: terminal.id, + }, + label: null, + }); + break; + } + case 'label': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + let block; + if (this.cx.isScheduled(terminal.block)) { + CompilerError.invariant(false, { + reason: `Unexpected 'label' where the block is already scheduled`, + loc: terminal.loc, + }); + } + else { + block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + terminal: { + kind: 'label', + loc: terminal.loc, + block, + id: terminal.id, + }, + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'sequence': + case 'optional': + case 'ternary': + case 'logical': { + const fallthroughId = terminal.fallthrough !== null && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + const { place, value } = this.visitValueBlockTerminal(terminal); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'instruction', + instruction: { + id: terminal.id, + lvalue: place, + value, + loc: terminal.loc, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'goto': { + switch (terminal.variant) { + case GotoVariant.Break: { + const break_ = this.visitBreak(terminal.block, terminal.id, terminal.loc); + if (break_ !== null) { + blockValue.push(break_); + } + break; + } + case GotoVariant.Continue: { + const continue_ = this.visitContinue(terminal.block, terminal.id, terminal.loc); + if (continue_ !== null) { + blockValue.push(continue_); + } + break; + } + case GotoVariant.Try: { + break; + } + default: { + assertExhaustive$1(terminal.variant, `Unexpected goto variant \`${terminal.variant}\``); + } + } + break; + } + case 'maybe-throw': { + if (!this.cx.isScheduled(terminal.continuation)) { + this.visitBlock(this.cx.ir.blocks.get(terminal.continuation), blockValue); + } + break; + } + case 'try': { + const fallthroughId = this.cx.reachable(terminal.fallthrough) && + !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + } + this.cx.scheduleCatchHandler(terminal.handler); + const block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + const handler = this.traverseBlock(this.cx.ir.blocks.get(terminal.handler)); + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: 'terminal', + label: fallthroughId == null ? null : { id: fallthroughId, implicit: false }, + terminal: { + kind: 'try', + loc: terminal.loc, + block, + handlerBinding: terminal.handlerBinding, + handler, + id: terminal.id, + }, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'pruned-scope': + case 'scope': { + const fallthroughId = !this.cx.isScheduled(terminal.fallthrough) + ? terminal.fallthrough + : null; + if (fallthroughId !== null) { + const scheduleId = this.cx.schedule(fallthroughId, 'if'); + scheduleIds.push(scheduleId); + this.cx.scopeFallthroughs.add(fallthroughId); + } + let block; + if (this.cx.isScheduled(terminal.block)) { + CompilerError.invariant(false, { + reason: `Unexpected 'scope' where the block is already scheduled`, + loc: terminal.loc, + }); + } + else { + block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)); + } + this.cx.unscheduleAll(scheduleIds); + blockValue.push({ + kind: terminal.kind, + instructions: block, + scope: terminal.scope, + }); + if (fallthroughId !== null) { + this.visitBlock(this.cx.ir.blocks.get(fallthroughId), blockValue); + } + break; + } + case 'unreachable': { + break; + } + case 'unsupported': { + CompilerError.invariant(false, { + reason: 'Unexpected unsupported terminal', + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(terminal, 'Unexpected terminal'); + } + } + } + visitValueBlock(id, loc) { + const defaultBlock = this.cx.ir.blocks.get(id); + if (defaultBlock.terminal.kind === 'branch') { + const instructions = defaultBlock.instructions; + if (instructions.length === 0) { + return { + block: defaultBlock.id, + place: defaultBlock.terminal.test, + value: { + kind: 'LoadLocal', + place: defaultBlock.terminal.test, + loc: defaultBlock.terminal.test.loc, + }, + id: defaultBlock.terminal.id, + }; + } + else if (defaultBlock.instructions.length === 1) { + const instr = defaultBlock.instructions[0]; + CompilerError.invariant(instr.lvalue.identifier.id === + defaultBlock.terminal.test.identifier.id, { + reason: 'Expected branch block to end in an instruction that sets the test value', + description: null, + loc: instr.lvalue.loc, + suggestions: null, + }); + return { + block: defaultBlock.id, + place: instr.lvalue, + value: instr.value, + id: instr.id, + }; + } + else { + const instr = defaultBlock.instructions.at(-1); + const sequence = { + kind: 'SequenceExpression', + instructions: defaultBlock.instructions.slice(0, -1), + id: instr.id, + value: instr.value, + loc: loc, + }; + return { + block: defaultBlock.id, + place: defaultBlock.terminal.test, + value: sequence, + id: defaultBlock.terminal.id, + }; + } + } + else if (defaultBlock.terminal.kind === 'goto') { + const instructions = defaultBlock.instructions; + if (instructions.length === 0) { + CompilerError.invariant(false, { + reason: 'Expected goto value block to have at least one instruction', + description: null, + loc: null, + suggestions: null, + }); + } + else if (defaultBlock.instructions.length === 1) { + const instr = defaultBlock.instructions[0]; + let place = instr.lvalue; + let value = instr.value; + if (value.kind === 'StoreLocal' && + value.lvalue.place.identifier.name === null) { + place = value.lvalue.place; + value = { + kind: 'LoadLocal', + place: value.value, + loc: value.value.loc, + }; + } + return { + block: defaultBlock.id, + place, + value, + id: instr.id, + }; + } + else { + const instr = defaultBlock.instructions.at(-1); + let place = instr.lvalue; + let value = instr.value; + if (value.kind === 'StoreLocal' && + value.lvalue.place.identifier.name === null) { + place = value.lvalue.place; + value = { + kind: 'LoadLocal', + place: value.value, + loc: value.value.loc, + }; + } + const sequence = { + kind: 'SequenceExpression', + instructions: defaultBlock.instructions.slice(0, -1), + id: instr.id, + value, + loc: loc, + }; + return { + block: defaultBlock.id, + place, + value: sequence, + id: instr.id, + }; + } + } + else { + const init = this.visitValueBlockTerminal(defaultBlock.terminal); + const final = this.visitValueBlock(init.fallthrough, loc); + const sequence = { + kind: 'SequenceExpression', + instructions: [ + ...defaultBlock.instructions, + { + id: init.id, + loc, + lvalue: init.place, + value: init.value, + }, + ], + id: final.id, + value: final.value, + loc, + }; + return { + block: init.fallthrough, + value: sequence, + place: final.place, + id: final.id, + }; + } + } + visitValueBlockTerminal(terminal) { + switch (terminal.kind) { + case 'sequence': { + const block = this.visitValueBlock(terminal.block, terminal.loc); + return { + value: block.value, + place: block.place, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'optional': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const consequent = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const call = { + kind: 'SequenceExpression', + instructions: [ + { + id: test.id, + loc: testBlock.terminal.loc, + lvalue: test.place, + value: test.value, + }, + ], + id: consequent.id, + value: consequent.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, consequent.place), + value: { + kind: 'OptionalExpression', + optional: terminal.optional, + value: call, + id: terminal.id, + loc: terminal.loc, + }, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'logical': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for logical test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const leftFinal = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const left = { + kind: 'SequenceExpression', + instructions: [ + { + id: test.id, + loc: terminal.loc, + lvalue: test.place, + value: test.value, + }, + ], + id: leftFinal.id, + value: leftFinal.value, + loc: terminal.loc, + }; + const right = this.visitValueBlock(testBlock.terminal.alternate, terminal.loc); + const value = { + kind: 'LogicalExpression', + operator: terminal.operator, + left: left, + right: right.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, leftFinal.place), + value, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'ternary': { + const test = this.visitValueBlock(terminal.test, terminal.loc); + const testBlock = this.cx.ir.blocks.get(test.block); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for ternary test block`, + description: null, + loc: testBlock.terminal.loc, + suggestions: null, + }); + } + const consequent = this.visitValueBlock(testBlock.terminal.consequent, terminal.loc); + const alternate = this.visitValueBlock(testBlock.terminal.alternate, terminal.loc); + const value = { + kind: 'ConditionalExpression', + test: test.value, + consequent: consequent.value, + alternate: alternate.value, + loc: terminal.loc, + }; + return { + place: Object.assign({}, consequent.place), + value, + fallthrough: terminal.fallthrough, + id: terminal.id, + }; + } + case 'maybe-throw': { + CompilerError.throwTodo({ + reason: `Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + case 'label': { + CompilerError.throwTodo({ + reason: `Support labeled statements combined with value blocks (conditional, logical, optional chaining, etc)`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + default: { + CompilerError.throwTodo({ + reason: `Support \`${terminal.kind}\` as a value block terminal (conditional, logical, optional chaining, etc)`, + description: null, + loc: terminal.loc, + suggestions: null, + }); + } + } + } + emptyBlock() { + return []; + } + visitBreak(block, id, loc) { + const target = this.cx.getBreakTarget(block); + if (target === null) { + CompilerError.invariant(false, { + reason: 'Expected a break target', + description: null, + loc: null, + suggestions: null, + }); + } + if (this.cx.scopeFallthroughs.has(target.block)) { + CompilerError.invariant(target.type === 'implicit', { + reason: 'Expected reactive scope to implicitly break to fallthrough', + loc, + }); + return null; + } + return { + kind: 'terminal', + terminal: { + kind: 'break', + loc, + target: target.block, + id, + targetKind: target.type, + }, + label: null, + }; + } + visitContinue(block, id, loc) { + const target = this.cx.getContinueTarget(block); + CompilerError.invariant(target !== null, { + reason: `Expected continue target to be scheduled for bb${block}`, + description: null, + loc: null, + suggestions: null, + }); + return { + kind: 'terminal', + terminal: { + kind: 'continue', + loc, + target: target.block, + id, + targetKind: target.type, + }, + label: null, + }; + } +} +let Context$2 = class Context { + constructor(ir) { + _Context_nextScheduleId.set(this, 0); + this.emitted = new Set(); + this.scopeFallthroughs = new Set(); + _Context_scheduled.set(this, new Set()); + _Context_catchHandlers.set(this, new Set()); + _Context_controlFlowStack.set(this, []); + this.ir = ir; + } + block(id) { + return this.ir.blocks.get(id); + } + scheduleCatchHandler(block) { + __classPrivateFieldGet(this, _Context_catchHandlers, "f").add(block); + } + reachable(id) { + const block = this.ir.blocks.get(id); + return block.terminal.kind !== 'unreachable'; + } + schedule(block, type) { + var _a, _b; + const id = (__classPrivateFieldSet(this, _Context_nextScheduleId, (_b = __classPrivateFieldGet(this, _Context_nextScheduleId, "f"), _a = _b++, _b), "f"), _a); + CompilerError.invariant(!__classPrivateFieldGet(this, _Context_scheduled, "f").has(block), { + reason: `Break block is already scheduled: bb${block}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(block); + __classPrivateFieldGet(this, _Context_controlFlowStack, "f").push({ block, id, type }); + return id; + } + scheduleLoop(fallthroughBlock, continueBlock, loopBlock) { + var _a, _b; + const id = (__classPrivateFieldSet(this, _Context_nextScheduleId, (_b = __classPrivateFieldGet(this, _Context_nextScheduleId, "f"), _a = _b++, _b), "f"), _a); + const ownsBlock = !__classPrivateFieldGet(this, _Context_scheduled, "f").has(fallthroughBlock); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(fallthroughBlock); + CompilerError.invariant(!__classPrivateFieldGet(this, _Context_scheduled, "f").has(continueBlock), { + reason: `Continue block is already scheduled: bb${continueBlock}`, + description: null, + loc: null, + suggestions: null, + }); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(continueBlock); + let ownsLoop = false; + if (loopBlock !== null) { + ownsLoop = !__classPrivateFieldGet(this, _Context_scheduled, "f").has(loopBlock); + __classPrivateFieldGet(this, _Context_scheduled, "f").add(loopBlock); + } + __classPrivateFieldGet(this, _Context_controlFlowStack, "f").push({ + block: fallthroughBlock, + ownsBlock, + id, + type: 'loop', + continueBlock, + loopBlock, + ownsLoop, + }); + return id; + } + unschedule(scheduleId) { + const last = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").pop(); + CompilerError.invariant(last !== undefined && last.id === scheduleId, { + reason: 'Can only unschedule the last target', + description: null, + loc: null, + suggestions: null, + }); + if (last.type !== 'loop' || last.ownsBlock !== null) { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.block); + } + if (last.type === 'loop') { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.continueBlock); + if (last.ownsLoop && last.loopBlock !== null) { + __classPrivateFieldGet(this, _Context_scheduled, "f").delete(last.loopBlock); + } + } + } + unscheduleAll(scheduleIds) { + for (let i = scheduleIds.length - 1; i >= 0; i--) { + this.unschedule(scheduleIds[i]); + } + } + isScheduled(block) { + return __classPrivateFieldGet(this, _Context_scheduled, "f").has(block) || __classPrivateFieldGet(this, _Context_catchHandlers, "f").has(block); + } + getBreakTarget(block) { + let hasPrecedingLoop = false; + for (let i = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1; i >= 0; i--) { + const target = __classPrivateFieldGet(this, _Context_controlFlowStack, "f")[i]; + if (target.block === block) { + let type; + if (target.type === 'loop') { + type = hasPrecedingLoop ? 'labeled' : 'unlabeled'; + } + else if (i === __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1) { + type = 'implicit'; + } + else { + type = 'labeled'; + } + return { + block: target.block, + type, + }; + } + hasPrecedingLoop || (hasPrecedingLoop = target.type === 'loop'); + } + CompilerError.invariant(false, { + reason: 'Expected a break target', + description: null, + loc: null, + suggestions: null, + }); + } + getContinueTarget(block) { + let hasPrecedingLoop = false; + for (let i = __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1; i >= 0; i--) { + const target = __classPrivateFieldGet(this, _Context_controlFlowStack, "f")[i]; + if (target.type == 'loop' && target.continueBlock === block) { + let type; + if (hasPrecedingLoop) { + type = 'labeled'; + } + else if (i === __classPrivateFieldGet(this, _Context_controlFlowStack, "f").length - 1) { + type = 'implicit'; + } + else { + type = 'unlabeled'; + } + return { + block: target.block, + type, + }; + } + hasPrecedingLoop || (hasPrecedingLoop = target.type === 'loop'); + } + return null; + } + debugBreakTargets() { + return __classPrivateFieldGet(this, _Context_controlFlowStack, "f").map(target => (Object.assign({}, target))); + } +}; +_Context_nextScheduleId = new WeakMap(), _Context_scheduled = new WeakMap(), _Context_catchHandlers = new WeakMap(), _Context_controlFlowStack = new WeakMap(); + +var GuardKind; +(function (GuardKind) { + GuardKind[GuardKind["PushHookGuard"] = 0] = "PushHookGuard"; + GuardKind[GuardKind["PopHookGuard"] = 1] = "PopHookGuard"; + GuardKind[GuardKind["AllowHook"] = 2] = "AllowHook"; + GuardKind[GuardKind["DisallowHook"] = 3] = "DisallowHook"; +})(GuardKind || (GuardKind = {})); + +function memoizeFbtAndMacroOperandsInSameScope(fn) { + var _a; + const fbtMacroTags = new Set([ + ...Array.from(FBT_TAGS).map((tag) => [tag, []]), + ...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []), + ]); + const fbtValues = new Set(); + const macroMethods = new Map(); + while (true) { + let vsize = fbtValues.size; + let msize = macroMethods.size; + visit$1(fn, fbtMacroTags, fbtValues, macroMethods); + if (vsize === fbtValues.size && msize === macroMethods.size) { + break; + } + } + return fbtValues; +} +const FBT_TAGS = new Set([ + 'fbt', + 'fbt:param', + 'fbs', + 'fbs:param', +]); +const SINGLE_CHILD_FBT_TAGS = new Set([ + 'fbt:param', + 'fbs:param', +]); +function visit$1(fn, fbtMacroTags, fbtValues, macroMethods) { + for (const [, block] of fn.body.blocks) { + for (const instruction of block.instructions) { + const { lvalue, value } = instruction; + if (lvalue === null) { + continue; + } + if (value.kind === 'Primitive' && + typeof value.value === 'string' && + matchesExactTag(value.value, fbtMacroTags)) { + fbtValues.add(lvalue.identifier.id); + } + else if (value.kind === 'LoadGlobal' && + matchesExactTag(value.binding.name, fbtMacroTags)) { + fbtValues.add(lvalue.identifier.id); + } + else if (value.kind === 'LoadGlobal' && + matchTagRoot(value.binding.name, fbtMacroTags) !== null) { + const methods = matchTagRoot(value.binding.name, fbtMacroTags); + macroMethods.set(lvalue.identifier.id, methods); + } + else if (value.kind === 'PropertyLoad' && + macroMethods.has(value.object.identifier.id)) { + const methods = macroMethods.get(value.object.identifier.id); + const newMethods = []; + for (const method of methods) { + if (method.length > 0 && + (method[0].type === 'wildcard' || + (method[0].type === 'name' && method[0].name === value.property))) { + if (method.length > 1) { + newMethods.push(method.slice(1)); + } + else { + fbtValues.add(lvalue.identifier.id); + } + } + } + if (newMethods.length > 0) { + macroMethods.set(lvalue.identifier.id, newMethods); + } + } + else if (isFbtCallExpression(fbtValues, value)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + continue; + } + for (const operand of eachReactiveValueOperand(value)) { + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + fbtValues.add(operand.identifier.id); + } + } + else if (isFbtJsxExpression(fbtMacroTags, fbtValues, value) || + isFbtJsxChild(fbtValues, lvalue, value)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + continue; + } + for (const operand of eachReactiveValueOperand(value)) { + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + fbtValues.add(operand.identifier.id); + } + } + else if (fbtValues.has(lvalue.identifier.id)) { + const fbtScope = lvalue.identifier.scope; + if (fbtScope === null) { + return; + } + for (const operand of eachReactiveValueOperand(value)) { + if (operand.identifier.name !== null && + operand.identifier.name.kind === 'named') { + continue; + } + operand.identifier.scope = fbtScope; + expandFbtScopeRange(fbtScope.range, operand.identifier.mutableRange); + } + } + } + } +} +function matchesExactTag(s, tags) { + return Array.from(tags).some(macro => typeof macro === 'string' + ? s === macro + : macro[1].length === 0 && macro[0] === s); +} +function matchTagRoot(s, tags) { + const methods = []; + for (const macro of tags) { + if (typeof macro === 'string') { + continue; + } + const [tag, rest] = macro; + if (tag === s && rest.length > 0) { + methods.push(rest); + } + } + if (methods.length > 0) { + return methods; + } + else { + return null; + } +} +function isFbtCallExpression(fbtValues, value) { + return ((value.kind === 'CallExpression' && + fbtValues.has(value.callee.identifier.id)) || + (value.kind === 'MethodCall' && fbtValues.has(value.property.identifier.id))); +} +function isFbtJsxExpression(fbtMacroTags, fbtValues, value) { + return (value.kind === 'JsxExpression' && + ((value.tag.kind === 'Identifier' && + fbtValues.has(value.tag.identifier.id)) || + (value.tag.kind === 'BuiltinTag' && + matchesExactTag(value.tag.name, fbtMacroTags)))); +} +function isFbtJsxChild(fbtValues, lvalue, value) { + return ((value.kind === 'JsxExpression' || value.kind === 'JsxFragment') && + lvalue !== null && + fbtValues.has(lvalue.identifier.id)); +} +function expandFbtScopeRange(fbtRange, extendWith) { + if (extendWith.start !== 0) { + fbtRange.start = makeInstructionId(Math.min(fbtRange.start, extendWith.start)); + } +} + +var _Context_nextCacheIndex, _Context_declarations; +const MEMO_CACHE_SENTINEL = 'react.memo_cache_sentinel'; +const EARLY_RETURN_SENTINEL = 'react.early_return_sentinel'; +function codegenFunction(fn, { uniqueIdentifiers, fbtOperands, }) { + var _a, _b, _c; + const cx = new Context$1(fn.env, (_a = fn.id) !== null && _a !== void 0 ? _a : '[[ anonymous ]]', uniqueIdentifiers, fbtOperands, null); + let fastRefreshState = null; + if (fn.env.config.enableResetCacheOnSourceFileChanges && + fn.env.code !== null) { + const hash = crypto.createHmac('sha256', fn.env.code).digest('hex'); + fastRefreshState = { + cacheIndex: cx.nextCacheIndex, + hash, + }; + } + const compileResult = codegenReactiveFunction(cx, fn); + if (compileResult.isErr()) { + return compileResult; + } + const compiled = compileResult.unwrap(); + const hookGuard = fn.env.config.enableEmitHookGuards; + if (hookGuard != null && fn.env.isInferredMemoEnabled) { + compiled.body = libExports$1.blockStatement([ + createHookGuard(hookGuard, fn.env.programContext, compiled.body.body, GuardKind.PushHookGuard, GuardKind.PopHookGuard), + ]); + } + const cacheCount = compiled.memoSlotsUsed; + if (cacheCount !== 0) { + const preface = []; + const useMemoCacheIdentifier = fn.env.programContext.addMemoCacheImport().name; + preface.push(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.callExpression(libExports$1.identifier(useMemoCacheIdentifier), [ + libExports$1.numericLiteral(cacheCount), + ])), + ])); + if (fastRefreshState !== null) { + const index = cx.synthesizeName('$i'); + preface.push(libExports$1.ifStatement(libExports$1.binaryExpression('!==', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(fastRefreshState.cacheIndex), true), libExports$1.stringLiteral(fastRefreshState.hash)), libExports$1.blockStatement([ + libExports$1.forStatement(libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(index), libExports$1.numericLiteral(0)), + ]), libExports$1.binaryExpression('<', libExports$1.identifier(index), libExports$1.numericLiteral(cacheCount)), libExports$1.assignmentExpression('+=', libExports$1.identifier(index), libExports$1.numericLiteral(1)), libExports$1.blockStatement([ + libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.identifier(index), true), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(MEMO_CACHE_SENTINEL)]))), + ])), + libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(fastRefreshState.cacheIndex), true), libExports$1.stringLiteral(fastRefreshState.hash))), + ]))); + } + compiled.body.body.unshift(...preface); + } + const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget; + if (emitInstrumentForget != null && + fn.id != null && + fn.env.isInferredMemoEnabled) { + const gating = emitInstrumentForget.gating != null + ? libExports$1.identifier(fn.env.programContext.addImportSpecifier(emitInstrumentForget.gating).name) + : null; + const globalGating = emitInstrumentForget.globalGating != null + ? libExports$1.identifier(emitInstrumentForget.globalGating) + : null; + if (emitInstrumentForget.globalGating != null) { + const assertResult = fn.env.programContext.assertGlobalBinding(emitInstrumentForget.globalGating); + if (assertResult.isErr()) { + return assertResult; + } + } + let ifTest; + if (gating != null && globalGating != null) { + ifTest = libExports$1.logicalExpression('&&', globalGating, gating); + } + else if (gating != null) { + ifTest = gating; + } + else { + CompilerError.invariant(globalGating != null, { + reason: 'Bad config not caught! Expected at least one of gating or globalGating', + loc: null, + suggestions: null, + }); + ifTest = globalGating; + } + const instrumentFnIdentifier = fn.env.programContext.addImportSpecifier(emitInstrumentForget.fn).name; + const test = libExports$1.ifStatement(ifTest, libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(instrumentFnIdentifier), [ + libExports$1.stringLiteral(fn.id), + libExports$1.stringLiteral((_b = fn.env.filename) !== null && _b !== void 0 ? _b : ''), + ]))); + compiled.body.body.unshift(test); + } + const outlined = []; + for (const { fn: outlinedFunction, type } of cx.env.getOutlinedFunctions()) { + const reactiveFunction = buildReactiveFunction(outlinedFunction); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + pruneHoistedContexts(reactiveFunction); + const identifiers = renameVariables(reactiveFunction); + const codegen = codegenReactiveFunction(new Context$1(cx.env, (_c = reactiveFunction.id) !== null && _c !== void 0 ? _c : '[[ anonymous ]]', identifiers, cx.fbtOperands), reactiveFunction); + if (codegen.isErr()) { + return codegen; + } + outlined.push({ fn: codegen.unwrap(), type }); + } + compiled.outlined = outlined; + return compileResult; +} +function codegenReactiveFunction(cx, fn) { + for (const param of fn.params) { + if (param.kind === 'Identifier') { + cx.temp.set(param.identifier.declarationId, null); + } + else { + cx.temp.set(param.place.identifier.declarationId, null); + } + } + const params = fn.params.map(param => convertParameter(param)); + const body = codegenBlock(cx, fn.body); + body.directives = fn.directives.map(d => libExports$1.directive(libExports$1.directiveLiteral(d))); + const statements = body.body; + if (statements.length !== 0) { + const last = statements[statements.length - 1]; + if (last.type === 'ReturnStatement' && last.argument == null) { + statements.pop(); + } + } + if (cx.errors.hasErrors()) { + return Err(cx.errors); + } + const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env); + visitReactiveFunction(fn, countMemoBlockVisitor, undefined); + return Ok({ + type: 'CodegenFunction', + loc: fn.loc, + id: fn.id !== null ? libExports$1.identifier(fn.id) : null, + params, + body, + generator: fn.generator, + async: fn.async, + memoSlotsUsed: cx.nextCacheIndex, + memoBlocks: countMemoBlockVisitor.memoBlocks, + memoValues: countMemoBlockVisitor.memoValues, + prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks, + prunedMemoValues: countMemoBlockVisitor.prunedMemoValues, + outlined: [], + hasFireRewrite: fn.env.hasFireRewrite, + hasInferredEffect: fn.env.hasInferredEffect, + inferredEffectLocations: fn.env.inferredEffectLocations, + }); +} +class CountMemoBlockVisitor extends ReactiveFunctionVisitor { + constructor(env) { + super(); + this.memoBlocks = 0; + this.memoValues = 0; + this.prunedMemoBlocks = 0; + this.prunedMemoValues = 0; + this.env = env; + } + visitScope(scopeBlock, state) { + this.memoBlocks += 1; + this.memoValues += scopeBlock.scope.declarations.size; + this.traverseScope(scopeBlock, state); + } + visitPrunedScope(scopeBlock, state) { + this.prunedMemoBlocks += 1; + this.prunedMemoValues += scopeBlock.scope.declarations.size; + this.traversePrunedScope(scopeBlock, state); + } +} +function convertParameter(param) { + if (param.kind === 'Identifier') { + return convertIdentifier(param.identifier); + } + else { + return libExports$1.restElement(convertIdentifier(param.place.identifier)); + } +} +let Context$1 = class Context { + constructor(env, fnName, uniqueIdentifiers, fbtOperands, temporaries = null) { + _Context_nextCacheIndex.set(this, 0); + _Context_declarations.set(this, new Set()); + this.errors = new CompilerError(); + this.objectMethods = new Map(); + this.synthesizedNames = new Map(); + this.env = env; + this.fnName = fnName; + this.uniqueIdentifiers = uniqueIdentifiers; + this.fbtOperands = fbtOperands; + this.temp = temporaries !== null ? new Map(temporaries) : new Map(); + } + get nextCacheIndex() { + var _a, _b; + return __classPrivateFieldSet(this, _Context_nextCacheIndex, (_b = __classPrivateFieldGet(this, _Context_nextCacheIndex, "f"), _a = _b++, _b), "f"), _a; + } + declare(identifier) { + __classPrivateFieldGet(this, _Context_declarations, "f").add(identifier.declarationId); + } + hasDeclared(identifier) { + return __classPrivateFieldGet(this, _Context_declarations, "f").has(identifier.declarationId); + } + synthesizeName(name) { + const previous = this.synthesizedNames.get(name); + if (previous !== undefined) { + return previous; + } + let validated = makeIdentifierName(name).value; + let index = 0; + while (this.uniqueIdentifiers.has(validated)) { + validated = makeIdentifierName(`${name}${index++}`).value; + } + this.uniqueIdentifiers.add(validated); + this.synthesizedNames.set(name, validated); + return validated; + } +}; +_Context_nextCacheIndex = new WeakMap(), _Context_declarations = new WeakMap(); +function codegenBlock(cx, block) { + const temp = new Map(cx.temp); + const result = codegenBlockNoReset(cx, block); + for (const [key, value] of cx.temp) { + if (!temp.has(key)) { + continue; + } + CompilerError.invariant(temp.get(key) === value, { + loc: null, + reason: 'Expected temporary value to be unchanged', + description: null, + suggestions: null, + }); + } + cx.temp = temp; + return result; +} +function codegenBlockNoReset(cx, block) { + const statements = []; + for (const item of block) { + switch (item.kind) { + case 'instruction': { + const statement = codegenInstructionNullable(cx, item.instruction); + if (statement !== null) { + statements.push(statement); + } + break; + } + case 'pruned-scope': { + const scopeBlock = codegenBlockNoReset(cx, item.instructions); + statements.push(...scopeBlock.body); + break; + } + case 'scope': { + const temp = new Map(cx.temp); + codegenReactiveScope(cx, statements, item.scope, item.instructions); + cx.temp = temp; + break; + } + case 'terminal': { + const statement = codegenTerminal(cx, item.terminal); + if (statement === null) { + break; + } + if (item.label !== null && !item.label.implicit) { + const block = statement.type === 'BlockStatement' && statement.body.length === 1 + ? statement.body[0] + : statement; + statements.push(libExports$1.labeledStatement(libExports$1.identifier(codegenLabel(item.label.id)), block)); + } + else if (statement.type === 'BlockStatement') { + statements.push(...statement.body); + } + else { + statements.push(statement); + } + break; + } + default: { + assertExhaustive$1(item, `Unexpected item kind \`${item.kind}\``); + } + } + } + return libExports$1.blockStatement(statements); +} +function wrapCacheDep(cx, value) { + if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) { + const emitFreezeIdentifier = cx.env.programContext.addImportSpecifier(cx.env.config.enableEmitFreeze).name; + cx.env.programContext + .assertGlobalBinding(EMIT_FREEZE_GLOBAL_GATING, cx.env.scope) + .unwrap(); + return libExports$1.conditionalExpression(libExports$1.identifier(EMIT_FREEZE_GLOBAL_GATING), libExports$1.callExpression(libExports$1.identifier(emitFreezeIdentifier), [ + value, + libExports$1.stringLiteral(cx.fnName), + ]), value); + } + else { + return value; + } +} +function codegenReactiveScope(cx, statements, scope, block) { + const cacheStoreStatements = []; + const cacheLoadStatements = []; + const cacheLoads = []; + const changeExpressions = []; + const changeExpressionComments = []; + const outputComments = []; + for (const dep of [...scope.dependencies].sort(compareScopeDependency)) { + const index = cx.nextCacheIndex; + changeExpressionComments.push(printDependencyComment(dep)); + const comparison = libExports$1.binaryExpression('!==', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), codegenDependency(cx, dep)); + if (cx.env.config.enableChangeVariableCodegen) { + const changeIdentifier = libExports$1.identifier(cx.synthesizeName(`c_${index}`)); + statements.push(libExports$1.variableDeclaration('const', [ + libExports$1.variableDeclarator(changeIdentifier, comparison), + ])); + changeExpressions.push(changeIdentifier); + } + else { + changeExpressions.push(comparison); + } + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), codegenDependency(cx, dep)))); + } + let firstOutputIndex = null; + for (const [, { identifier }] of [...scope.declarations].sort(([, a], [, b]) => compareScopeDeclaration(a, b))) { + const index = cx.nextCacheIndex; + if (firstOutputIndex === null) { + firstOutputIndex = index; + } + CompilerError.invariant(identifier.name != null, { + reason: `Expected scope declaration identifier to be named`, + description: `Declaration \`${printIdentifier(identifier)}\` is unnamed in scope @${scope.id}`, + loc: null, + suggestions: null, + }); + const name = convertIdentifier(identifier); + outputComments.push(name.name); + if (!cx.hasDeclared(identifier)) { + statements.push(libExports$1.variableDeclaration('let', [libExports$1.variableDeclarator(name)])); + } + cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) }); + cx.declare(identifier); + } + for (const reassignment of scope.reassignments) { + const index = cx.nextCacheIndex; + if (firstOutputIndex === null) { + firstOutputIndex = index; + } + const name = convertIdentifier(reassignment); + outputComments.push(name.name); + cacheLoads.push({ name, index, value: wrapCacheDep(cx, name) }); + } + let testCondition = changeExpressions.reduce((acc, ident) => { + if (acc == null) { + return ident; + } + return libExports$1.logicalExpression('||', acc, ident); + }, null); + if (testCondition === null) { + CompilerError.invariant(firstOutputIndex !== null, { + reason: `Expected scope to have at least one declaration`, + description: `Scope '@${scope.id}' has no declarations`, + loc: null, + suggestions: null, + }); + testCondition = libExports$1.binaryExpression('===', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(firstOutputIndex), true), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(MEMO_CACHE_SENTINEL)])); + } + if (cx.env.config.disableMemoizationForDebugging) { + CompilerError.invariant(cx.env.config.enableChangeDetectionForDebugging == null, { + reason: `Expected to not have both change detection enabled and memoization disabled`, + description: `Incompatible config options`, + loc: null, + }); + testCondition = libExports$1.logicalExpression('||', testCondition, libExports$1.booleanLiteral(true)); + } + let computationBlock = codegenBlock(cx, block); + let memoStatement; + const detectionFunction = cx.env.config.enableChangeDetectionForDebugging; + if (detectionFunction != null && changeExpressions.length > 0) { + const loc = typeof scope.loc === 'symbol' + ? 'unknown location' + : `(${scope.loc.start.line}:${scope.loc.end.line})`; + const importedDetectionFunctionIdentifier = cx.env.programContext.addImportSpecifier(detectionFunction).name; + const cacheLoadOldValueStatements = []; + const changeDetectionStatements = []; + const idempotenceDetectionStatements = []; + for (const { name, index, value } of cacheLoads) { + const loadName = cx.synthesizeName(`old$${name.name}`); + const slot = libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true); + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', slot, value))); + cacheLoadOldValueStatements.push(libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(loadName), slot), + ])); + changeDetectionStatements.push(libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(importedDetectionFunctionIdentifier), [ + libExports$1.identifier(loadName), + libExports$1.cloneNode(name, true), + libExports$1.stringLiteral(name.name), + libExports$1.stringLiteral(cx.fnName), + libExports$1.stringLiteral('cached'), + libExports$1.stringLiteral(loc), + ]))); + idempotenceDetectionStatements.push(libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(importedDetectionFunctionIdentifier), [ + libExports$1.cloneNode(slot, true), + libExports$1.cloneNode(name, true), + libExports$1.stringLiteral(name.name), + libExports$1.stringLiteral(cx.fnName), + libExports$1.stringLiteral('recomputed'), + libExports$1.stringLiteral(loc), + ]))); + idempotenceDetectionStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', name, slot))); + } + const condition = cx.synthesizeName('condition'); + const recomputationBlock = libExports$1.cloneNode(computationBlock, true); + memoStatement = libExports$1.blockStatement([ + ...computationBlock.body, + libExports$1.variableDeclaration('let', [ + libExports$1.variableDeclarator(libExports$1.identifier(condition), testCondition), + ]), + libExports$1.ifStatement(libExports$1.unaryExpression('!', libExports$1.identifier(condition)), libExports$1.blockStatement([ + ...cacheLoadOldValueStatements, + ...changeDetectionStatements, + ])), + ...cacheStoreStatements, + libExports$1.ifStatement(libExports$1.identifier(condition), libExports$1.blockStatement([ + ...recomputationBlock.body, + ...idempotenceDetectionStatements, + ])), + ]); + } + else { + for (const { name, index, value } of cacheLoads) { + cacheStoreStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true), value))); + cacheLoadStatements.push(libExports$1.expressionStatement(libExports$1.assignmentExpression('=', name, libExports$1.memberExpression(libExports$1.identifier(cx.synthesizeName('$')), libExports$1.numericLiteral(index), true)))); + } + computationBlock.body.push(...cacheStoreStatements); + memoStatement = libExports$1.ifStatement(testCondition, computationBlock, libExports$1.blockStatement(cacheLoadStatements)); + } + if (cx.env.config.enableMemoizationComments) { + if (changeExpressionComments.length) { + libExports$1.addComment(memoStatement, 'leading', ` check if ${printDelimitedCommentList(changeExpressionComments, 'or')} changed`, true); + libExports$1.addComment(memoStatement, 'leading', ` "useMemo" for ${printDelimitedCommentList(outputComments, 'and')}:`, true); + } + else { + libExports$1.addComment(memoStatement, 'leading', ' cache value with no dependencies', true); + libExports$1.addComment(memoStatement, 'leading', ` "useMemo" for ${printDelimitedCommentList(outputComments, 'and')}:`, true); + } + if (computationBlock.body.length > 0) { + libExports$1.addComment(computationBlock.body[0], 'leading', ` Inputs changed, recompute`, true); + } + if (cacheLoadStatements.length > 0) { + libExports$1.addComment(cacheLoadStatements[0], 'leading', ` Inputs did not change, use cached value`, true); + } + } + statements.push(memoStatement); + const earlyReturnValue = scope.earlyReturnValue; + if (earlyReturnValue !== null) { + CompilerError.invariant(earlyReturnValue.value.name !== null && + earlyReturnValue.value.name.kind === 'named', { + reason: `Expected early return value to be promoted to a named variable`, + loc: earlyReturnValue.loc, + description: null, + suggestions: null, + }); + const name = earlyReturnValue.value.name.value; + statements.push(libExports$1.ifStatement(libExports$1.binaryExpression('!==', libExports$1.identifier(name), libExports$1.callExpression(libExports$1.memberExpression(libExports$1.identifier('Symbol'), libExports$1.identifier('for')), [libExports$1.stringLiteral(EARLY_RETURN_SENTINEL)])), libExports$1.blockStatement([libExports$1.returnStatement(libExports$1.identifier(name))]))); + } +} +function codegenTerminal(cx, terminal) { + switch (terminal.kind) { + case 'break': { + if (terminal.targetKind === 'implicit') { + return null; + } + return libExports$1.breakStatement(terminal.targetKind === 'labeled' + ? libExports$1.identifier(codegenLabel(terminal.target)) + : null); + } + case 'continue': { + if (terminal.targetKind === 'implicit') { + return null; + } + return libExports$1.continueStatement(terminal.targetKind === 'labeled' + ? libExports$1.identifier(codegenLabel(terminal.target)) + : null); + } + case 'for': { + return libExports$1.forStatement(codegenForInit(cx, terminal.init), codegenInstructionValueToExpression(cx, terminal.test), terminal.update !== null + ? codegenInstructionValueToExpression(cx, terminal.update) + : null, codegenBlock(cx, terminal.loop)); + } + case 'for-in': { + CompilerError.invariant(terminal.init.kind === 'SequenceExpression', { + reason: `Expected a sequence expression init for for..in`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.init.loc, + suggestions: null, + }); + if (terminal.init.instructions.length !== 2) { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..in inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + const iterableCollection = terminal.init.instructions[0]; + const iterableItem = terminal.init.instructions[1]; + let lval; + switch (iterableItem.value.kind) { + case 'StoreLocal': { + lval = codegenLValue(cx, iterableItem.value.lvalue.place); + break; + } + case 'Destructure': { + lval = codegenLValue(cx, iterableItem.value.lvalue.pattern); + break; + } + case 'StoreContext': { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..in inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + default: + CompilerError.invariant(false, { + reason: `Expected a StoreLocal or Destructure to be assigned to the collection`, + description: `Found ${iterableItem.value.kind}`, + loc: iterableItem.value.loc, + suggestions: null, + }); + } + let varDeclKind; + switch (iterableItem.value.lvalue.kind) { + case InstructionKind.Const: + varDeclKind = 'const'; + break; + case InstructionKind.Let: + varDeclKind = 'let'; + break; + case InstructionKind.Reassign: + CompilerError.invariant(false, { + reason: 'Destructure should never be Reassign as it would be an Object/ArrayPattern', + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + case InstructionKind.Catch: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedLet: + case InstructionKind.HoistedFunction: + case InstructionKind.Function: + CompilerError.invariant(false, { + reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..in collection`, + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + default: + assertExhaustive$1(iterableItem.value.lvalue.kind, `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`); + } + return libExports$1.forInStatement(createVariableDeclaration(iterableItem.value.loc, varDeclKind, [ + libExports$1.variableDeclarator(lval, null), + ]), codegenInstructionValueToExpression(cx, iterableCollection.value), codegenBlock(cx, terminal.loop)); + } + case 'for-of': { + CompilerError.invariant(terminal.init.kind === 'SequenceExpression' && + terminal.init.instructions.length === 1 && + terminal.init.instructions[0].value.kind === 'GetIterator', { + reason: `Expected a single-expression sequence expression init for for..of`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.init.loc, + suggestions: null, + }); + const iterableCollection = terminal.init.instructions[0].value; + CompilerError.invariant(terminal.test.kind === 'SequenceExpression', { + reason: `Expected a sequence expression test for for..of`, + description: `Got \`${terminal.init.kind}\` expression instead`, + loc: terminal.test.loc, + suggestions: null, + }); + if (terminal.test.instructions.length !== 2) { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..of inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + const iterableItem = terminal.test.instructions[1]; + let lval; + switch (iterableItem.value.kind) { + case 'StoreLocal': { + lval = codegenLValue(cx, iterableItem.value.lvalue.place); + break; + } + case 'Destructure': { + lval = codegenLValue(cx, iterableItem.value.lvalue.pattern); + break; + } + case 'StoreContext': { + CompilerError.throwTodo({ + reason: 'Support non-trivial for..of inits', + description: null, + loc: terminal.init.loc, + suggestions: null, + }); + } + default: + CompilerError.invariant(false, { + reason: `Expected a StoreLocal or Destructure to be assigned to the collection`, + description: `Found ${iterableItem.value.kind}`, + loc: iterableItem.value.loc, + suggestions: null, + }); + } + let varDeclKind; + switch (iterableItem.value.lvalue.kind) { + case InstructionKind.Const: + varDeclKind = 'const'; + break; + case InstructionKind.Let: + varDeclKind = 'let'; + break; + case InstructionKind.Reassign: + case InstructionKind.Catch: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedLet: + case InstructionKind.HoistedFunction: + case InstructionKind.Function: + CompilerError.invariant(false, { + reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..of collection`, + description: null, + loc: iterableItem.loc, + suggestions: null, + }); + default: + assertExhaustive$1(iterableItem.value.lvalue.kind, `Unhandled lvalue kind: ${iterableItem.value.lvalue.kind}`); + } + return libExports$1.forOfStatement(createVariableDeclaration(iterableItem.value.loc, varDeclKind, [ + libExports$1.variableDeclarator(lval, null), + ]), codegenInstructionValueToExpression(cx, iterableCollection), codegenBlock(cx, terminal.loop)); + } + case 'if': { + const test = codegenPlaceToExpression(cx, terminal.test); + const consequent = codegenBlock(cx, terminal.consequent); + let alternate = null; + if (terminal.alternate !== null) { + const block = codegenBlock(cx, terminal.alternate); + if (block.body.length !== 0) { + alternate = block; + } + } + return libExports$1.ifStatement(test, consequent, alternate); + } + case 'return': { + const value = codegenPlaceToExpression(cx, terminal.value); + if (value.type === 'Identifier' && value.name === 'undefined') { + return libExports$1.returnStatement(); + } + return libExports$1.returnStatement(value); + } + case 'switch': { + return libExports$1.switchStatement(codegenPlaceToExpression(cx, terminal.test), terminal.cases.map(case_ => { + const test = case_.test !== null + ? codegenPlaceToExpression(cx, case_.test) + : null; + const block = codegenBlock(cx, case_.block); + return libExports$1.switchCase(test, [block]); + })); + } + case 'throw': { + return libExports$1.throwStatement(codegenPlaceToExpression(cx, terminal.value)); + } + case 'do-while': { + const test = codegenInstructionValueToExpression(cx, terminal.test); + return libExports$1.doWhileStatement(test, codegenBlock(cx, terminal.loop)); + } + case 'while': { + const test = codegenInstructionValueToExpression(cx, terminal.test); + return libExports$1.whileStatement(test, codegenBlock(cx, terminal.loop)); + } + case 'label': { + return codegenBlock(cx, terminal.block); + } + case 'try': { + let catchParam = null; + if (terminal.handlerBinding !== null) { + catchParam = convertIdentifier(terminal.handlerBinding.identifier); + cx.temp.set(terminal.handlerBinding.identifier.declarationId, null); + } + return libExports$1.tryStatement(codegenBlock(cx, terminal.block), libExports$1.catchClause(catchParam, codegenBlock(cx, terminal.handler))); + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } +} +function codegenInstructionNullable(cx, instr) { + if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext' || + instr.value.kind === 'Destructure' || + instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + let kind = instr.value.lvalue.kind; + let lvalue; + let value; + if (instr.value.kind === 'StoreLocal') { + kind = cx.hasDeclared(instr.value.lvalue.place.identifier) + ? InstructionKind.Reassign + : kind; + lvalue = instr.value.lvalue.place; + value = codegenPlaceToExpression(cx, instr.value.value); + } + else if (instr.value.kind === 'StoreContext') { + lvalue = instr.value.lvalue.place; + value = codegenPlaceToExpression(cx, instr.value.value); + } + else if (instr.value.kind === 'DeclareLocal' || + instr.value.kind === 'DeclareContext') { + if (cx.hasDeclared(instr.value.lvalue.place.identifier)) { + return null; + } + kind = instr.value.lvalue.kind; + lvalue = instr.value.lvalue.place; + value = null; + } + else { + lvalue = instr.value.lvalue.pattern; + let hasReassign = false; + let hasDeclaration = false; + for (const place of eachPatternOperand(lvalue)) { + if (kind !== InstructionKind.Reassign && + place.identifier.name === null) { + cx.temp.set(place.identifier.declarationId, null); + } + const isDeclared = cx.hasDeclared(place.identifier); + hasReassign || (hasReassign = isDeclared); + hasDeclaration || (hasDeclaration = !isDeclared); + } + if (hasReassign && hasDeclaration) { + CompilerError.invariant(false, { + reason: 'Encountered a destructuring operation where some identifiers are already declared (reassignments) but others are not (declarations)', + description: null, + loc: instr.loc, + suggestions: null, + }); + } + else if (hasReassign) { + kind = InstructionKind.Reassign; + } + value = codegenPlaceToExpression(cx, instr.value.value); + } + switch (kind) { + case InstructionKind.Const: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Const declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createVariableDeclaration(instr.loc, 'const', [ + libExports$1.variableDeclarator(codegenLValue(cx, lvalue), value), + ]); + } + case InstructionKind.Function: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Function declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + const genLvalue = codegenLValue(cx, lvalue); + CompilerError.invariant(genLvalue.type === 'Identifier', { + reason: 'Expected an identifier as a function declaration lvalue', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + CompilerError.invariant((value === null || value === void 0 ? void 0 : value.type) === 'FunctionExpression', { + reason: 'Expected a function as a function declaration value', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createFunctionDeclaration(instr.loc, genLvalue, value.params, value.body, value.generator, value.async); + } + case InstructionKind.Let: { + CompilerError.invariant(instr.lvalue === null, { + reason: `Const declaration cannot be referenced as an expression`, + description: null, + loc: instr.value.loc, + suggestions: null, + }); + return createVariableDeclaration(instr.loc, 'let', [ + libExports$1.variableDeclarator(codegenLValue(cx, lvalue), value), + ]); + } + case InstructionKind.Reassign: { + CompilerError.invariant(value !== null, { + reason: 'Expected a value for reassignment', + description: null, + loc: instr.value.loc, + suggestions: null, + }); + const expr = libExports$1.assignmentExpression('=', codegenLValue(cx, lvalue), value); + if (instr.lvalue !== null) { + if (instr.value.kind !== 'StoreContext') { + cx.temp.set(instr.lvalue.identifier.declarationId, expr); + return null; + } + else { + const statement = codegenInstruction(cx, instr, expr); + if (statement.type === 'EmptyStatement') { + return null; + } + return statement; + } + } + else { + return createExpressionStatement(instr.loc, expr); + } + } + case InstructionKind.Catch: { + return libExports$1.emptyStatement(); + } + case InstructionKind.HoistedLet: + case InstructionKind.HoistedConst: + case InstructionKind.HoistedFunction: { + CompilerError.invariant(false, { + reason: `Expected ${kind} to have been pruned in PruneHoistedContexts`, + description: null, + loc: instr.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(kind, `Unexpected instruction kind \`${kind}\``); + } + } + } + else if (instr.value.kind === 'StartMemoize' || + instr.value.kind === 'FinishMemoize') { + return null; + } + else if (instr.value.kind === 'Debugger') { + return libExports$1.debuggerStatement(); + } + else if (instr.value.kind === 'ObjectMethod') { + CompilerError.invariant(instr.lvalue, { + reason: 'Expected object methods to have a temp lvalue', + loc: null, + suggestions: null, + }); + cx.objectMethods.set(instr.lvalue.identifier.id, instr.value); + return null; + } + else { + const value = codegenInstructionValue(cx, instr.value); + const statement = codegenInstruction(cx, instr, value); + if (statement.type === 'EmptyStatement') { + return null; + } + return statement; + } +} +function codegenForInit(cx, init) { + if (init.kind === 'SequenceExpression') { + const body = codegenBlock(cx, init.instructions.map(instruction => ({ + kind: 'instruction', + instruction, + }))).body; + const declarators = []; + let kind = 'const'; + body.forEach(instr => { + var _a; + let top = undefined; + if (instr.type === 'ExpressionStatement' && + instr.expression.type === 'AssignmentExpression' && + instr.expression.operator === '=' && + instr.expression.left.type === 'Identifier' && + ((_a = (top = declarators.at(-1))) === null || _a === void 0 ? void 0 : _a.id.type) === 'Identifier' && + (top === null || top === void 0 ? void 0 : top.id.name) === instr.expression.left.name && + (top === null || top === void 0 ? void 0 : top.init) == null) { + top.init = instr.expression.right; + } + else { + CompilerError.invariant(instr.type === 'VariableDeclaration' && + (instr.kind === 'let' || instr.kind === 'const'), { + reason: 'Expected a variable declaration', + loc: init.loc, + description: `Got ${instr.type}`, + suggestions: null, + }); + if (instr.kind === 'let') { + kind = 'let'; + } + declarators.push(...instr.declarations); + } + }); + CompilerError.invariant(declarators.length > 0, { + reason: 'Expected a variable declaration', + loc: init.loc, + description: null, + suggestions: null, + }); + return libExports$1.variableDeclaration(kind, declarators); + } + else { + return codegenInstructionValueToExpression(cx, init); + } +} +function printDependencyComment(dependency) { + const identifier = convertIdentifier(dependency.identifier); + let name = identifier.name; + if (dependency.path !== null) { + for (const path of dependency.path) { + name += `.${path.property}`; + } + } + return name; +} +function printDelimitedCommentList(items, finalCompletion) { + if (items.length === 2) { + return items.join(` ${finalCompletion} `); + } + else if (items.length <= 1) { + return items.join(''); + } + let output = []; + for (let i = 0; i < items.length; i++) { + const item = items[i]; + if (i < items.length - 2) { + output.push(`${item}, `); + } + else if (i === items.length - 2) { + output.push(`${item}, ${finalCompletion} `); + } + else { + output.push(item); + } + } + return output.join(''); +} +function codegenDependency(cx, dependency) { + let object = convertIdentifier(dependency.identifier); + if (dependency.path.length !== 0) { + const hasOptional = dependency.path.some(path => path.optional); + for (const path of dependency.path) { + const property = typeof path.property === 'string' + ? libExports$1.identifier(path.property) + : libExports$1.numericLiteral(path.property); + const isComputed = typeof path.property !== 'string'; + if (hasOptional) { + object = libExports$1.optionalMemberExpression(object, property, isComputed, path.optional); + } + else { + object = libExports$1.memberExpression(object, property, isComputed); + } + } + } + return object; +} +function withLoc(fn) { + return (loc, ...args) => { + const node = fn(...args); + if (loc != null && loc != GeneratedSource) { + node.loc = loc; + } + return node; + }; +} +const createBinaryExpression = withLoc(libExports$1.binaryExpression); +const createExpressionStatement = withLoc(libExports$1.expressionStatement); +const createVariableDeclaration = withLoc(libExports$1.variableDeclaration); +const createFunctionDeclaration = withLoc(libExports$1.functionDeclaration); +const createTaggedTemplateExpression = withLoc(libExports$1.taggedTemplateExpression); +const createLogicalExpression = withLoc(libExports$1.logicalExpression); +const createSequenceExpression = withLoc(libExports$1.sequenceExpression); +const createConditionalExpression = withLoc(libExports$1.conditionalExpression); +const createTemplateLiteral = withLoc(libExports$1.templateLiteral); +const createJsxNamespacedName = withLoc(libExports$1.jsxNamespacedName); +const createJsxElement = withLoc(libExports$1.jsxElement); +const createJsxAttribute = withLoc(libExports$1.jsxAttribute); +const createJsxIdentifier = withLoc(libExports$1.jsxIdentifier); +const createJsxExpressionContainer = withLoc(libExports$1.jsxExpressionContainer); +const createJsxText = withLoc(libExports$1.jsxText); +const createJsxClosingElement = withLoc(libExports$1.jsxClosingElement); +const createJsxOpeningElement = withLoc(libExports$1.jsxOpeningElement); +const createStringLiteral = withLoc(libExports$1.stringLiteral); +function createHookGuard(guard, context, stmts, before, after) { + const guardFnName = context.addImportSpecifier(guard).name; + function createHookGuardImpl(kind) { + return libExports$1.expressionStatement(libExports$1.callExpression(libExports$1.identifier(guardFnName), [libExports$1.numericLiteral(kind)])); + } + return libExports$1.tryStatement(libExports$1.blockStatement([createHookGuardImpl(before), ...stmts]), null, libExports$1.blockStatement([createHookGuardImpl(after)])); +} +function createCallExpression(env, callee, args, loc, isHook) { + const callExpr = libExports$1.callExpression(callee, args); + if (loc != null && loc != GeneratedSource) { + callExpr.loc = loc; + } + const hookGuard = env.config.enableEmitHookGuards; + if (hookGuard != null && isHook && env.isInferredMemoEnabled) { + const iife = libExports$1.functionExpression(null, [], libExports$1.blockStatement([ + createHookGuard(hookGuard, env.programContext, [libExports$1.returnStatement(callExpr)], GuardKind.AllowHook, GuardKind.DisallowHook), + ])); + return libExports$1.callExpression(iife, []); + } + else { + return callExpr; + } +} +function codegenLabel(id) { + return `bb${id}`; +} +function codegenInstruction(cx, instr, value) { + if (libExports$1.isStatement(value)) { + return value; + } + if (instr.lvalue === null) { + return libExports$1.expressionStatement(convertValueToExpression(value)); + } + if (instr.lvalue.identifier.name === null) { + cx.temp.set(instr.lvalue.identifier.declarationId, value); + return libExports$1.emptyStatement(); + } + else { + const expressionValue = convertValueToExpression(value); + if (cx.hasDeclared(instr.lvalue.identifier)) { + return createExpressionStatement(instr.loc, libExports$1.assignmentExpression('=', convertIdentifier(instr.lvalue.identifier), expressionValue)); + } + else { + return createVariableDeclaration(instr.loc, 'const', [ + libExports$1.variableDeclarator(convertIdentifier(instr.lvalue.identifier), expressionValue), + ]); + } + } +} +function convertValueToExpression(value) { + if (value.type === 'JSXText') { + return createStringLiteral(value.loc, value.value); + } + return value; +} +function codegenInstructionValueToExpression(cx, instrValue) { + const value = codegenInstructionValue(cx, instrValue); + return convertValueToExpression(value); +} +function codegenInstructionValue(cx, instrValue) { + var _a, _b, _c, _d, _e, _f, _g, _h; + let value; + switch (instrValue.kind) { + case 'ArrayExpression': { + const elements = instrValue.elements.map(element => { + if (element.kind === 'Identifier') { + return codegenPlaceToExpression(cx, element); + } + else if (element.kind === 'Spread') { + return libExports$1.spreadElement(codegenPlaceToExpression(cx, element.place)); + } + else { + return null; + } + }); + value = libExports$1.arrayExpression(elements); + break; + } + case 'BinaryExpression': { + const left = codegenPlaceToExpression(cx, instrValue.left); + const right = codegenPlaceToExpression(cx, instrValue.right); + value = createBinaryExpression(instrValue.loc, instrValue.operator, left, right); + break; + } + case 'UnaryExpression': { + value = libExports$1.unaryExpression(instrValue.operator, codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'Primitive': { + value = codegenValue(cx, instrValue.loc, instrValue.value); + break; + } + case 'CallExpression': { + if (cx.env.config.enableForest) { + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = libExports$1.callExpression(callee, args); + if (instrValue.typeArguments != null) { + value.typeArguments = libExports$1.typeParameterInstantiation(instrValue.typeArguments); + } + break; + } + const isHook = getHookKind(cx.env, instrValue.callee.identifier) != null; + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = createCallExpression(cx.env, callee, args, instrValue.loc, isHook); + break; + } + case 'OptionalExpression': { + const optionalValue = codegenInstructionValueToExpression(cx, instrValue.value); + switch (optionalValue.type) { + case 'OptionalCallExpression': + case 'CallExpression': { + CompilerError.invariant(libExports$1.isExpression(optionalValue.callee), { + reason: 'v8 intrinsics are validated during lowering', + description: null, + loc: (_a = optionalValue.callee.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + value = libExports$1.optionalCallExpression(optionalValue.callee, optionalValue.arguments, instrValue.optional); + break; + } + case 'OptionalMemberExpression': + case 'MemberExpression': { + const property = optionalValue.property; + CompilerError.invariant(libExports$1.isExpression(property), { + reason: 'Private names are validated during lowering', + description: null, + loc: (_b = property.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + value = libExports$1.optionalMemberExpression(optionalValue.object, property, optionalValue.computed, instrValue.optional); + break; + } + default: { + CompilerError.invariant(false, { + reason: 'Expected an optional value to resolve to a call expression or member expression', + description: `Got a \`${optionalValue.type}\``, + loc: instrValue.loc, + suggestions: null, + }); + } + } + break; + } + case 'MethodCall': { + const isHook = getHookKind(cx.env, instrValue.property.identifier) != null; + const memberExpr = codegenPlaceToExpression(cx, instrValue.property); + CompilerError.invariant(libExports$1.isMemberExpression(memberExpr) || + libExports$1.isOptionalMemberExpression(memberExpr), { + reason: '[Codegen] Internal error: MethodCall::property must be an unpromoted + unmemoized MemberExpression. ' + + `Got a \`${memberExpr.type}\``, + description: null, + loc: (_c = memberExpr.loc) !== null && _c !== void 0 ? _c : null, + suggestions: null, + }); + CompilerError.invariant(libExports$1.isNodesEquivalent(memberExpr.object, codegenPlaceToExpression(cx, instrValue.receiver)), { + reason: '[Codegen] Internal error: Forget should always generate MethodCall::property ' + + 'as a MemberExpression of MethodCall::receiver', + description: null, + loc: (_d = memberExpr.loc) !== null && _d !== void 0 ? _d : null, + suggestions: null, + }); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = createCallExpression(cx.env, memberExpr, args, instrValue.loc, isHook); + break; + } + case 'NewExpression': { + const callee = codegenPlaceToExpression(cx, instrValue.callee); + const args = instrValue.args.map(arg => codegenArgument(cx, arg)); + value = libExports$1.newExpression(callee, args); + break; + } + case 'ObjectExpression': { + const properties = []; + for (const property of instrValue.properties) { + if (property.kind === 'ObjectProperty') { + const key = codegenObjectPropertyKey(cx, property.key); + switch (property.type) { + case 'property': { + const value = codegenPlaceToExpression(cx, property.place); + properties.push(libExports$1.objectProperty(key, value, property.key.kind === 'computed', key.type === 'Identifier' && + value.type === 'Identifier' && + value.name === key.name)); + break; + } + case 'method': { + const method = cx.objectMethods.get(property.place.identifier.id); + CompilerError.invariant(method, { + reason: 'Expected ObjectMethod instruction', + loc: null, + suggestions: null, + }); + const loweredFunc = method.loweredFunc; + const reactiveFunction = buildReactiveFunction(loweredFunc.func); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + const fn = codegenReactiveFunction(new Context$1(cx.env, (_e = reactiveFunction.id) !== null && _e !== void 0 ? _e : '[[ anonymous ]]', cx.uniqueIdentifiers, cx.fbtOperands, cx.temp), reactiveFunction).unwrap(); + const babelNode = libExports$1.objectMethod('method', key, fn.params, fn.body, false); + babelNode.async = fn.async; + babelNode.generator = fn.generator; + properties.push(babelNode); + break; + } + default: + assertExhaustive$1(property.type, `Unexpected property type: ${property.type}`); + } + } + else { + properties.push(libExports$1.spreadElement(codegenPlaceToExpression(cx, property.place))); + } + } + value = libExports$1.objectExpression(properties); + break; + } + case 'JSXText': { + value = createJsxText(instrValue.loc, instrValue.value); + break; + } + case 'JsxExpression': { + const attributes = []; + for (const attribute of instrValue.props) { + attributes.push(codegenJsxAttribute(cx, attribute)); + } + let tagValue = instrValue.tag.kind === 'Identifier' + ? codegenPlaceToExpression(cx, instrValue.tag) + : libExports$1.stringLiteral(instrValue.tag.name); + let tag; + if (tagValue.type === 'Identifier') { + tag = createJsxIdentifier(instrValue.tag.loc, tagValue.name); + } + else if (tagValue.type === 'MemberExpression') { + tag = convertMemberExpressionToJsx(tagValue); + } + else { + CompilerError.invariant(tagValue.type === 'StringLiteral', { + reason: `Expected JSX tag to be an identifier or string, got \`${tagValue.type}\``, + description: null, + loc: (_f = tagValue.loc) !== null && _f !== void 0 ? _f : null, + suggestions: null, + }); + if (tagValue.value.indexOf(':') >= 0) { + const [namespace, name] = tagValue.value.split(':', 2); + tag = createJsxNamespacedName(instrValue.tag.loc, createJsxIdentifier(instrValue.tag.loc, namespace), createJsxIdentifier(instrValue.tag.loc, name)); + } + else { + tag = createJsxIdentifier(instrValue.loc, tagValue.value); + } + } + let children; + if (tagValue.type === 'StringLiteral' && + SINGLE_CHILD_FBT_TAGS.has(tagValue.value)) { + CompilerError.invariant(instrValue.children != null, { + loc: instrValue.loc, + reason: 'Expected fbt element to have children', + suggestions: null, + description: null, + }); + children = instrValue.children.map(child => codegenJsxFbtChildElement(cx, child)); + } + else { + children = + instrValue.children !== null + ? instrValue.children.map(child => codegenJsxElement(cx, child)) + : []; + } + value = createJsxElement(instrValue.loc, createJsxOpeningElement(instrValue.openingLoc, tag, attributes, instrValue.children === null), instrValue.children !== null + ? createJsxClosingElement(instrValue.closingLoc, tag) + : null, children, instrValue.children === null); + break; + } + case 'JsxFragment': { + value = libExports$1.jsxFragment(libExports$1.jsxOpeningFragment(), libExports$1.jsxClosingFragment(), instrValue.children.map(child => codegenJsxElement(cx, child))); + break; + } + case 'UnsupportedNode': { + const node = instrValue.node; + if (!libExports$1.isExpression(node)) { + return node; + } + value = node; + break; + } + case 'PropertyStore': + case 'PropertyLoad': + case 'PropertyDelete': { + let memberExpr; + if (typeof instrValue.property === 'string') { + memberExpr = libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), libExports$1.identifier(instrValue.property)); + } + else { + memberExpr = libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), libExports$1.numericLiteral(instrValue.property), true); + } + if (instrValue.kind === 'PropertyStore') { + value = libExports$1.assignmentExpression('=', memberExpr, codegenPlaceToExpression(cx, instrValue.value)); + } + else if (instrValue.kind === 'PropertyLoad') { + value = memberExpr; + } + else { + value = libExports$1.unaryExpression('delete', memberExpr); + } + break; + } + case 'ComputedStore': { + value = libExports$1.assignmentExpression('=', libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), codegenPlaceToExpression(cx, instrValue.property), true), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'ComputedLoad': { + const object = codegenPlaceToExpression(cx, instrValue.object); + const property = codegenPlaceToExpression(cx, instrValue.property); + value = libExports$1.memberExpression(object, property, true); + break; + } + case 'ComputedDelete': { + value = libExports$1.unaryExpression('delete', libExports$1.memberExpression(codegenPlaceToExpression(cx, instrValue.object), codegenPlaceToExpression(cx, instrValue.property), true)); + break; + } + case 'LoadLocal': + case 'LoadContext': { + value = codegenPlaceToExpression(cx, instrValue.place); + break; + } + case 'FunctionExpression': { + const loweredFunc = instrValue.loweredFunc.func; + const reactiveFunction = buildReactiveFunction(loweredFunc); + pruneUnusedLabels(reactiveFunction); + pruneUnusedLValues(reactiveFunction); + pruneHoistedContexts(reactiveFunction); + const fn = codegenReactiveFunction(new Context$1(cx.env, (_g = reactiveFunction.id) !== null && _g !== void 0 ? _g : '[[ anonymous ]]', cx.uniqueIdentifiers, cx.fbtOperands, cx.temp), reactiveFunction).unwrap(); + if (instrValue.type === 'ArrowFunctionExpression') { + let body = fn.body; + if (body.body.length === 1 && loweredFunc.directives.length == 0) { + const stmt = body.body[0]; + if (stmt.type === 'ReturnStatement' && stmt.argument != null) { + body = stmt.argument; + } + } + value = libExports$1.arrowFunctionExpression(fn.params, body, fn.async); + } + else { + value = libExports$1.functionExpression((_h = fn.id) !== null && _h !== void 0 ? _h : (instrValue.name != null ? libExports$1.identifier(instrValue.name) : null), fn.params, fn.body, fn.generator, fn.async); + } + break; + } + case 'TaggedTemplateExpression': { + value = createTaggedTemplateExpression(instrValue.loc, codegenPlaceToExpression(cx, instrValue.tag), libExports$1.templateLiteral([libExports$1.templateElement(instrValue.value)], [])); + break; + } + case 'TypeCastExpression': { + if (libExports$1.isTSType(instrValue.typeAnnotation)) { + if (instrValue.typeAnnotationKind === 'satisfies') { + value = libExports$1.tsSatisfiesExpression(codegenPlaceToExpression(cx, instrValue.value), instrValue.typeAnnotation); + } + else { + value = libExports$1.tsAsExpression(codegenPlaceToExpression(cx, instrValue.value), instrValue.typeAnnotation); + } + } + else { + value = libExports$1.typeCastExpression(codegenPlaceToExpression(cx, instrValue.value), libExports$1.typeAnnotation(instrValue.typeAnnotation)); + } + break; + } + case 'LogicalExpression': { + value = createLogicalExpression(instrValue.loc, instrValue.operator, codegenInstructionValueToExpression(cx, instrValue.left), codegenInstructionValueToExpression(cx, instrValue.right)); + break; + } + case 'ConditionalExpression': { + value = createConditionalExpression(instrValue.loc, codegenInstructionValueToExpression(cx, instrValue.test), codegenInstructionValueToExpression(cx, instrValue.consequent), codegenInstructionValueToExpression(cx, instrValue.alternate)); + break; + } + case 'SequenceExpression': { + const body = codegenBlockNoReset(cx, instrValue.instructions.map(instruction => ({ + kind: 'instruction', + instruction, + }))).body; + const expressions = body.map(stmt => { + var _a, _b; + if (stmt.type === 'ExpressionStatement') { + return stmt.expression; + } + else { + if (libExports$1.isVariableDeclaration(stmt)) { + const declarator = stmt.declarations[0]; + cx.errors.push({ + reason: `(CodegenReactiveFunction::codegenInstructionValue) Cannot declare variables in a value block, tried to declare '${declarator.id.name}'`, + severity: ErrorSeverity.Todo, + loc: (_a = declarator.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + return libExports$1.stringLiteral(`TODO handle ${declarator.id}`); + } + else { + cx.errors.push({ + reason: `(CodegenReactiveFunction::codegenInstructionValue) Handle conversion of ${stmt.type} to expression`, + severity: ErrorSeverity.Todo, + loc: (_b = stmt.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + return libExports$1.stringLiteral(`TODO handle ${stmt.type}`); + } + } + }); + if (expressions.length === 0) { + value = codegenInstructionValueToExpression(cx, instrValue.value); + } + else { + value = createSequenceExpression(instrValue.loc, [ + ...expressions, + codegenInstructionValueToExpression(cx, instrValue.value), + ]); + } + break; + } + case 'TemplateLiteral': { + value = createTemplateLiteral(instrValue.loc, instrValue.quasis.map(q => libExports$1.templateElement(q)), instrValue.subexprs.map(p => codegenPlaceToExpression(cx, p))); + break; + } + case 'LoadGlobal': { + value = libExports$1.identifier(instrValue.binding.name); + break; + } + case 'RegExpLiteral': { + value = libExports$1.regExpLiteral(instrValue.pattern, instrValue.flags); + break; + } + case 'MetaProperty': { + value = libExports$1.metaProperty(libExports$1.identifier(instrValue.meta), libExports$1.identifier(instrValue.property)); + break; + } + case 'Await': { + value = libExports$1.awaitExpression(codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'GetIterator': { + value = codegenPlaceToExpression(cx, instrValue.collection); + break; + } + case 'IteratorNext': { + value = codegenPlaceToExpression(cx, instrValue.iterator); + break; + } + case 'NextPropertyOf': { + value = codegenPlaceToExpression(cx, instrValue.value); + break; + } + case 'PostfixUpdate': { + value = libExports$1.updateExpression(instrValue.operation, codegenPlaceToExpression(cx, instrValue.lvalue), false); + break; + } + case 'PrefixUpdate': { + value = libExports$1.updateExpression(instrValue.operation, codegenPlaceToExpression(cx, instrValue.lvalue), true); + break; + } + case 'StoreLocal': { + CompilerError.invariant(instrValue.lvalue.kind === InstructionKind.Reassign, { + reason: `Unexpected StoreLocal in codegenInstructionValue`, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + value = libExports$1.assignmentExpression('=', codegenLValue(cx, instrValue.lvalue.place), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'StoreGlobal': { + value = libExports$1.assignmentExpression('=', libExports$1.identifier(instrValue.name), codegenPlaceToExpression(cx, instrValue.value)); + break; + } + case 'StartMemoize': + case 'FinishMemoize': + case 'Debugger': + case 'DeclareLocal': + case 'DeclareContext': + case 'Destructure': + case 'ObjectMethod': + case 'StoreContext': { + CompilerError.invariant(false, { + reason: `Unexpected ${instrValue.kind} in codegenInstructionValue`, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(instrValue, `Unexpected instruction value kind \`${instrValue.kind}\``); + } + } + return value; +} +const STRING_REQUIRES_EXPR_CONTAINER_PATTERN = /[\u{0000}-\u{001F}\u{007F}\u{0080}-\u{FFFF}]|"|\\/u; +function codegenJsxAttribute(cx, attribute) { + switch (attribute.kind) { + case 'JsxAttribute': { + let propName; + if (attribute.name.indexOf(':') === -1) { + propName = createJsxIdentifier(attribute.place.loc, attribute.name); + } + else { + const [namespace, name] = attribute.name.split(':', 2); + propName = createJsxNamespacedName(attribute.place.loc, createJsxIdentifier(attribute.place.loc, namespace), createJsxIdentifier(attribute.place.loc, name)); + } + const innerValue = codegenPlaceToExpression(cx, attribute.place); + let value; + switch (innerValue.type) { + case 'StringLiteral': { + value = innerValue; + if (STRING_REQUIRES_EXPR_CONTAINER_PATTERN.test(value.value) && + !cx.fbtOperands.has(attribute.place.identifier.id)) { + value = createJsxExpressionContainer(value.loc, value); + } + break; + } + default: { + value = createJsxExpressionContainer(attribute.place.loc, innerValue); + break; + } + } + return createJsxAttribute(attribute.place.loc, propName, value); + } + case 'JsxSpreadAttribute': { + return libExports$1.jsxSpreadAttribute(codegenPlaceToExpression(cx, attribute.argument)); + } + default: { + assertExhaustive$1(attribute, `Unexpected attribute kind \`${attribute.kind}\``); + } + } +} +const JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN = /[<>&{}]/; +function codegenJsxElement(cx, place) { + const value = codegenPlace(cx, place); + switch (value.type) { + case 'JSXText': { + if (JSX_TEXT_CHILD_REQUIRES_EXPR_CONTAINER_PATTERN.test(value.value)) { + return createJsxExpressionContainer(place.loc, createStringLiteral(place.loc, value.value)); + } + return createJsxText(place.loc, value.value); + } + case 'JSXElement': + case 'JSXFragment': { + return value; + } + default: { + return createJsxExpressionContainer(place.loc, value); + } + } +} +function codegenJsxFbtChildElement(cx, place) { + const value = codegenPlace(cx, place); + switch (value.type) { + case 'JSXText': + case 'JSXElement': { + return value; + } + default: { + return createJsxExpressionContainer(place.loc, value); + } + } +} +function convertMemberExpressionToJsx(expr) { + var _a, _b; + CompilerError.invariant(expr.property.type === 'Identifier', { + reason: 'Expected JSX member expression property to be a string', + description: null, + loc: (_a = expr.loc) !== null && _a !== void 0 ? _a : null, + suggestions: null, + }); + const property = libExports$1.jsxIdentifier(expr.property.name); + if (expr.object.type === 'Identifier') { + return libExports$1.jsxMemberExpression(libExports$1.jsxIdentifier(expr.object.name), property); + } + else { + CompilerError.invariant(expr.object.type === 'MemberExpression', { + reason: 'Expected JSX member expression to be an identifier or nested member expression', + description: null, + loc: (_b = expr.object.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + const object = convertMemberExpressionToJsx(expr.object); + return libExports$1.jsxMemberExpression(object, property); + } +} +function codegenObjectPropertyKey(cx, key) { + switch (key.kind) { + case 'string': { + return libExports$1.stringLiteral(key.name); + } + case 'identifier': { + return libExports$1.identifier(key.name); + } + case 'computed': { + const expr = codegenPlace(cx, key.name); + CompilerError.invariant(libExports$1.isExpression(expr), { + reason: 'Expected object property key to be an expression', + description: null, + loc: key.name.loc, + suggestions: null, + }); + return expr; + } + case 'number': { + return libExports$1.numericLiteral(key.name); + } + } +} +function codegenArrayPattern(cx, pattern) { + const hasHoles = !pattern.items.every(e => e.kind !== 'Hole'); + if (hasHoles) { + const result = libExports$1.arrayPattern([]); + for (const item of pattern.items) { + if (item.kind === 'Hole') { + result.elements.push(null); + } + else { + result.elements.push(codegenLValue(cx, item)); + } + } + return result; + } + else { + return libExports$1.arrayPattern(pattern.items.map(item => { + if (item.kind === 'Hole') { + return null; + } + return codegenLValue(cx, item); + })); + } +} +function codegenLValue(cx, pattern) { + switch (pattern.kind) { + case 'ArrayPattern': { + return codegenArrayPattern(cx, pattern); + } + case 'ObjectPattern': { + return libExports$1.objectPattern(pattern.properties.map(property => { + if (property.kind === 'ObjectProperty') { + const key = codegenObjectPropertyKey(cx, property.key); + const value = codegenLValue(cx, property.place); + return libExports$1.objectProperty(key, value, property.key.kind === 'computed', key.type === 'Identifier' && + value.type === 'Identifier' && + value.name === key.name); + } + else { + return libExports$1.restElement(codegenLValue(cx, property.place)); + } + })); + } + case 'Spread': { + return libExports$1.restElement(codegenLValue(cx, pattern.place)); + } + case 'Identifier': { + return convertIdentifier(pattern.identifier); + } + default: { + assertExhaustive$1(pattern, `Unexpected pattern kind \`${pattern.kind}\``); + } + } +} +function codegenValue(cx, loc, value) { + if (typeof value === 'number') { + return libExports$1.numericLiteral(value); + } + else if (typeof value === 'boolean') { + return libExports$1.booleanLiteral(value); + } + else if (typeof value === 'string') { + return createStringLiteral(loc, value); + } + else if (value === null) { + return libExports$1.nullLiteral(); + } + else if (value === undefined) { + return libExports$1.identifier('undefined'); + } + else { + assertExhaustive$1(value, 'Unexpected primitive value kind'); + } +} +function codegenArgument(cx, arg) { + if (arg.kind === 'Identifier') { + return codegenPlaceToExpression(cx, arg); + } + else { + return libExports$1.spreadElement(codegenPlaceToExpression(cx, arg.place)); + } +} +function codegenPlaceToExpression(cx, place) { + const value = codegenPlace(cx, place); + return convertValueToExpression(value); +} +function codegenPlace(cx, place) { + let tmp = cx.temp.get(place.identifier.declarationId); + if (tmp != null) { + return tmp; + } + CompilerError.invariant(place.identifier.name !== null || tmp !== undefined, { + reason: `[Codegen] No value found for temporary`, + description: `Value for '${printPlace(place)}' was not set in the codegen context`, + loc: place.loc, + suggestions: null, + }); + const identifier = convertIdentifier(place.identifier); + identifier.loc = place.loc; + return identifier; +} +function convertIdentifier(identifier) { + CompilerError.invariant(identifier.name !== null && identifier.name.kind === 'named', { + reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`, + loc: GeneratedSource, + description: `identifier ${identifier.id} is unnamed`, + suggestions: null, + }); + return libExports$1.identifier(identifier.name.value); +} +function compareScopeDependency(a, b) { + var _a, _b; + CompilerError.invariant(((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' && ((_b = b.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named', { + reason: '[Codegen] Expected named identifier for dependency', + loc: a.identifier.loc, + }); + const aName = [ + a.identifier.name.value, + ...a.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`), + ].join('.'); + const bName = [ + b.identifier.name.value, + ...b.path.map(entry => `${entry.optional ? '?' : ''}${entry.property}`), + ].join('.'); + if (aName < bName) + return -1; + else if (aName > bName) + return 1; + else + return 0; +} +function compareScopeDeclaration(a, b) { + var _a, _b; + CompilerError.invariant(((_a = a.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' && ((_b = b.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named', { + reason: '[Codegen] Expected named identifier for declaration', + loc: a.identifier.loc, + }); + const aName = a.identifier.name.value; + const bName = b.identifier.name.value; + if (aName < bName) + return -1; + else if (aName > bName) + return 1; + else + return 0; +} + +function extractScopeDeclarationsFromDestructuring(fn) { + const state = new State$1(fn.env); + visitReactiveFunction(fn, new Visitor$9(), state); +} +let State$1 = class State { + constructor(env) { + this.declared = new Set(); + this.env = env; + } +}; +let Visitor$9 = class Visitor extends ReactiveFunctionTransform { + visitScope(scope, state) { + for (const [, declaration] of scope.scope.declarations) { + state.declared.add(declaration.identifier.declarationId); + } + this.traverseScope(scope, state); + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + if (instruction.value.kind === 'Destructure') { + const transformed = transformDestructuring(state, instruction, instruction.value); + if (transformed) { + return { + kind: 'replace-many', + value: transformed.map(instruction => ({ + kind: 'instruction', + instruction, + })), + }; + } + } + return { kind: 'keep' }; + } +}; +function transformDestructuring(state, instr, destructure) { + let reassigned = new Set(); + let hasDeclaration = false; + for (const place of eachPatternOperand(destructure.lvalue.pattern)) { + const isDeclared = state.declared.has(place.identifier.declarationId); + if (isDeclared) { + reassigned.add(place.identifier.id); + } + hasDeclaration || (hasDeclaration = !isDeclared); + } + if (reassigned.size === 0 || !hasDeclaration) { + return null; + } + const instructions = []; + const renamed = new Map(); + mapPatternOperands(destructure.lvalue.pattern, place => { + if (!reassigned.has(place.identifier.id)) { + return place; + } + const temporary = clonePlaceToTemporary(state.env, place); + promoteTemporary(temporary.identifier); + renamed.set(place, temporary); + return temporary; + }); + instructions.push(instr); + for (const [original, temporary] of renamed) { + instructions.push({ + id: instr.id, + lvalue: null, + value: { + kind: 'StoreLocal', + lvalue: { + kind: InstructionKind.Reassign, + place: original, + }, + value: temporary, + type: null, + loc: destructure.loc, + }, + loc: instr.loc, + }); + } + return instructions; +} + +function mergeReactiveScopesThatInvalidateTogether(fn) { + const lastUsageVisitor = new FindLastUsageVisitor(); + visitReactiveFunction(fn, lastUsageVisitor, undefined); + visitReactiveFunction(fn, new Transform$4(lastUsageVisitor.lastUsage), null); +} +function log(msg) { +} +class FindLastUsageVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.lastUsage = new Map(); + } + visitPlace(id, place, _state) { + const previousUsage = this.lastUsage.get(place.identifier.declarationId); + const lastUsage = previousUsage !== undefined + ? makeInstructionId(Math.max(previousUsage, id)) + : id; + this.lastUsage.set(place.identifier.declarationId, lastUsage); + } +} +let Transform$4 = class Transform extends ReactiveFunctionTransform { + constructor(lastUsage) { + super(); + this.lastUsage = lastUsage; + } + transformScope(scopeBlock, state) { + this.visitScope(scopeBlock, scopeBlock.scope.dependencies); + if (state !== null && + areEqualDependencies(state, scopeBlock.scope.dependencies)) { + return { kind: 'replace-many', value: scopeBlock.instructions }; + } + else { + return { kind: 'keep' }; + } + } + visitBlock(block, state) { + this.traverseBlock(block, state); + let current = null; + const merged = []; + function reset() { + CompilerError.invariant(current !== null, { + loc: null, + reason: 'MergeConsecutiveScopes: expected current scope to be non-null if reset()', + suggestions: null, + description: null, + }); + if (current.to > current.from + 1) { + merged.push(current); + } + current = null; + } + for (let i = 0; i < block.length; i++) { + const instr = block[i]; + switch (instr.kind) { + case 'terminal': { + if (current !== null) { + reset(); + } + break; + } + case 'pruned-scope': { + if (current !== null) { + reset(); + } + break; + } + case 'instruction': { + switch (instr.instruction.value.kind) { + case 'BinaryExpression': + case 'ComputedLoad': + case 'JSXText': + case 'LoadGlobal': + case 'LoadLocal': + case 'Primitive': + case 'PropertyLoad': + case 'TemplateLiteral': + case 'UnaryExpression': { + if (current !== null && instr.instruction.lvalue !== null) { + current.lvalues.add(instr.instruction.lvalue.identifier.declarationId); + } + break; + } + case 'StoreLocal': { + if (current !== null) { + if (instr.instruction.value.lvalue.kind === InstructionKind.Const) { + for (const lvalue of eachInstructionLValue(instr.instruction)) { + current.lvalues.add(lvalue.identifier.declarationId); + } + } + else { + reset(); + } + } + break; + } + default: { + if (current !== null) { + reset(); + } + } + } + break; + } + case 'scope': { + if (current !== null && + canMergeScopes(current.block, instr) && + areLValuesLastUsedByScope(instr.scope, current.lvalues, this.lastUsage)) { + current.block.scope.range.end = makeInstructionId(Math.max(current.block.scope.range.end, instr.scope.range.end)); + for (const [key, value] of instr.scope.declarations) { + current.block.scope.declarations.set(key, value); + } + updateScopeDeclarations(current.block.scope, this.lastUsage); + current.to = i + 1; + current.lvalues.clear(); + if (!scopeIsEligibleForMerging(instr)) { + reset(); + } + } + else { + if (current !== null) { + reset(); + } + if (scopeIsEligibleForMerging(instr)) { + current = { + block: instr, + from: i, + to: i + 1, + lvalues: new Set(), + }; + } + } + break; + } + default: { + assertExhaustive$1(instr, `Unexpected instruction kind \`${instr.kind}\``); + } + } + } + if (current !== null) { + reset(); + } + if (merged.length) { + for (const entry of merged) { + log(printReactiveScopeSummary(entry.block.scope) + + ` from=${entry.from} to=${entry.to}`); + } + } + if (merged.length === 0) { + return; + } + const nextInstructions = []; + let index = 0; + for (const entry of merged) { + if (index < entry.from) { + nextInstructions.push(...block.slice(index, entry.from)); + index = entry.from; + } + const mergedScope = block[entry.from]; + CompilerError.invariant(mergedScope.kind === 'scope', { + loc: null, + reason: 'MergeConsecutiveScopes: Expected scope starting index to be a scope', + description: null, + suggestions: null, + }); + nextInstructions.push(mergedScope); + index++; + while (index < entry.to) { + const instr = block[index++]; + if (instr.kind === 'scope') { + mergedScope.instructions.push(...instr.instructions); + mergedScope.scope.merged.add(instr.scope.id); + } + else { + mergedScope.instructions.push(instr); + } + } + } + while (index < block.length) { + nextInstructions.push(block[index++]); + } + block.length = 0; + block.push(...nextInstructions); + } +}; +function updateScopeDeclarations(scope, lastUsage) { + for (const [id, decl] of scope.declarations) { + const lastUsedAt = lastUsage.get(decl.identifier.declarationId); + if (lastUsedAt < scope.range.end) { + scope.declarations.delete(id); + } + } +} +function areLValuesLastUsedByScope(scope, lvalues, lastUsage) { + for (const lvalue of lvalues) { + const lastUsedAt = lastUsage.get(lvalue); + if (lastUsedAt >= scope.range.end) { + return false; + } + } + return true; +} +function canMergeScopes(current, next) { + if (current.scope.reassignments.size !== 0 || + next.scope.reassignments.size !== 0) { + return false; + } + if (areEqualDependencies(current.scope.dependencies, next.scope.dependencies)) { + return true; + } + if (areEqualDependencies(new Set([...current.scope.declarations.values()].map(declaration => ({ + identifier: declaration.identifier, + path: [], + }))), next.scope.dependencies) || + (next.scope.dependencies.size !== 0 && + [...next.scope.dependencies].every(dep => isAlwaysInvalidatingType(dep.identifier.type) && + Iterable_some(current.scope.declarations.values(), decl => decl.identifier.declarationId === dep.identifier.declarationId)))) { + return true; + } + log(` ${printReactiveScopeSummary(current.scope)}`); + log(` ${printReactiveScopeSummary(next.scope)}`); + return false; +} +function isAlwaysInvalidatingType(type) { + switch (type.kind) { + case 'Object': { + switch (type.shapeId) { + case BuiltInArrayId: + case BuiltInObjectId: + case BuiltInFunctionId: + case BuiltInJsxId: { + return true; + } + } + break; + } + case 'Function': { + return true; + } + } + return false; +} +function areEqualDependencies(a, b) { + if (a.size !== b.size) { + return false; + } + for (const aValue of a) { + let found = false; + for (const bValue of b) { + if (aValue.identifier.declarationId === bValue.identifier.declarationId && + areEqualPaths(aValue.path, bValue.path)) { + found = true; + break; + } + } + if (!found) { + return false; + } + } + return true; +} +function scopeIsEligibleForMerging(scopeBlock) { + if (scopeBlock.scope.dependencies.size === 0) { + return true; + } + return [...scopeBlock.scope.declarations].some(([, decl]) => isAlwaysInvalidatingType(decl.identifier.type)); +} + +var _PromoteInterposedTemporaries_promotable, _PromoteInterposedTemporaries_consts, _PromoteInterposedTemporaries_globals; +class PromoteTemporaries extends ReactiveFunctionVisitor { + visitScope(scopeBlock, state) { + for (const dep of scopeBlock.scope.dependencies) { + const { identifier } = dep; + if (identifier.name == null) { + promoteIdentifier(identifier, state); + } + } + for (const [, declaration] of scopeBlock.scope.declarations) { + if (declaration.identifier.name == null) { + promoteIdentifier(declaration.identifier, state); + } + } + this.traverseScope(scopeBlock, state); + } + visitPrunedScope(scopeBlock, state) { + var _a; + for (const [, declaration] of scopeBlock.scope.declarations) { + if (declaration.identifier.name == null && + ((_a = state.pruned.get(declaration.identifier.declarationId)) === null || _a === void 0 ? void 0 : _a.usedOutsideScope) === true) { + promoteIdentifier(declaration.identifier, state); + } + } + this.traversePrunedScope(scopeBlock, state); + } + visitParam(place, state) { + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + for (const operand of fn.params) { + const place = operand.kind === 'Identifier' ? operand : operand.place; + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitReactiveFunction(fn, this, state); + } +} +class PromoteAllInstancedOfPromotedTemporaries extends ReactiveFunctionVisitor { + visitPlace(_id, place, state) { + if (place.identifier.name === null && + state.promoted.has(place.identifier.declarationId)) { + promoteIdentifier(place.identifier, state); + } + } + visitLValue(_id, _lvalue, _state) { + this.visitPlace(_id, _lvalue, _state); + } + traverseScopeIdentifiers(scope, state) { + for (const [, decl] of scope.declarations) { + if (decl.identifier.name === null && + state.promoted.has(decl.identifier.declarationId)) { + promoteIdentifier(decl.identifier, state); + } + } + for (const dep of scope.dependencies) { + if (dep.identifier.name === null && + state.promoted.has(dep.identifier.declarationId)) { + promoteIdentifier(dep.identifier, state); + } + } + for (const reassignment of scope.reassignments) { + if (reassignment.name === null && + state.promoted.has(reassignment.declarationId)) { + promoteIdentifier(reassignment, state); + } + } + } + visitScope(scope, state) { + this.traverseScope(scope, state); + this.traverseScopeIdentifiers(scope.scope, state); + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + this.traverseScopeIdentifiers(scopeBlock.scope, state); + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +} +class CollectPromotableTemporaries extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.activeScopes = []; + } + visitPlace(_id, place, state) { + if (this.activeScopes.length !== 0 && + state.pruned.has(place.identifier.declarationId)) { + const prunedPlace = state.pruned.get(place.identifier.declarationId); + if (prunedPlace.activeScopes.indexOf(this.activeScopes.at(-1)) === -1) { + prunedPlace.usedOutsideScope = true; + } + } + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'JsxExpression' && value.tag.kind === 'Identifier') { + state.tags.add(value.tag.identifier.declarationId); + } + } + visitPrunedScope(scopeBlock, state) { + for (const [_id, decl] of scopeBlock.scope.declarations) { + state.pruned.set(decl.identifier.declarationId, { + activeScopes: [...this.activeScopes], + usedOutsideScope: false, + }); + } + this.visitBlock(scopeBlock.instructions, state); + } + visitScope(scopeBlock, state) { + this.activeScopes.push(scopeBlock.scope.id); + this.traverseScope(scopeBlock, state); + this.activeScopes.pop(); + } +} +class PromoteInterposedTemporaries extends ReactiveFunctionVisitor { + constructor(promotable, params) { + super(); + _PromoteInterposedTemporaries_promotable.set(this, void 0); + _PromoteInterposedTemporaries_consts.set(this, new Set()); + _PromoteInterposedTemporaries_globals.set(this, new Set()); + params.forEach(param => { + switch (param.kind) { + case 'Identifier': + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(param.identifier.id); + break; + case 'Spread': + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(param.place.identifier.id); + break; + } + }); + __classPrivateFieldSet(this, _PromoteInterposedTemporaries_promotable, promotable, "f"); + } + visitPlace(_id, place, state) { + const promo = state.get(place.identifier.id); + if (promo) { + const [identifier, needsPromotion] = promo; + if (needsPromotion && + identifier.name === null && + !__classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").has(identifier.id)) { + promoteIdentifier(identifier, __classPrivateFieldGet(this, _PromoteInterposedTemporaries_promotable, "f")); + } + } + } + visitInstruction(instruction, state) { + for (const lval of eachInstructionValueLValue(instruction.value)) { + CompilerError.invariant(lval.identifier.name != null, { + reason: 'PromoteInterposedTemporaries: Assignment targets not expected to be temporaries', + loc: instruction.loc, + }); + } + switch (instruction.value.kind) { + case 'CallExpression': + case 'MethodCall': + case 'Await': + case 'PropertyStore': + case 'PropertyDelete': + case 'ComputedStore': + case 'ComputedDelete': + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'StoreLocal': + case 'StoreContext': + case 'StoreGlobal': + case 'Destructure': { + let constStore = false; + if ((instruction.value.kind === 'StoreContext' || + instruction.value.kind === 'StoreLocal') && + (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst')) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.lvalue.place.identifier.id); + constStore = true; + } + if (instruction.value.kind === 'Destructure' && + (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst')) { + [...eachPatternOperand(instruction.value.lvalue.pattern)].forEach(ident => __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(ident.identifier.id)); + constStore = true; + } + if (instruction.value.kind === 'MethodCall') { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.property.identifier.id); + } + super.visitInstruction(instruction, state); + if (!constStore && + (instruction.lvalue == null || + instruction.lvalue.identifier.name != null)) { + for (const [key, [ident, _]] of state.entries()) { + state.set(key, [ident, true]); + } + } + if (instruction.lvalue && instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + break; + } + case 'DeclareContext': + case 'DeclareLocal': { + if (instruction.value.lvalue.kind === 'Const' || + instruction.value.lvalue.kind === 'HoistedConst') { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.value.lvalue.place.identifier.id); + } + super.visitInstruction(instruction, state); + break; + } + case 'LoadContext': + case 'LoadLocal': { + if (instruction.lvalue && instruction.lvalue.identifier.name === null) { + if (__classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").has(instruction.value.place.identifier.id)) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.lvalue.identifier.id); + } + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + super.visitInstruction(instruction, state); + break; + } + case 'PropertyLoad': + case 'ComputedLoad': { + if (instruction.lvalue) { + if (__classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").has(instruction.value.object.identifier.id)) { + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").add(instruction.lvalue.identifier.id); + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_consts, "f").add(instruction.lvalue.identifier.id); + } + if (instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.id, [ + instruction.lvalue.identifier, + false, + ]); + } + } + super.visitInstruction(instruction, state); + break; + } + case 'LoadGlobal': { + instruction.lvalue && + __classPrivateFieldGet(this, _PromoteInterposedTemporaries_globals, "f").add(instruction.lvalue.identifier.id); + super.visitInstruction(instruction, state); + break; + } + default: { + super.visitInstruction(instruction, state); + } + } + } +} +_PromoteInterposedTemporaries_promotable = new WeakMap(), _PromoteInterposedTemporaries_consts = new WeakMap(), _PromoteInterposedTemporaries_globals = new WeakMap(); +function promoteUsedTemporaries(fn) { + const state = { + tags: new Set(), + promoted: new Set(), + pruned: new Map(), + }; + visitReactiveFunction(fn, new CollectPromotableTemporaries(), state); + for (const operand of fn.params) { + const place = operand.kind === 'Identifier' ? operand : operand.place; + if (place.identifier.name === null) { + promoteIdentifier(place.identifier, state); + } + } + visitReactiveFunction(fn, new PromoteTemporaries(), state); + visitReactiveFunction(fn, new PromoteInterposedTemporaries(state, fn.params), new Map()); + visitReactiveFunction(fn, new PromoteAllInstancedOfPromotedTemporaries(), state); +} +function promoteIdentifier(identifier, state) { + CompilerError.invariant(identifier.name === null, { + reason: 'promoteTemporary: Expected to be called only for temporary variables', + description: null, + loc: GeneratedSource, + suggestions: null, + }); + if (state.tags.has(identifier.declarationId)) { + promoteTemporaryJsxTag(identifier); + } + else { + promoteTemporary(identifier); + } + state.promoted.add(identifier.declarationId); +} + +function propagateEarlyReturns(fn) { + visitReactiveFunction(fn, new Transform$3(fn.env), { + withinReactiveScope: false, + earlyReturnValue: null, + }); +} +let Transform$3 = class Transform extends ReactiveFunctionTransform { + constructor(env) { + super(); + this.env = env; + } + visitScope(scopeBlock, parentState) { + if (scopeBlock.scope.earlyReturnValue !== null) { + return; + } + const innerState = { + withinReactiveScope: true, + earlyReturnValue: parentState.earlyReturnValue, + }; + this.traverseScope(scopeBlock, innerState); + const earlyReturnValue = innerState.earlyReturnValue; + if (earlyReturnValue !== null) { + if (!parentState.withinReactiveScope) { + scopeBlock.scope.earlyReturnValue = earlyReturnValue; + scopeBlock.scope.declarations.set(earlyReturnValue.value.id, { + identifier: earlyReturnValue.value, + scope: scopeBlock.scope, + }); + const instructions = scopeBlock.instructions; + const loc = earlyReturnValue.loc; + const sentinelTemp = createTemporaryPlace(this.env, loc); + const symbolTemp = createTemporaryPlace(this.env, loc); + const forTemp = createTemporaryPlace(this.env, loc); + const argTemp = createTemporaryPlace(this.env, loc); + scopeBlock.instructions = [ + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, symbolTemp), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: 'Symbol', + }, + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, forTemp), + value: { + kind: 'PropertyLoad', + object: Object.assign({}, symbolTemp), + property: makePropertyLiteral('for'), + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, argTemp), + value: { + kind: 'Primitive', + value: EARLY_RETURN_SENTINEL, + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: Object.assign({}, sentinelTemp), + value: { + kind: 'MethodCall', + receiver: symbolTemp, + property: forTemp, + args: [argTemp], + loc, + }, + }, + }, + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: null, + value: { + kind: 'StoreLocal', + loc, + type: null, + lvalue: { + kind: InstructionKind.Let, + place: { + kind: 'Identifier', + effect: Effect.ConditionallyMutate, + loc, + reactive: true, + identifier: earlyReturnValue.value, + }, + }, + value: Object.assign({}, sentinelTemp), + }, + }, + }, + { + kind: 'terminal', + label: { + id: earlyReturnValue.label, + implicit: false, + }, + terminal: { + kind: 'label', + id: makeInstructionId(0), + loc: GeneratedSource, + block: instructions, + }, + }, + ]; + } + else { + parentState.earlyReturnValue = earlyReturnValue; + } + } + } + transformTerminal(stmt, state) { + if (state.withinReactiveScope && stmt.terminal.kind === 'return') { + const loc = stmt.terminal.value.loc; + let earlyReturnValue; + if (state.earlyReturnValue !== null) { + earlyReturnValue = state.earlyReturnValue; + } + else { + const identifier = createTemporaryPlace(this.env, loc).identifier; + promoteTemporary(identifier); + earlyReturnValue = { + label: this.env.nextBlockId, + loc, + value: identifier, + }; + } + state.earlyReturnValue = earlyReturnValue; + return { + kind: 'replace-many', + value: [ + { + kind: 'instruction', + instruction: { + id: makeInstructionId(0), + loc, + lvalue: null, + value: { + kind: 'StoreLocal', + loc, + type: null, + lvalue: { + kind: InstructionKind.Reassign, + place: { + kind: 'Identifier', + identifier: earlyReturnValue.value, + effect: Effect.Capture, + loc, + reactive: true, + }, + }, + value: stmt.terminal.value, + }, + }, + }, + { + kind: 'terminal', + label: null, + terminal: { + kind: 'break', + id: makeInstructionId(0), + loc, + targetKind: 'labeled', + target: earlyReturnValue.label, + }, + }, + ], + }; + } + this.traverseTerminal(stmt, state); + return { kind: 'keep' }; + } +}; + +var _Node_value, _Node_next; +function empty() { + return EMPTY; +} +class Node { + constructor(value, next = EMPTY) { + _Node_value.set(this, void 0); + _Node_next.set(this, void 0); + __classPrivateFieldSet(this, _Node_value, value, "f"); + __classPrivateFieldSet(this, _Node_next, next, "f"); + } + push(value) { + return new Node(value, this); + } + pop() { + return __classPrivateFieldGet(this, _Node_next, "f"); + } + find(fn) { + return fn(__classPrivateFieldGet(this, _Node_value, "f")) ? true : __classPrivateFieldGet(this, _Node_next, "f").find(fn); + } + contains(value) { + return (value === __classPrivateFieldGet(this, _Node_value, "f") || + (__classPrivateFieldGet(this, _Node_next, "f") !== null && __classPrivateFieldGet(this, _Node_next, "f").contains(value))); + } + each(fn) { + fn(__classPrivateFieldGet(this, _Node_value, "f")); + __classPrivateFieldGet(this, _Node_next, "f").each(fn); + } + get value() { + return __classPrivateFieldGet(this, _Node_value, "f"); + } + print(fn) { + return fn(__classPrivateFieldGet(this, _Node_value, "f")) + __classPrivateFieldGet(this, _Node_next, "f").print(fn); + } +} +_Node_value = new WeakMap(), _Node_next = new WeakMap(); +class Empty { + push(value) { + return new Node(value, this); + } + pop() { + return this; + } + find(_fn) { + return false; + } + contains(_value) { + return false; + } + each(_fn) { + return; + } + get value() { + return null; + } + print(_) { + return ''; + } +} +const EMPTY = new Empty(); + +function pruneHoistedContexts(fn) { + visitReactiveFunction(fn, new Visitor$8(), { + activeScopes: empty(), + }); +} +let Visitor$8 = class Visitor extends ReactiveFunctionTransform { + visitScope(scope, state) { + state.activeScopes = state.activeScopes.push(new Set(scope.scope.declarations.keys())); + this.traverseScope(scope, state); + state.activeScopes.pop(); + } + transformInstruction(instruction, state) { + this.visitInstruction(instruction, state); + if (instruction.value.kind === 'DeclareContext') { + const maybeNonHoisted = convertHoistedLValueKind(instruction.value.lvalue.kind); + if (maybeNonHoisted != null) { + return { kind: 'remove' }; + } + } + if (instruction.value.kind === 'StoreContext' && + instruction.value.lvalue.kind !== InstructionKind.Reassign) { + const lvalueId = instruction.value.lvalue.place.identifier.id; + const isDeclaredByScope = state.activeScopes.find(scope => scope.has(lvalueId)); + if (isDeclaredByScope) { + instruction.value.lvalue.kind = InstructionKind.Reassign; + } + } + return { kind: 'keep' }; + } +}; + +function inferOperandEffect(state, place) { + const value = state.kind(place); + CompilerError.invariant(value != null, { + reason: 'Expected operand to have a kind', + loc: null, + }); + switch (place.effect) { + case Effect.Store: + case Effect.Mutate: { + if (isRefOrRefValue(place.identifier)) { + break; + } + else if (value.kind === ValueKind.Context) { + CompilerError.invariant(value.context.size > 0, { + reason: "[InferFunctionEffects] Expected Context-kind value's capture list to be non-empty.", + loc: place.loc, + }); + return { + kind: 'ContextMutation', + loc: place.loc, + effect: place.effect, + places: value.context, + }; + } + else if (value.kind !== ValueKind.Mutable && + value.kind !== ValueKind.Primitive) { + let reason = getWriteErrorReason(value); + return { + kind: value.reason.size === 1 && value.reason.has(ValueReason.Global) + ? 'GlobalMutation' + : 'ReactMutation', + error: { + reason, + description: place.identifier.name !== null && + place.identifier.name.kind === 'named' + ? `Found mutation of \`${place.identifier.name.value}\`` + : null, + loc: place.loc, + suggestions: null, + severity: ErrorSeverity.InvalidReact, + }, + }; + } + break; + } + } + return null; +} +function inheritFunctionEffects(state, place) { + const effects = inferFunctionInstrEffects(state, place); + return effects + .flatMap(effect => { + if (effect.kind === 'GlobalMutation' || effect.kind === 'ReactMutation') { + return [effect]; + } + else { + const effects = []; + CompilerError.invariant(effect.kind === 'ContextMutation', { + reason: 'Expected ContextMutation', + loc: null, + }); + for (const place of effect.places) { + if (state.isDefined(place)) { + const replayedEffect = inferOperandEffect(state, Object.assign(Object.assign({}, place), { loc: effect.loc, effect: effect.effect })); + if (replayedEffect != null) { + if (replayedEffect.kind === 'ContextMutation') { + effects.push(effect); + } + else { + effects.push(replayedEffect); + } + } + } + } + return effects; + } + }) + .filter((effect) => effect != null); +} +function inferFunctionInstrEffects(state, place) { + const effects = []; + const instrs = state.values(place); + CompilerError.invariant(instrs != null, { + reason: 'Expected operand to have instructions', + loc: null, + }); + for (const instr of instrs) { + if ((instr.kind === 'FunctionExpression' || instr.kind === 'ObjectMethod') && + instr.loweredFunc.func.effects != null) { + effects.push(...instr.loweredFunc.func.effects); + } + } + return effects; +} +function operandEffects(state, place, filterRenderSafe) { + const functionEffects = []; + const effect = inferOperandEffect(state, place); + effect && functionEffects.push(effect); + functionEffects.push(...inheritFunctionEffects(state, place)); + if (filterRenderSafe) { + return functionEffects.filter(effect => !isEffectSafeOutsideRender(effect)); + } + else { + return functionEffects; + } +} +function inferInstructionFunctionEffects(env, state, instr) { + var _a, _b; + var _c; + const functionEffects = []; + switch (instr.value.kind) { + case 'JsxExpression': { + if (instr.value.tag.kind === 'Identifier') { + functionEffects.push(...operandEffects(state, instr.value.tag, false)); + } + (_a = instr.value.children) === null || _a === void 0 ? void 0 : _a.forEach(child => functionEffects.push(...operandEffects(state, child, false))); + for (const attr of instr.value.props) { + if (attr.kind === 'JsxSpreadAttribute') { + functionEffects.push(...operandEffects(state, attr.argument, false)); + } + else { + functionEffects.push(...operandEffects(state, attr.place, true)); + } + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + for (const operand of eachInstructionOperand(instr)) { + (_b = (_c = instr.value.loweredFunc.func).effects) !== null && _b !== void 0 ? _b : (_c.effects = []); + instr.value.loweredFunc.func.effects.push(...inferFunctionInstrEffects(state, operand)); + } + break; + } + case 'MethodCall': + case 'CallExpression': { + let callee; + if (instr.value.kind === 'MethodCall') { + callee = instr.value.property; + functionEffects.push(...operandEffects(state, instr.value.receiver, false)); + } + else { + callee = instr.value.callee; + } + functionEffects.push(...operandEffects(state, callee, false)); + let isHook = getHookKind(env, callee.identifier) != null; + for (const arg of instr.value.args) { + const place = arg.kind === 'Identifier' ? arg : arg.place; + functionEffects.push(...operandEffects(state, place, isHook)); + } + break; + } + case 'StartMemoize': + case 'FinishMemoize': + case 'LoadLocal': + case 'StoreLocal': { + break; + } + case 'StoreGlobal': { + functionEffects.push({ + kind: 'GlobalMutation', + error: { + reason: 'Unexpected reassignment of a variable which was defined outside of the component. Components and hooks should be pure and side-effect free, but variable reassignment is a form of side-effect. If this variable is used in rendering, use useState instead. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#side-effects-must-run-outside-of-render)', + loc: instr.loc, + suggestions: null, + severity: ErrorSeverity.InvalidReact, + }, + }); + break; + } + default: { + for (const operand of eachInstructionOperand(instr)) { + functionEffects.push(...operandEffects(state, operand, false)); + } + } + } + return functionEffects; +} +function inferTerminalFunctionEffects(state, block) { + const functionEffects = []; + for (const operand of eachTerminalOperand(block.terminal)) { + functionEffects.push(...operandEffects(state, operand, true)); + } + return functionEffects; +} +function transformFunctionEffectErrors(functionEffects) { + return functionEffects.map(eff => { + switch (eff.kind) { + case 'ReactMutation': + case 'GlobalMutation': { + return eff.error; + } + case 'ContextMutation': { + return { + severity: ErrorSeverity.Invariant, + reason: `Unexpected ContextMutation in top-level function effects`, + loc: eff.loc, + }; + } + default: + assertExhaustive$1(eff, `Unexpected function effect kind \`${eff.kind}\``); + } + }); +} +function isEffectSafeOutsideRender(effect) { + return effect.kind === 'GlobalMutation'; +} +function getWriteErrorReason(abstractValue) { + if (abstractValue.reason.has(ValueReason.Global)) { + return 'Writing to a variable defined outside a component or hook is not allowed. Consider using an effect'; + } + else if (abstractValue.reason.has(ValueReason.JsxCaptured)) { + return 'Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX'; + } + else if (abstractValue.reason.has(ValueReason.Context)) { + return `Mutating a value returned from 'useContext()', which should not be mutated`; + } + else if (abstractValue.reason.has(ValueReason.KnownReturnSignature)) { + return 'Mutating a value returned from a function whose return value should not be mutated'; + } + else if (abstractValue.reason.has(ValueReason.ReactiveFunctionArgument)) { + return 'Mutating component props or hook arguments is not allowed. Consider using a local variable instead'; + } + else if (abstractValue.reason.has(ValueReason.State)) { + return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead"; + } + else if (abstractValue.reason.has(ValueReason.ReducerState)) { + return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead"; + } + else { + return 'This mutates a variable that React considers immutable'; + } +} + +var _InferenceState_isFunctionExpression, _InferenceState_values, _InferenceState_variables; +const UndefinedValue = { + kind: 'Primitive', + loc: GeneratedSource, + value: undefined, +}; +function inferReferenceEffects(fn, options = { isFunctionExpression: false }) { + var _a; + const initialState = InferenceState.empty(fn.env, options.isFunctionExpression); + const value = { + kind: 'Primitive', + loc: fn.loc, + value: undefined, + }; + initialState.initialize(value, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + for (const ref of fn.context) { + const value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.loc, + }; + initialState.initialize(value, { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set([ref]), + }); + initialState.define(ref, value); + } + const paramKind = options.isFunctionExpression + ? { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + } + : { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.ReactiveFunctionArgument]), + context: new Set(), + }; + if (fn.fnType === 'Component') { + CompilerError.invariant(fn.params.length <= 2, { + reason: 'Expected React component to have not more than two parameters: one for props and for ref', + description: null, + loc: fn.loc, + suggestions: null, + }); + const [props, ref] = fn.params; + let value; + let place; + if (props) { + inferParam(props, initialState, paramKind); + } + if (ref) { + if (ref.kind === 'Identifier') { + place = ref; + value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.loc, + }; + } + else { + place = ref.place; + value = { + kind: 'ObjectExpression', + properties: [], + loc: ref.place.loc, + }; + } + initialState.initialize(value, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + initialState.define(place, value); + } + } + else { + for (const param of fn.params) { + inferParam(param, initialState, paramKind); + } + } + const statesByBlock = new Map(); + const queuedStates = new Map(); + function queue(blockId, state) { + var _a; + let queuedState = queuedStates.get(blockId); + if (queuedState != null) { + state = (_a = queuedState.merge(state)) !== null && _a !== void 0 ? _a : queuedState; + queuedStates.set(blockId, state); + } + else { + const prevState = statesByBlock.get(blockId); + const nextState = prevState != null ? prevState.merge(state) : state; + if (nextState != null) { + queuedStates.set(blockId, nextState); + } + } + } + queue(fn.body.entry, initialState); + const functionEffects = (_a = fn.effects) !== null && _a !== void 0 ? _a : []; + while (queuedStates.size !== 0) { + for (const [blockId, block] of fn.body.blocks) { + const incomingState = queuedStates.get(blockId); + queuedStates.delete(blockId); + if (incomingState == null) { + continue; + } + statesByBlock.set(blockId, incomingState); + const state = incomingState.clone(); + inferBlock(fn.env, state, block, functionEffects); + for (const nextBlockId of eachTerminalSuccessor(block.terminal)) { + queue(nextBlockId, state); + } + } + } + if (options.isFunctionExpression) { + fn.effects = functionEffects; + return []; + } + else { + return transformFunctionEffectErrors(functionEffects); + } +} +class InferenceState { + constructor(env, isFunctionExpression, values, variables) { + _InferenceState_isFunctionExpression.set(this, void 0); + _InferenceState_values.set(this, void 0); + _InferenceState_variables.set(this, void 0); + this.env = env; + __classPrivateFieldSet(this, _InferenceState_isFunctionExpression, isFunctionExpression, "f"); + __classPrivateFieldSet(this, _InferenceState_values, values, "f"); + __classPrivateFieldSet(this, _InferenceState_variables, variables, "f"); + } + static empty(env, isFunctionExpression) { + return new InferenceState(env, isFunctionExpression, new Map(), new Map()); + } + get isFunctionExpression() { + return __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"); + } + initialize(value, kind) { + CompilerError.invariant(value.kind !== 'LoadLocal', { + reason: 'Expected all top-level identifiers to be defined as variables, not values', + description: null, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_values, "f").set(value, kind); + } + values(place) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value kind to be initialized`, + description: `${printPlace(place)}`, + loc: place.loc, + suggestions: null, + }); + return Array.from(values); + } + kind(place) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value kind to be initialized`, + description: `${printPlace(place)}`, + loc: place.loc, + suggestions: null, + }); + let mergedKind = null; + for (const value of values) { + const kind = __classPrivateFieldGet(this, _InferenceState_values, "f").get(value); + mergedKind = + mergedKind !== null ? mergeAbstractValues(mergedKind, kind) : kind; + } + CompilerError.invariant(mergedKind !== null, { + reason: `InferReferenceEffects::kind: Expected at least one value`, + description: `No value found at \`${printPlace(place)}\``, + loc: place.loc, + suggestions: null, + }); + return mergedKind; + } + alias(place, value) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(value.identifier.id); + CompilerError.invariant(values != null, { + reason: `[hoisting] Expected value for identifier to be initialized`, + description: `${printIdentifier(value.identifier)}`, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(place.identifier.id, new Set(values)); + } + define(place, value) { + CompilerError.invariant(__classPrivateFieldGet(this, _InferenceState_values, "f").has(value), { + reason: `Expected value to be initialized at '${printSourceLocation(value.loc)}'`, + description: null, + loc: value.loc, + suggestions: null, + }); + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(place.identifier.id, new Set([value])); + } + isDefined(place) { + return __classPrivateFieldGet(this, _InferenceState_variables, "f").has(place.identifier.id); + } + referenceAndRecordEffects(freezeActions, place, effectKind, reason) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + if (values === undefined) { + CompilerError.invariant(effectKind !== Effect.Store, { + reason: '[InferReferenceEffects] Unhandled store reference effect', + description: null, + loc: place.loc, + suggestions: null, + }); + place.effect = + effectKind === Effect.ConditionallyMutate + ? Effect.ConditionallyMutate + : Effect.Read; + return; + } + const action = this.reference(place, effectKind, reason); + action && freezeActions.push(action); + } + freezeValues(values, reason) { + for (const value of values) { + if (value.kind === 'DeclareContext' || + (value.kind === 'StoreContext' && + (value.lvalue.kind === InstructionKind.Let || + value.lvalue.kind === InstructionKind.Const))) { + continue; + } + __classPrivateFieldGet(this, _InferenceState_values, "f").set(value, { + kind: ValueKind.Frozen, + reason, + context: new Set(), + }); + if (value.kind === 'FunctionExpression' && + (this.env.config.enablePreserveExistingMemoizationGuarantees || + this.env.config.enableTransitivelyFreezeFunctionExpressions)) { + for (const operand of value.loweredFunc.func.context) { + const operandValues = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(operand.identifier.id); + if (operandValues !== undefined) { + this.freezeValues(operandValues, reason); + } + } + } + } + } + reference(place, effectKind, reason) { + const values = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(place.identifier.id); + CompilerError.invariant(values !== undefined, { + reason: '[InferReferenceEffects] Expected value to be initialized', + description: null, + loc: place.loc, + suggestions: null, + }); + let valueKind = this.kind(place); + let effect = null; + let freeze = null; + switch (effectKind) { + case Effect.Freeze: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context || + valueKind.kind === ValueKind.MaybeFrozen) { + const reasonSet = new Set([reason]); + effect = Effect.Freeze; + valueKind = { + kind: ValueKind.Frozen, + reason: reasonSet, + context: new Set(), + }; + freeze = { values, reason: reasonSet }; + } + else { + effect = Effect.Read; + } + break; + } + case Effect.ConditionallyMutate: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context) { + effect = Effect.ConditionallyMutate; + } + else { + effect = Effect.Read; + } + break; + } + case Effect.ConditionallyMutateIterator: { + if (valueKind.kind === ValueKind.Mutable || + valueKind.kind === ValueKind.Context) { + if (isArrayType(place.identifier) || + isSetType(place.identifier) || + isMapType(place.identifier)) { + effect = Effect.Capture; + } + else { + effect = Effect.ConditionallyMutate; + } + } + else { + effect = Effect.Read; + } + break; + } + case Effect.Mutate: { + effect = Effect.Mutate; + break; + } + case Effect.Store: { + effect = isObjectType(place.identifier) ? Effect.Store : Effect.Mutate; + break; + } + case Effect.Capture: { + if (valueKind.kind === ValueKind.Primitive || + valueKind.kind === ValueKind.Global || + valueKind.kind === ValueKind.Frozen || + valueKind.kind === ValueKind.MaybeFrozen) { + effect = Effect.Read; + } + else { + effect = Effect.Capture; + } + break; + } + case Effect.Read: { + effect = Effect.Read; + break; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect, expected to infer a precise effect kind', + description: null, + loc: place.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(effectKind, `Unexpected reference kind \`${effectKind}\``); + } + } + CompilerError.invariant(effect !== null, { + reason: 'Expected effect to be set', + description: null, + loc: place.loc, + suggestions: null, + }); + place.effect = effect; + return freeze; + } + merge(other) { + let nextValues = null; + let nextVariables = null; + for (const [id, thisValue] of __classPrivateFieldGet(this, _InferenceState_values, "f")) { + const otherValue = __classPrivateFieldGet(other, _InferenceState_values, "f").get(id); + if (otherValue !== undefined) { + const mergedValue = mergeAbstractValues(thisValue, otherValue); + if (mergedValue !== thisValue) { + nextValues = nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")); + nextValues.set(id, mergedValue); + } + } + } + for (const [id, otherValue] of __classPrivateFieldGet(other, _InferenceState_values, "f")) { + if (__classPrivateFieldGet(this, _InferenceState_values, "f").has(id)) { + continue; + } + nextValues = nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")); + nextValues.set(id, otherValue); + } + for (const [id, thisValues] of __classPrivateFieldGet(this, _InferenceState_variables, "f")) { + const otherValues = __classPrivateFieldGet(other, _InferenceState_variables, "f").get(id); + if (otherValues !== undefined) { + let mergedValues = null; + for (const otherValue of otherValues) { + if (!thisValues.has(otherValue)) { + mergedValues = mergedValues !== null && mergedValues !== void 0 ? mergedValues : new Set(thisValues); + mergedValues.add(otherValue); + } + } + if (mergedValues !== null) { + nextVariables = nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f")); + nextVariables.set(id, mergedValues); + } + } + } + for (const [id, otherValues] of __classPrivateFieldGet(other, _InferenceState_variables, "f")) { + if (__classPrivateFieldGet(this, _InferenceState_variables, "f").has(id)) { + continue; + } + nextVariables = nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f")); + nextVariables.set(id, new Set(otherValues)); + } + if (nextVariables === null && nextValues === null) { + return null; + } + else { + return new InferenceState(this.env, __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"), nextValues !== null && nextValues !== void 0 ? nextValues : new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")), nextVariables !== null && nextVariables !== void 0 ? nextVariables : new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f"))); + } + } + clone() { + return new InferenceState(this.env, __classPrivateFieldGet(this, _InferenceState_isFunctionExpression, "f"), new Map(__classPrivateFieldGet(this, _InferenceState_values, "f")), new Map(__classPrivateFieldGet(this, _InferenceState_variables, "f"))); + } + debug() { + const result = { values: {}, variables: {} }; + const objects = new Map(); + function identify(value) { + let id = objects.get(value); + if (id == null) { + id = objects.size; + objects.set(value, id); + } + return id; + } + for (const [value, kind] of __classPrivateFieldGet(this, _InferenceState_values, "f")) { + const id = identify(value); + result.values[id] = { kind, value: printMixedHIR(value) }; + } + for (const [variable, values] of __classPrivateFieldGet(this, _InferenceState_variables, "f")) { + result.variables[`$${variable}`] = [...values].map(identify); + } + return result; + } + inferPhi(phi) { + const values = new Set(); + for (const [_, operand] of phi.operands) { + const operandValues = __classPrivateFieldGet(this, _InferenceState_variables, "f").get(operand.identifier.id); + if (operandValues === undefined) + continue; + for (const v of operandValues) { + values.add(v); + } + } + if (values.size > 0) { + __classPrivateFieldGet(this, _InferenceState_variables, "f").set(phi.place.identifier.id, values); + } + } +} +_InferenceState_isFunctionExpression = new WeakMap(), _InferenceState_values = new WeakMap(), _InferenceState_variables = new WeakMap(); +function inferParam(param, initialState, paramKind) { + let value; + let place; + if (param.kind === 'Identifier') { + place = param; + value = { + kind: 'Primitive', + loc: param.loc, + value: undefined, + }; + } + else { + place = param.place; + value = { + kind: 'Primitive', + loc: param.place.loc, + value: undefined, + }; + } + initialState.initialize(value, paramKind); + initialState.define(place, value); +} +function mergeValues(a, b) { + if (a === b) { + return a; + } + else if (a === ValueKind.MaybeFrozen || b === ValueKind.MaybeFrozen) { + return ValueKind.MaybeFrozen; + } + else if (a === ValueKind.Mutable || b === ValueKind.Mutable) { + if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.MaybeFrozen; + } + else if (a === ValueKind.Context || b === ValueKind.Context) { + return ValueKind.Context; + } + else { + return ValueKind.Mutable; + } + } + else if (a === ValueKind.Context || b === ValueKind.Context) { + if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.MaybeFrozen; + } + else { + return ValueKind.Context; + } + } + else if (a === ValueKind.Frozen || b === ValueKind.Frozen) { + return ValueKind.Frozen; + } + else if (a === ValueKind.Global || b === ValueKind.Global) { + return ValueKind.Global; + } + else { + CompilerError.invariant(a === ValueKind.Primitive && b == ValueKind.Primitive, { + reason: `Unexpected value kind in mergeValues()`, + description: `Found kinds ${a} and ${b}`, + loc: GeneratedSource, + }); + return ValueKind.Primitive; + } +} +function isSuperset(a, b) { + for (const v of b) { + if (!a.has(v)) { + return false; + } + } + return true; +} +function mergeAbstractValues(a, b) { + const kind = mergeValues(a.kind, b.kind); + if (kind === a.kind && + kind === b.kind && + isSuperset(a.reason, b.reason) && + isSuperset(a.context, b.context)) { + return a; + } + const reason = new Set(a.reason); + for (const r of b.reason) { + reason.add(r); + } + const context = new Set(a.context); + for (const c of b.context) { + context.add(c); + } + return { kind, reason, context }; +} +function inferBlock(env, state, block, functionEffects) { + var _a, _b, _c; + for (const phi of block.phis) { + state.inferPhi(phi); + } + for (const instr of block.instructions) { + const instrValue = instr.value; + const defaultLvalueEffect = Effect.ConditionallyMutate; + let continuation; + const freezeActions = []; + switch (instrValue.kind) { + case 'BinaryExpression': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.Read, + reason: ValueReason.Other, + }, + }; + break; + } + case 'ArrayExpression': { + const contextRefOperands = getContextRefOperand(state, instrValue); + const valueKind = contextRefOperands.length > 0 + ? { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set(contextRefOperands), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + for (const element of instrValue.elements) { + if (element.kind === 'Spread') { + state.referenceAndRecordEffects(freezeActions, element.place, Effect.ConditionallyMutateIterator, ValueReason.Other); + } + else if (element.kind === 'Identifier') { + state.referenceAndRecordEffects(freezeActions, element, Effect.Capture, ValueReason.Other); + } + else ; + } + state.initialize(instrValue, valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { + kind: 'funeffects', + }; + break; + } + case 'NewExpression': { + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.callee.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'ObjectExpression': { + const contextRefOperands = getContextRefOperand(state, instrValue); + const valueKind = contextRefOperands.length > 0 + ? { + kind: ValueKind.Context, + reason: new Set([ValueReason.Other]), + context: new Set(contextRefOperands), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + for (const property of instrValue.properties) { + switch (property.kind) { + case 'ObjectProperty': { + if (property.key.kind === 'computed') { + state.referenceAndRecordEffects(freezeActions, property.key.name, Effect.Freeze, ValueReason.Other); + } + state.referenceAndRecordEffects(freezeActions, property.place, Effect.Capture, ValueReason.Other); + break; + } + case 'Spread': { + state.referenceAndRecordEffects(freezeActions, property.place, Effect.Capture, ValueReason.Other); + break; + } + default: { + assertExhaustive$1(property, `Unexpected property kind \`${property.kind}\``); + } + } + } + state.initialize(instrValue, valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'UnaryExpression': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Read, reason: ValueReason.Other }, + }; + break; + } + case 'UnsupportedNode': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'JsxExpression': { + if (instrValue.tag.kind === 'Identifier') { + state.referenceAndRecordEffects(freezeActions, instrValue.tag, Effect.Freeze, ValueReason.JsxCaptured); + } + if (instrValue.children !== null) { + for (const child of instrValue.children) { + state.referenceAndRecordEffects(freezeActions, child, Effect.Freeze, ValueReason.JsxCaptured); + } + } + for (const attr of instrValue.props) { + if (attr.kind === 'JsxSpreadAttribute') { + state.referenceAndRecordEffects(freezeActions, attr.argument, Effect.Freeze, ValueReason.JsxCaptured); + } + else { + state.referenceAndRecordEffects(freezeActions, attr.place, Effect.Freeze, ValueReason.JsxCaptured); + } + } + state.initialize(instrValue, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.ConditionallyMutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'JsxFragment': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.Freeze, + reason: ValueReason.Other, + }, + }; + break; + } + case 'TemplateLiteral': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Read, reason: ValueReason.Other }, + }; + break; + } + case 'RegExpLiteral': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { + kind: Effect.ConditionallyMutate, + reason: ValueReason.Other, + }, + }; + break; + } + case 'MetaProperty': { + if (instrValue.meta !== 'import' || instrValue.property !== 'meta') { + continuation = { kind: 'funeffects' }; + break; + } + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Global, + reason: new Set([ValueReason.Global]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'LoadGlobal': + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Global, + reason: new Set([ValueReason.Global]), + context: new Set(), + }, + effect: null, + }; + break; + case 'Debugger': + case 'JSXText': + case 'Primitive': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: null, + }; + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + let hasMutableOperand = false; + for (const operand of eachInstructionOperand(instr)) { + CompilerError.invariant(operand.effect !== Effect.Unknown, { + reason: 'Expected fn effects to be populated', + loc: operand.loc, + }); + state.referenceAndRecordEffects(freezeActions, operand, operand.effect, ValueReason.Other); + hasMutableOperand || (hasMutableOperand = isMutableEffect(operand.effect, operand.loc)); + } + state.initialize(instrValue, { + kind: hasMutableOperand ? ValueKind.Mutable : ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'TaggedTemplateExpression': { + const operands = [...eachInstructionValueOperand(instrValue)]; + if (operands.length !== 1) { + CompilerError.throwTodo({ + reason: 'Support tagged template expressions with interpolations', + loc: instrValue.loc, + }); + } + const signature = getFunctionCallSignature(env, instrValue.tag.identifier.type); + let calleeEffect = (_a = signature === null || signature === void 0 ? void 0 : signature.calleeEffect) !== null && _a !== void 0 ? _a : Effect.ConditionallyMutate; + const returnValueKind = signature !== null + ? { + kind: signature.returnValueKind, + reason: new Set([ + (_b = signature.returnValueReason) !== null && _b !== void 0 ? _b : ValueReason.KnownReturnSignature, + ]), + context: new Set(), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + state.referenceAndRecordEffects(freezeActions, instrValue.tag, calleeEffect, ValueReason.Other); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.ConditionallyMutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'CallExpression': { + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.callee.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'MethodCall': { + CompilerError.invariant(state.isDefined(instrValue.receiver), { + reason: '[InferReferenceEffects] Internal error: receiver of PropertyCall should have been defined by corresponding PropertyLoad', + description: null, + loc: instrValue.loc, + suggestions: null, + }); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + inferCallEffects(state, instr, freezeActions, getFunctionCallSignature(env, instrValue.property.identifier.type)); + continuation = { kind: 'funeffects' }; + break; + } + case 'PropertyStore': { + const effect = state.kind(instrValue.object).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Store, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'PropertyDelete': { + continuation = { + kind: 'initialize', + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + effect: { kind: Effect.Mutate, reason: ValueReason.Other }, + }; + break; + } + case 'PropertyLoad': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, state.kind(instrValue.object)); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedStore': { + const effect = state.kind(instrValue.object).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Capture, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Store, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedDelete': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Mutate, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + state.initialize(instrValue, { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Mutate; + continuation = { kind: 'funeffects' }; + break; + } + case 'ComputedLoad': { + state.referenceAndRecordEffects(freezeActions, instrValue.object, Effect.Read, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.property, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, state.kind(instrValue.object)); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'Await': { + state.initialize(instrValue, state.kind(instrValue.value)); + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.ConditionallyMutate, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.value); + continuation = { kind: 'funeffects' }; + break; + } + case 'TypeCastExpression': { + state.initialize(instrValue, state.kind(instrValue.value)); + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.Read, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.value); + continuation = { kind: 'funeffects' }; + break; + } + case 'StartMemoize': + case 'FinishMemoize': { + for (const val of eachInstructionValueOperand(instrValue)) { + if (env.config.enablePreserveExistingMemoizationGuarantees) { + state.referenceAndRecordEffects(freezeActions, val, Effect.Freeze, ValueReason.Other); + } + else { + state.referenceAndRecordEffects(freezeActions, val, Effect.Read, ValueReason.Other); + } + } + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + state.initialize(instrValue, { + kind: ValueKind.Frozen, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'LoadLocal': { + const lvalue = instr.lvalue; + state.referenceAndRecordEffects(freezeActions, instrValue.place, Effect.Capture, ValueReason.Other); + lvalue.effect = Effect.ConditionallyMutate; + state.alias(lvalue, instrValue.place); + continuation = { kind: 'funeffects' }; + break; + } + case 'LoadContext': { + state.referenceAndRecordEffects(freezeActions, instrValue.place, Effect.Capture, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.ConditionallyMutate; + const valueKind = state.kind(instrValue.place); + state.initialize(instrValue, valueKind); + state.define(lvalue, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'DeclareLocal': { + const value = UndefinedValue; + state.initialize(value, instrValue.lvalue.kind === InstructionKind.Catch + ? { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + } + : { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, value); + continuation = { kind: 'funeffects' }; + break; + } + case 'DeclareContext': { + state.initialize(instrValue, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, instrValue); + continuation = { kind: 'funeffects' }; + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + const effect = state.isDefined(instrValue.lvalue) && + state.kind(instrValue.lvalue).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + state.alias(instrValue.lvalue, instrValue.value); + instrValue.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreLocal': { + const effect = state.isDefined(instrValue.lvalue.place) && + state.kind(instrValue.lvalue.place).kind === ValueKind.Context + ? Effect.ConditionallyMutate + : Effect.Capture; + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + state.alias(instrValue.lvalue.place, instrValue.value); + instrValue.lvalue.place.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreContext': { + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.ConditionallyMutate, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.lvalue.place, Effect.Mutate, ValueReason.Other); + const lvalue = instr.lvalue; + if (instrValue.lvalue.kind !== InstructionKind.Reassign) { + state.initialize(instrValue, { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }); + state.define(instrValue.lvalue.place, instrValue); + } + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'StoreGlobal': { + state.referenceAndRecordEffects(freezeActions, instrValue.value, Effect.Capture, ValueReason.Other); + const lvalue = instr.lvalue; + lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'Destructure': { + let effect = Effect.Capture; + for (const place of eachPatternOperand(instrValue.lvalue.pattern)) { + if (state.isDefined(place) && + state.kind(place).kind === ValueKind.Context) { + effect = Effect.ConditionallyMutate; + break; + } + } + state.referenceAndRecordEffects(freezeActions, instrValue.value, effect, ValueReason.Other); + const lvalue = instr.lvalue; + state.alias(lvalue, instrValue.value); + lvalue.effect = Effect.Store; + for (const place of eachPatternOperand(instrValue.lvalue.pattern)) { + state.alias(place, instrValue.value); + place.effect = Effect.Store; + } + continuation = { kind: 'funeffects' }; + break; + } + case 'GetIterator': { + const kind = state.kind(instrValue.collection).kind; + const isMutable = kind === ValueKind.Mutable || kind === ValueKind.Context; + let effect; + let valueKind; + const iterator = instrValue.collection.identifier; + if (!isMutable || + isArrayType(iterator) || + isMapType(iterator) || + isSetType(iterator)) { + effect = { + kind: Effect.Read, + reason: ValueReason.Other, + }; + valueKind = { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + } + else { + effect = { + kind: Effect.Capture, + reason: ValueReason.Other, + }; + valueKind = state.kind(instrValue.collection); + } + continuation = { + kind: 'initialize', + effect, + valueKind, + lvalueEffect: Effect.Store, + }; + break; + } + case 'IteratorNext': { + state.referenceAndRecordEffects(freezeActions, instrValue.iterator, Effect.ConditionallyMutateIterator, ValueReason.Other); + state.referenceAndRecordEffects(freezeActions, instrValue.collection, Effect.Capture, ValueReason.Other); + state.initialize(instrValue, state.kind(instrValue.collection)); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = Effect.Store; + continuation = { kind: 'funeffects' }; + break; + } + case 'NextPropertyOf': { + continuation = { + kind: 'initialize', + effect: { kind: Effect.Read, reason: ValueReason.Other }, + lvalueEffect: Effect.Store, + valueKind: { + kind: ValueKind.Primitive, + reason: new Set([ValueReason.Other]), + context: new Set(), + }, + }; + break; + } + default: { + assertExhaustive$1(instrValue, 'Unexpected instruction kind'); + } + } + if (continuation.kind === 'initialize') { + for (const operand of eachInstructionOperand(instr)) { + CompilerError.invariant(continuation.effect != null, { + reason: `effectKind must be set for instruction value \`${instrValue.kind}\``, + description: null, + loc: instrValue.loc, + suggestions: null, + }); + state.referenceAndRecordEffects(freezeActions, operand, continuation.effect.kind, continuation.effect.reason); + } + state.initialize(instrValue, continuation.valueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = (_c = continuation.lvalueEffect) !== null && _c !== void 0 ? _c : defaultLvalueEffect; + } + functionEffects.push(...inferInstructionFunctionEffects(env, state, instr)); + freezeActions.forEach(({ values, reason }) => state.freezeValues(values, reason)); + } + const terminalFreezeActions = []; + for (const operand of eachTerminalOperand(block.terminal)) { + let effect; + if (block.terminal.kind === 'return' || block.terminal.kind === 'throw') { + if (state.isDefined(operand) && + ((operand.identifier.type.kind === 'Function' && + state.isFunctionExpression) || + state.kind(operand).kind === ValueKind.Context)) { + effect = Effect.ConditionallyMutate; + } + else { + effect = Effect.Freeze; + } + } + else { + effect = Effect.Read; + } + state.referenceAndRecordEffects(terminalFreezeActions, operand, effect, ValueReason.Other); + } + functionEffects.push(...inferTerminalFunctionEffects(state, block)); + terminalFreezeActions.forEach(({ values, reason }) => state.freezeValues(values, reason)); +} +function getContextRefOperand(state, instrValue) { + const result = []; + for (const place of eachInstructionValueOperand(instrValue)) { + if (state.isDefined(place) && + state.kind(place).kind === ValueKind.Context) { + result.push(place); + } + } + return result; +} +function getFunctionCallSignature(env, type) { + if (type.kind !== 'Function') { + return null; + } + return env.getFunctionSignature(type); +} +function getFunctionEffects(fn, sig) { + const results = []; + for (let i = 0; i < fn.args.length; i++) { + const arg = fn.args[i]; + if (i < sig.positionalParams.length) { + if (arg.kind === 'Identifier') { + results.push(sig.positionalParams[i]); + } + else { + return null; + } + } + else if (sig.restParam !== null) { + results.push(sig.restParam); + } + else { + return null; + } + } + return results; +} +function isKnownMutableEffect(effect) { + switch (effect) { + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + return true; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: GeneratedSource, + suggestions: null, + }); + } + case Effect.Read: + case Effect.Capture: + case Effect.Freeze: { + return false; + } + default: { + assertExhaustive$1(effect, `Unexpected effect \`${effect}\``); + } + } +} +function areArgumentsImmutableAndNonMutating(state, args) { + for (const arg of args) { + if (arg.kind === 'Identifier' && arg.identifier.type.kind === 'Function') { + const fnShape = state.env.getFunctionSignature(arg.identifier.type); + if (fnShape != null) { + return (!fnShape.positionalParams.some(isKnownMutableEffect) && + (fnShape.restParam == null || + !isKnownMutableEffect(fnShape.restParam))); + } + } + const place = arg.kind === 'Identifier' ? arg : arg.place; + const kind = state.kind(place).kind; + switch (kind) { + case ValueKind.Primitive: + case ValueKind.Frozen: { + break; + } + default: { + return false; + } + } + const values = state.values(place); + for (const value of values) { + if (value.kind === 'FunctionExpression' && + value.loweredFunc.func.params.some(param => { + const place = param.kind === 'Identifier' ? param : param.place; + const range = place.identifier.mutableRange; + return range.end > range.start + 1; + })) { + return false; + } + } + } + return true; +} +function getArgumentEffect(signatureEffect, arg) { + if (signatureEffect != null) { + if (arg.kind === 'Identifier') { + return signatureEffect; + } + else if (signatureEffect === Effect.Mutate || + signatureEffect === Effect.ConditionallyMutate) { + return signatureEffect; + } + else { + if (signatureEffect === Effect.Freeze) { + CompilerError.throwTodo({ + reason: 'Support spread syntax for hook arguments', + loc: arg.place.loc, + }); + } + return Effect.ConditionallyMutateIterator; + } + } + else { + return Effect.ConditionallyMutate; + } +} +function inferCallEffects(state, instr, freezeActions, signature) { + var _a; + const instrValue = instr.value; + const returnValueKind = signature !== null + ? { + kind: signature.returnValueKind, + reason: new Set([ + (_a = signature.returnValueReason) !== null && _a !== void 0 ? _a : ValueReason.KnownReturnSignature, + ]), + context: new Set(), + } + : { + kind: ValueKind.Mutable, + reason: new Set([ValueReason.Other]), + context: new Set(), + }; + if (instrValue.kind === 'MethodCall' && + signature !== null && + signature.mutableOnlyIfOperandsAreMutable && + areArgumentsImmutableAndNonMutating(state, instrValue.args)) { + for (const arg of instrValue.args) { + const place = arg.kind === 'Identifier' ? arg : arg.place; + state.referenceAndRecordEffects(freezeActions, place, Effect.Read, ValueReason.Other); + } + state.referenceAndRecordEffects(freezeActions, instrValue.receiver, Effect.Capture, ValueReason.Other); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = + instrValue.receiver.effect === Effect.Capture + ? Effect.Store + : Effect.ConditionallyMutate; + return; + } + const effects = signature !== null ? getFunctionEffects(instrValue, signature) : null; + let hasCaptureArgument = false; + for (let i = 0; i < instrValue.args.length; i++) { + const arg = instrValue.args[i]; + const place = arg.kind === 'Identifier' ? arg : arg.place; + state.referenceAndRecordEffects(freezeActions, place, getArgumentEffect(effects != null ? effects[i] : null, arg), ValueReason.Other); + hasCaptureArgument || (hasCaptureArgument = place.effect === Effect.Capture); + } + const callee = instrValue.kind === 'MethodCall' ? instrValue.receiver : instrValue.callee; + if (signature !== null) { + state.referenceAndRecordEffects(freezeActions, callee, signature.calleeEffect, ValueReason.Other); + } + else { + state.referenceAndRecordEffects(freezeActions, callee, instrValue.kind === 'NewExpression' + ? Effect.Read + : Effect.ConditionallyMutate, ValueReason.Other); + } + hasCaptureArgument || (hasCaptureArgument = callee.effect === Effect.Capture); + state.initialize(instrValue, returnValueKind); + state.define(instr.lvalue, instrValue); + instr.lvalue.effect = hasCaptureArgument + ? Effect.Store + : Effect.ConditionallyMutate; +} + +function pruneNonEscapingScopes(fn) { + const state = new State(fn.env); + for (const param of fn.params) { + if (param.kind === 'Identifier') { + state.declare(param.identifier.declarationId); + } + else { + state.declare(param.place.identifier.declarationId); + } + } + visitReactiveFunction(fn, new CollectDependenciesVisitor(fn.env, state), []); + const memoized = computeMemoizedIdentifiers(state); + visitReactiveFunction(fn, new PruneScopesTransform(), memoized); +} +var MemoizationLevel; +(function (MemoizationLevel) { + MemoizationLevel["Memoized"] = "Memoized"; + MemoizationLevel["Conditional"] = "Conditional"; + MemoizationLevel["Unmemoized"] = "Unmemoized"; + MemoizationLevel["Never"] = "Never"; +})(MemoizationLevel || (MemoizationLevel = {})); +function joinAliases(kind1, kind2) { + if (kind1 === MemoizationLevel.Memoized || + kind2 === MemoizationLevel.Memoized) { + return MemoizationLevel.Memoized; + } + else if (kind1 === MemoizationLevel.Conditional || + kind2 === MemoizationLevel.Conditional) { + return MemoizationLevel.Conditional; + } + else if (kind1 === MemoizationLevel.Unmemoized || + kind2 === MemoizationLevel.Unmemoized) { + return MemoizationLevel.Unmemoized; + } + else { + return MemoizationLevel.Never; + } +} +class State { + constructor(env) { + this.definitions = new Map(); + this.identifiers = new Map(); + this.scopes = new Map(); + this.escapingValues = new Set(); + this.env = env; + } + declare(id) { + this.identifiers.set(id, { + level: MemoizationLevel.Never, + memoized: false, + dependencies: new Set(), + scopes: new Set(), + seen: false, + }); + } + visitOperand(id, place, identifier) { + const scope = getPlaceScope(id, place); + if (scope !== null) { + let node = this.scopes.get(scope.id); + if (node === undefined) { + node = { + dependencies: [...scope.dependencies].map(dep => dep.identifier.declarationId), + seen: false, + }; + this.scopes.set(scope.id, node); + } + const identifierNode = this.identifiers.get(identifier); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: `[${id}] operand=${printPlace(place)} for identifier declaration ${identifier}`, + loc: place.loc, + suggestions: null, + }); + identifierNode.scopes.add(scope.id); + } + } +} +function computeMemoizedIdentifiers(state) { + const memoized = new Set(); + function visit(id, forceMemoize = false) { + const node = state.identifiers.get(id); + CompilerError.invariant(node !== undefined, { + reason: `Expected a node for all identifiers, none found for \`${id}\``, + description: null, + loc: null, + suggestions: null, + }); + if (node.seen) { + return node.memoized; + } + node.seen = true; + node.memoized = false; + let hasMemoizedDependency = false; + for (const dep of node.dependencies) { + const isDepMemoized = visit(dep); + hasMemoizedDependency || (hasMemoizedDependency = isDepMemoized); + } + if (node.level === MemoizationLevel.Memoized || + (node.level === MemoizationLevel.Conditional && + (hasMemoizedDependency || forceMemoize)) || + (node.level === MemoizationLevel.Unmemoized && forceMemoize)) { + node.memoized = true; + memoized.add(id); + for (const scope of node.scopes) { + forceMemoizeScopeDependencies(scope); + } + } + return node.memoized; + } + function forceMemoizeScopeDependencies(id) { + const node = state.scopes.get(id); + CompilerError.invariant(node !== undefined, { + reason: 'Expected a node for all scopes', + description: null, + loc: null, + suggestions: null, + }); + if (node.seen) { + return; + } + node.seen = true; + for (const dep of node.dependencies) { + visit(dep, true); + } + return; + } + for (const value of state.escapingValues) { + visit(value); + } + return memoized; +} +function computePatternLValues(pattern) { + const lvalues = []; + switch (pattern.kind) { + case 'ArrayPattern': { + for (const item of pattern.items) { + if (item.kind === 'Identifier') { + lvalues.push({ place: item, level: MemoizationLevel.Conditional }); + } + else if (item.kind === 'Spread') { + lvalues.push({ place: item.place, level: MemoizationLevel.Memoized }); + } + } + break; + } + case 'ObjectPattern': { + for (const property of pattern.properties) { + if (property.kind === 'ObjectProperty') { + lvalues.push({ + place: property.place, + level: MemoizationLevel.Conditional, + }); + } + else { + lvalues.push({ + place: property.place, + level: MemoizationLevel.Memoized, + }); + } + } + break; + } + default: { + assertExhaustive$1(pattern, `Unexpected pattern kind \`${pattern.kind}\``); + } + } + return lvalues; +} +class CollectDependenciesVisitor extends ReactiveFunctionVisitor { + constructor(env, state) { + super(); + this.env = env; + this.state = state; + this.options = { + memoizeJsxElements: !this.env.config.enableForest, + forceMemoizePrimitives: this.env.config.enableForest, + }; + } + computeMemoizationInputs(value, lvalue) { + const env = this.env; + const options = this.options; + switch (value.kind) { + case 'ConditionalExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [ + ...this.computeMemoizationInputs(value.consequent, null).rvalues, + ...this.computeMemoizationInputs(value.alternate, null).rvalues, + ], + }; + } + case 'LogicalExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [ + ...this.computeMemoizationInputs(value.left, null).rvalues, + ...this.computeMemoizationInputs(value.right, null).rvalues, + ], + }; + } + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitValueForMemoization(instr.id, instr.value, instr.lvalue); + } + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: this.computeMemoizationInputs(value.value, null).rvalues, + }; + } + case 'JsxExpression': { + const operands = []; + if (value.tag.kind === 'Identifier') { + operands.push(value.tag); + } + for (const prop of value.props) { + if (prop.kind === 'JsxAttribute') { + operands.push(prop.place); + } + else { + operands.push(prop.argument); + } + } + if (value.children !== null) { + for (const child of value.children) { + operands.push(child); + } + } + const level = options.memoizeJsxElements + ? MemoizationLevel.Memoized + : MemoizationLevel.Unmemoized; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: operands, + }; + } + case 'JsxFragment': { + const level = options.memoizeJsxElements + ? MemoizationLevel.Memoized + : MemoizationLevel.Unmemoized; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: value.children, + }; + } + case 'NextPropertyOf': + case 'StartMemoize': + case 'FinishMemoize': + case 'Debugger': + case 'ComputedDelete': + case 'PropertyDelete': + case 'LoadGlobal': + case 'MetaProperty': + case 'TemplateLiteral': + case 'Primitive': + case 'JSXText': + case 'BinaryExpression': + case 'UnaryExpression': { + const level = options.forceMemoizePrimitives + ? MemoizationLevel.Memoized + : MemoizationLevel.Never; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: [], + }; + } + case 'Await': + case 'TypeCastExpression': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.value], + }; + } + case 'IteratorNext': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.iterator, value.collection], + }; + } + case 'GetIterator': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.collection], + }; + } + case 'LoadLocal': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.place], + }; + } + case 'LoadContext': { + return { + lvalues: lvalue !== null + ? [{ place: lvalue, level: MemoizationLevel.Conditional }] + : [], + rvalues: [value.place], + }; + } + case 'DeclareContext': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Memoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [], + }; + } + case 'DeclareLocal': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Unmemoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [], + }; + } + case 'PrefixUpdate': + case 'PostfixUpdate': { + const lvalues = [ + { place: value.lvalue, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreLocal': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreContext': { + const lvalues = [ + { place: value.lvalue.place, level: MemoizationLevel.Memoized }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'StoreGlobal': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Unmemoized }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'Destructure': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + lvalues.push(...computePatternLValues(value.lvalue.pattern)); + return { + lvalues: lvalues, + rvalues: [value.value], + }; + } + case 'ComputedLoad': + case 'PropertyLoad': { + const level = options.forceMemoizePrimitives + ? MemoizationLevel.Memoized + : MemoizationLevel.Conditional; + return { + lvalues: lvalue !== null ? [{ place: lvalue, level }] : [], + rvalues: [value.object], + }; + } + case 'ComputedStore': { + const lvalues = [ + { place: value.object, level: MemoizationLevel.Conditional }, + ]; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues, + rvalues: [value.value], + }; + } + case 'OptionalExpression': { + const lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Conditional }); + } + return { + lvalues: lvalues, + rvalues: [ + ...this.computeMemoizationInputs(value.value, null).rvalues, + ], + }; + } + case 'TaggedTemplateExpression': { + const signature = getFunctionCallSignature(env, value.tag.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'CallExpression': { + const signature = getFunctionCallSignature(env, value.callee.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'MethodCall': { + const signature = getFunctionCallSignature(env, value.property.identifier.type); + let lvalues = []; + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + if ((signature === null || signature === void 0 ? void 0 : signature.noAlias) === true) { + return { + lvalues, + rvalues: [], + }; + } + const operands = [...eachReactiveValueOperand(value)]; + lvalues.push(...operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized }))); + return { + lvalues, + rvalues: operands, + }; + } + case 'RegExpLiteral': + case 'ObjectMethod': + case 'FunctionExpression': + case 'ArrayExpression': + case 'NewExpression': + case 'ObjectExpression': + case 'PropertyStore': { + const operands = [...eachReactiveValueOperand(value)]; + const lvalues = operands + .filter(operand => isMutableEffect(operand.effect, operand.loc)) + .map(place => ({ place, level: MemoizationLevel.Memoized })); + if (lvalue !== null) { + lvalues.push({ place: lvalue, level: MemoizationLevel.Memoized }); + } + return { + lvalues, + rvalues: operands, + }; + } + case 'UnsupportedNode': { + CompilerError.invariant(false, { + reason: `Unexpected unsupported node`, + description: null, + loc: value.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(value, `Unexpected value kind \`${value.kind}\``); + } + } + } + visitValueForMemoization(id, value, lvalue) { + var _a, _b, _c; + const state = this.state; + const aliasing = this.computeMemoizationInputs(value, lvalue); + for (const operand of aliasing.rvalues) { + const operandId = (_a = state.definitions.get(operand.identifier.declarationId)) !== null && _a !== void 0 ? _a : operand.identifier.declarationId; + state.visitOperand(id, operand, operandId); + } + for (const { place: lvalue, level } of aliasing.lvalues) { + const lvalueId = (_b = state.definitions.get(lvalue.identifier.declarationId)) !== null && _b !== void 0 ? _b : lvalue.identifier.declarationId; + let node = state.identifiers.get(lvalueId); + if (node === undefined) { + node = { + level: MemoizationLevel.Never, + memoized: false, + dependencies: new Set(), + scopes: new Set(), + seen: false, + }; + state.identifiers.set(lvalueId, node); + } + node.level = joinAliases(node.level, level); + for (const operand of aliasing.rvalues) { + const operandId = (_c = state.definitions.get(operand.identifier.declarationId)) !== null && _c !== void 0 ? _c : operand.identifier.declarationId; + if (operandId === lvalueId) { + continue; + } + node.dependencies.add(operandId); + } + state.visitOperand(id, lvalue, lvalueId); + } + if (value.kind === 'LoadLocal' && lvalue !== null) { + state.definitions.set(lvalue.identifier.declarationId, value.place.identifier.declarationId); + } + else if (value.kind === 'CallExpression' || value.kind === 'MethodCall') { + let callee = value.kind === 'CallExpression' ? value.callee : value.property; + if (getHookKind(state.env, callee.identifier) != null) { + const signature = getFunctionCallSignature(this.env, callee.identifier.type); + if (signature && signature.noAlias === true) { + return; + } + for (const operand of value.args) { + const place = operand.kind === 'Spread' ? operand.place : operand; + state.escapingValues.add(place.identifier.declarationId); + } + } + } + } + visitInstruction(instruction, _scopes) { + this.visitValueForMemoization(instruction.id, instruction.value, instruction.lvalue); + } + visitTerminal(stmt, scopes) { + this.traverseTerminal(stmt, scopes); + if (stmt.terminal.kind === 'return') { + this.state.escapingValues.add(stmt.terminal.value.identifier.declarationId); + const identifierNode = this.state.identifiers.get(stmt.terminal.value.identifier.declarationId); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: null, + loc: stmt.terminal.loc, + suggestions: null, + }); + for (const scope of scopes) { + identifierNode.scopes.add(scope.id); + } + } + } + visitScope(scope, scopes) { + for (const reassignment of scope.scope.reassignments) { + const identifierNode = this.state.identifiers.get(reassignment.declarationId); + CompilerError.invariant(identifierNode !== undefined, { + reason: 'Expected identifier to be initialized', + description: null, + loc: reassignment.loc, + suggestions: null, + }); + for (const scope of scopes) { + identifierNode.scopes.add(scope.id); + } + identifierNode.scopes.add(scope.scope.id); + } + this.traverseScope(scope, [...scopes, scope.scope]); + } +} +class PruneScopesTransform extends ReactiveFunctionTransform { + constructor() { + super(...arguments); + this.prunedScopes = new Set(); + this.reassignments = new Map(); + } + transformScope(scopeBlock, state) { + this.visitScope(scopeBlock, state); + if ((scopeBlock.scope.declarations.size === 0 && + scopeBlock.scope.reassignments.size === 0) || + scopeBlock.scope.earlyReturnValue !== null) { + return { kind: 'keep' }; + } + const hasMemoizedOutput = Array.from(scopeBlock.scope.declarations.values()).some(decl => state.has(decl.identifier.declarationId)) || + Array.from(scopeBlock.scope.reassignments).some(identifier => state.has(identifier.declarationId)); + if (hasMemoizedOutput) { + return { kind: 'keep' }; + } + else { + this.prunedScopes.add(scopeBlock.scope.id); + return { + kind: 'replace-many', + value: scopeBlock.instructions, + }; + } + } + transformInstruction(instruction, state) { + var _a; + this.traverseInstruction(instruction, state); + const value = instruction.value; + if (value.kind === 'StoreLocal' && value.lvalue.kind === 'Reassign') { + const ids = getOrInsertDefault(this.reassignments, value.lvalue.place.identifier.declarationId, new Set()); + ids.add(value.value.identifier); + } + else if (value.kind === 'FinishMemoize') { + let decls; + if (value.decl.identifier.scope == null) { + decls = (_a = this.reassignments.get(value.decl.identifier.declarationId)) !== null && _a !== void 0 ? _a : [ + value.decl.identifier, + ]; + } + else { + decls = [value.decl.identifier]; + } + if ([...decls].every(decl => decl.scope == null || this.prunedScopes.has(decl.scope.id))) { + value.pruned = true; + } + } + return { kind: 'keep' }; + } +} + +let Visitor$7 = class Visitor extends ReactiveFunctionVisitor { + visitLValue(id, lvalue, state) { + this.visitPlace(id, lvalue, state); + } + visitPlace(_id, place, state) { + if (place.reactive) { + state.add(place.identifier.id); + } + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + for (const [id, decl] of scopeBlock.scope.declarations) { + if (!isPrimitiveType(decl.identifier) && + !isStableRefType(decl.identifier, state)) { + state.add(id); + } + } + } +}; +function isStableRefType(identifier, reactiveIdentifiers) { + return isUseRefType(identifier) && !reactiveIdentifiers.has(identifier.id); +} +function collectReactiveIdentifiers(fn) { + const visitor = new Visitor$7(); + const state = new Set(); + visitReactiveFunction(fn, visitor, state); + return state; +} + +function pruneNonReactiveDependencies(fn) { + const reactiveIdentifiers = collectReactiveIdentifiers(fn); + visitReactiveFunction(fn, new Visitor$6(), reactiveIdentifiers); +} +let Visitor$6 = class Visitor extends ReactiveFunctionVisitor { + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + const { lvalue, value } = instruction; + switch (value.kind) { + case 'LoadLocal': { + if (lvalue !== null && state.has(value.place.identifier.id)) { + state.add(lvalue.identifier.id); + } + break; + } + case 'StoreLocal': { + if (state.has(value.value.identifier.id)) { + state.add(value.lvalue.place.identifier.id); + if (lvalue !== null) { + state.add(lvalue.identifier.id); + } + } + break; + } + case 'Destructure': { + if (state.has(value.value.identifier.id)) { + for (const lvalue of eachPatternOperand(value.lvalue.pattern)) { + if (isStableType(lvalue.identifier)) { + continue; + } + state.add(lvalue.identifier.id); + } + if (lvalue !== null) { + state.add(lvalue.identifier.id); + } + } + break; + } + case 'PropertyLoad': { + if (lvalue !== null && + state.has(value.object.identifier.id) && + !isStableType(lvalue.identifier)) { + state.add(lvalue.identifier.id); + } + break; + } + case 'ComputedLoad': { + if (lvalue !== null && + (state.has(value.object.identifier.id) || + state.has(value.property.identifier.id))) { + state.add(lvalue.identifier.id); + } + break; + } + } + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + for (const dep of scopeBlock.scope.dependencies) { + const isReactive = state.has(dep.identifier.id); + if (!isReactive) { + scopeBlock.scope.dependencies.delete(dep); + } + } + if (scopeBlock.scope.dependencies.size !== 0) { + for (const [, declaration] of scopeBlock.scope.declarations) { + state.add(declaration.identifier.id); + } + for (const reassignment of scopeBlock.scope.reassignments) { + state.add(reassignment.id); + } + } + } +}; + +function pruneUnusedLValues(fn) { + const lvalues = new Map(); + visitReactiveFunction(fn, new Visitor$5(), lvalues); + for (const [, instr] of lvalues) { + instr.lvalue = null; + } +} +let Visitor$5 = class Visitor extends ReactiveFunctionVisitor { + visitPlace(id, place, state) { + state.delete(place.identifier.declarationId); + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + if (instruction.lvalue !== null && + instruction.lvalue.identifier.name === null) { + state.set(instruction.lvalue.identifier.declarationId, instruction); + } + } +}; + +function pruneUnusedLabels(fn) { + const labels = new Set(); + visitReactiveFunction(fn, new Transform$2(), labels); +} +let Transform$2 = class Transform extends ReactiveFunctionTransform { + transformTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + const { terminal } = stmt; + if ((terminal.kind === 'break' || terminal.kind === 'continue') && + terminal.targetKind === 'labeled') { + state.add(terminal.target); + } + const isReachableLabel = stmt.label !== null && state.has(stmt.label.id); + if (stmt.terminal.kind === 'label' && !isReachableLabel) { + const block = [...stmt.terminal.block]; + const last = block.at(-1); + if (last !== undefined && + last.kind === 'terminal' && + last.terminal.kind === 'break' && + last.terminal.target === null) { + block.pop(); + } + return { kind: 'replace-many', value: block }; + } + else { + if (!isReachableLabel && stmt.label != null) { + stmt.label.implicit = true; + } + return { kind: 'keep' }; + } + } +}; + +function pruneUnusedScopes(fn) { + visitReactiveFunction(fn, new Transform$1(), { + hasReturnStatement: false, + }); +} +let Transform$1 = class Transform extends ReactiveFunctionTransform { + visitTerminal(stmt, state) { + this.traverseTerminal(stmt, state); + if (stmt.terminal.kind === 'return') { + state.hasReturnStatement = true; + } + } + transformScope(scopeBlock, _state) { + const scopeState = { hasReturnStatement: false }; + this.visitScope(scopeBlock, scopeState); + if (!scopeState.hasReturnStatement && + scopeBlock.scope.reassignments.size === 0 && + (scopeBlock.scope.declarations.size === 0 || + !hasOwnDeclaration(scopeBlock))) { + return { + kind: 'replace', + value: { + kind: 'pruned-scope', + scope: scopeBlock.scope, + instructions: scopeBlock.instructions, + }, + }; + } + else { + return { kind: 'keep' }; + } + } +}; +function hasOwnDeclaration(block) { + for (const declaration of block.scope.declarations.values()) { + if (declaration.scope.id === block.scope.id) { + return true; + } + } + return false; +} + +function collectReferencedGlobals(fn) { + const identifiers = new Set(); + visitReactiveFunction(fn, new Visitor$4(), identifiers); + return identifiers; +} +let Visitor$4 = class Visitor extends ReactiveFunctionVisitor { + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + else if (value.kind === 'LoadGlobal') { + state.add(value.binding.name); + } + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +}; + +var _Scopes_instances, _Scopes_seen, _Scopes_stack, _Scopes_globals, _Scopes_programContext, _Scopes_lookup; +function renameVariables(fn) { + const globals = collectReferencedGlobals(fn); + const scopes = new Scopes(globals, fn.env.programContext); + renameVariablesImpl(fn, new Visitor$3(), scopes); + return new Set([...scopes.names, ...globals]); +} +function renameVariablesImpl(fn, visitor, scopes) { + scopes.enter(() => { + for (const param of fn.params) { + if (param.kind === 'Identifier') { + scopes.visit(param.identifier); + } + else { + scopes.visit(param.place.identifier); + } + } + visitReactiveFunction(fn, visitor, scopes); + }); +} +let Visitor$3 = class Visitor extends ReactiveFunctionVisitor { + visitParam(place, state) { + state.visit(place.identifier); + } + visitLValue(_id, lvalue, state) { + state.visit(lvalue.identifier); + } + visitPlace(id, place, state) { + state.visit(place.identifier); + } + visitBlock(block, state) { + state.enter(() => { + this.traverseBlock(block, state); + }); + } + visitPrunedScope(scopeBlock, state) { + this.traverseBlock(scopeBlock.instructions, state); + } + visitScope(scope, state) { + for (const [_, declaration] of scope.scope.declarations) { + state.visit(declaration.identifier); + } + this.traverseScope(scope, state); + } + visitValue(id, value, state) { + this.traverseValue(id, value, state); + if (value.kind === 'FunctionExpression' || value.kind === 'ObjectMethod') { + this.visitHirFunction(value.loweredFunc.func, state); + } + } + visitReactiveFunctionValue(_id, _dependencies, _fn, _state) { + renameVariablesImpl(_fn, this, _state); + } +}; +class Scopes { + constructor(globals, programContext) { + _Scopes_instances.add(this); + _Scopes_seen.set(this, new Map()); + _Scopes_stack.set(this, [new Map()]); + _Scopes_globals.set(this, void 0); + _Scopes_programContext.set(this, void 0); + this.names = new Set(); + __classPrivateFieldSet(this, _Scopes_globals, globals, "f"); + __classPrivateFieldSet(this, _Scopes_programContext, programContext, "f"); + } + visit(identifier) { + const originalName = identifier.name; + if (originalName === null) { + return; + } + const mappedName = __classPrivateFieldGet(this, _Scopes_seen, "f").get(identifier.declarationId); + if (mappedName !== undefined) { + identifier.name = mappedName; + return; + } + let name = originalName.value; + let id = 0; + if (isPromotedTemporary(originalName.value)) { + name = `t${id++}`; + } + else if (isPromotedJsxTemporary(originalName.value)) { + name = `T${id++}`; + } + while (__classPrivateFieldGet(this, _Scopes_instances, "m", _Scopes_lookup).call(this, name) !== null || __classPrivateFieldGet(this, _Scopes_globals, "f").has(name)) { + if (isPromotedTemporary(originalName.value)) { + name = `t${id++}`; + } + else if (isPromotedJsxTemporary(originalName.value)) { + name = `T${id++}`; + } + else { + name = `${originalName.value}$${id++}`; + } + } + __classPrivateFieldGet(this, _Scopes_programContext, "f").addNewReference(name); + const identifierName = makeIdentifierName(name); + identifier.name = identifierName; + __classPrivateFieldGet(this, _Scopes_seen, "f").set(identifier.declarationId, identifierName); + __classPrivateFieldGet(this, _Scopes_stack, "f").at(-1).set(identifierName.value, identifier.declarationId); + this.names.add(identifierName.value); + } + enter(fn) { + const next = new Map(); + __classPrivateFieldGet(this, _Scopes_stack, "f").push(next); + fn(); + const last = __classPrivateFieldGet(this, _Scopes_stack, "f").pop(); + CompilerError.invariant(last === next, { + reason: 'Mismatch push/pop calls', + description: null, + loc: null, + suggestions: null, + }); + } +} +_Scopes_seen = new WeakMap(), _Scopes_stack = new WeakMap(), _Scopes_globals = new WeakMap(), _Scopes_programContext = new WeakMap(), _Scopes_instances = new WeakSet(), _Scopes_lookup = function _Scopes_lookup(name) { + for (let i = __classPrivateFieldGet(this, _Scopes_stack, "f").length - 1; i >= 0; i--) { + const scope = __classPrivateFieldGet(this, _Scopes_stack, "f")[i]; + const entry = scope.get(name); + if (entry !== undefined) { + return entry; + } + } + return null; +}; + +function stabilizeBlockIds(fn) { + const referenced = new Set(); + visitReactiveFunction(fn, new CollectReferencedLabels(), referenced); + const mappings = new Map(); + for (const blockId of referenced) { + mappings.set(blockId, makeBlockId(mappings.size)); + } + visitReactiveFunction(fn, new RewriteBlockIds(), mappings); +} +class CollectReferencedLabels extends ReactiveFunctionVisitor { + visitScope(scope, state) { + const { earlyReturnValue } = scope.scope; + if (earlyReturnValue != null) { + state.add(earlyReturnValue.label); + } + this.traverseScope(scope, state); + } + visitTerminal(stmt, state) { + if (stmt.label != null) { + if (!stmt.label.implicit) { + state.add(stmt.label.id); + } + } + this.traverseTerminal(stmt, state); + } +} +class RewriteBlockIds extends ReactiveFunctionVisitor { + visitScope(scope, state) { + const { earlyReturnValue } = scope.scope; + if (earlyReturnValue != null) { + const rewrittenId = getOrInsertDefault(state, earlyReturnValue.label, state.size); + earlyReturnValue.label = makeBlockId(rewrittenId); + } + this.traverseScope(scope, state); + } + visitTerminal(stmt, state) { + if (stmt.label != null) { + const rewrittenId = getOrInsertDefault(state, stmt.label.id, state.size); + stmt.label.id = makeBlockId(rewrittenId); + } + const terminal = stmt.terminal; + if (terminal.kind === 'break' || terminal.kind === 'continue') { + const rewrittenId = getOrInsertDefault(state, terminal.target, state.size); + terminal.target = makeBlockId(rewrittenId); + } + this.traverseTerminal(stmt, state); + } +} + +function inferAliases(func) { + const aliases = new DisjointSet(); + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + inferInstr(instr, aliases); + } + } + return aliases; +} +function inferInstr(instr, aliases) { + const { lvalue, value: instrValue } = instr; + let alias = null; + switch (instrValue.kind) { + case 'LoadLocal': + case 'LoadContext': { + if (isPrimitiveType(instrValue.place.identifier)) { + return; + } + alias = instrValue.place; + break; + } + case 'StoreLocal': + case 'StoreContext': { + alias = instrValue.value; + break; + } + case 'Destructure': { + alias = instrValue.value; + break; + } + case 'ComputedLoad': + case 'PropertyLoad': { + alias = instrValue.object; + break; + } + case 'TypeCastExpression': { + alias = instrValue.value; + break; + } + default: + return; + } + aliases.union([lvalue.identifier, alias.identifier]); +} + +function inferAliasForPhis(func, aliases) { + var _a, _b; + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + const isPhiMutatedAfterCreation = phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id); + if (isPhiMutatedAfterCreation) { + for (const [, operand] of phi.operands) { + aliases.union([phi.place.identifier, operand.identifier]); + } + } + } + } +} + +function inferAliasForStores(func, aliases) { + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + const isStore = lvalue.effect === Effect.Store || + ![...eachInstructionValueOperand(value)].every(operand => operand.effect !== Effect.Store); + if (!isStore) { + continue; + } + for (const operand of eachInstructionLValue(instr)) { + maybeAlias(aliases, lvalue, operand, instr.id); + } + for (const operand of eachInstructionValueOperand(value)) { + if (operand.effect === Effect.Capture || + operand.effect === Effect.Store) { + maybeAlias(aliases, lvalue, operand, instr.id); + } + } + } + } +} +function maybeAlias(aliases, lvalue, rvalue, id) { + if (lvalue.identifier.mutableRange.end > id + 1 || + rvalue.identifier.mutableRange.end > id) { + aliases.union([lvalue.identifier, rvalue.identifier]); + } +} + +function infer$1(place, instrId) { + if (!isRefOrRefValue(place.identifier)) { + place.identifier.mutableRange.end = makeInstructionId(instrId + 1); + } +} +function inferPlace(place, instrId, inferMutableRangeForStores) { + switch (place.effect) { + case Effect.Unknown: { + throw new Error(`Found an unknown place ${printPlace(place)}}!`); + } + case Effect.Capture: + case Effect.Read: + case Effect.Freeze: + return; + case Effect.Store: + if (inferMutableRangeForStores) { + infer$1(place, instrId); + } + return; + case Effect.ConditionallyMutateIterator: { + const identifier = place.identifier; + if (!isArrayType(identifier) && + !isSetType(identifier) && + !isMapType(identifier)) { + infer$1(place, instrId); + } + return; + } + case Effect.ConditionallyMutate: + case Effect.Mutate: { + infer$1(place, instrId); + return; + } + default: + assertExhaustive$1(place.effect, `Unexpected ${printPlace(place)} effect`); + } +} +function inferMutableLifetimes(func, inferMutableRangeForStores) { + var _a, _b; + const contextVariableDeclarationInstructions = new Map(); + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + const isPhiMutatedAfterCreation = phi.place.identifier.mutableRange.end > + ((_b = (_a = block.instructions.at(0)) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id); + if (inferMutableRangeForStores && + isPhiMutatedAfterCreation && + phi.place.identifier.mutableRange.start === 0) { + for (const [, operand] of phi.operands) { + if (phi.place.identifier.mutableRange.start === 0) { + phi.place.identifier.mutableRange.start = + operand.identifier.mutableRange.start; + } + else { + phi.place.identifier.mutableRange.start = makeInstructionId(Math.min(phi.place.identifier.mutableRange.start, operand.identifier.mutableRange.start)); + } + } + } + } + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + const lvalueId = operand.identifier; + lvalueId.mutableRange.start = instr.id; + lvalueId.mutableRange.end = makeInstructionId(instr.id + 1); + } + for (const operand of eachInstructionOperand(instr)) { + inferPlace(operand, instr.id, inferMutableRangeForStores); + } + if (instr.value.kind === 'DeclareContext' || + (instr.value.kind === 'StoreContext' && + instr.value.lvalue.kind !== InstructionKind.Reassign && + !contextVariableDeclarationInstructions.has(instr.value.lvalue.place.identifier))) { + contextVariableDeclarationInstructions.set(instr.value.lvalue.place.identifier, instr.id); + } + else if (instr.value.kind === 'StoreContext') { + const declaration = contextVariableDeclarationInstructions.get(instr.value.lvalue.place.identifier); + if (declaration != null && + !isRefOrRefValue(instr.value.lvalue.place.identifier)) { + const range = instr.value.lvalue.place.identifier.mutableRange; + if (range.start === 0) { + range.start = declaration; + } + else { + range.start = makeInstructionId(Math.min(range.start, declaration)); + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + inferPlace(operand, block.terminal.id, inferMutableRangeForStores); + } + } +} + +function inferMutableRangesForAlias(_fn, aliases) { + const aliasSets = aliases.buildSets(); + for (const aliasSet of aliasSets) { + const mutatingIdentifiers = [...aliasSet].filter(id => id.mutableRange.end - id.mutableRange.start > 1 && !isRefOrRefValue(id)); + if (mutatingIdentifiers.length > 0) { + let lastMutatingInstructionId = 0; + for (const id of mutatingIdentifiers) { + if (id.mutableRange.end > lastMutatingInstructionId) { + lastMutatingInstructionId = id.mutableRange.end; + } + } + for (const alias of aliasSet) { + if (alias.mutableRange.end < lastMutatingInstructionId && + !isRefOrRefValue(alias)) { + alias.mutableRange.end = lastMutatingInstructionId; + } + } + } + } +} + +function inferTryCatchAliases(fn, aliases) { + const handlerParams = new Map(); + for (const [_, block] of fn.body.blocks) { + if (block.terminal.kind === 'try' && + block.terminal.handlerBinding !== null) { + handlerParams.set(block.terminal.handler, block.terminal.handlerBinding.identifier); + } + else if (block.terminal.kind === 'maybe-throw') { + const handlerParam = handlerParams.get(block.terminal.handler); + if (handlerParam === undefined) { + continue; + } + for (const instr of block.instructions) { + aliases.union([handlerParam, instr.lvalue.identifier]); + } + } + } +} + +function inferMutableRanges(ir) { + inferMutableLifetimes(ir, false); + const aliases = inferAliases(ir); + inferTryCatchAliases(ir, aliases); + let prevAliases = aliases.canonicalize(); + while (true) { + inferMutableRangesForAlias(ir, aliases); + inferAliasForStores(ir, aliases); + inferAliasForPhis(ir, aliases); + const nextAliases = aliases.canonicalize(); + if (areEqualMaps(prevAliases, nextAliases)) { + break; + } + prevAliases = nextAliases; + } + inferMutableLifetimes(ir, true); + prevAliases = aliases.canonicalize(); + while (true) { + inferMutableRangesForAlias(ir, aliases); + inferAliasForPhis(ir, aliases); + const nextAliases = aliases.canonicalize(); + if (areEqualMaps(prevAliases, nextAliases)) { + break; + } + prevAliases = nextAliases; + } +} +function areEqualMaps(a, b) { + if (a.size !== b.size) { + return false; + } + for (const [key, value] of a) { + if (!b.has(key)) { + return false; + } + if (b.get(key) !== value) { + return false; + } + } + return true; +} + +function analyseFunctions(func) { + for (const [_, block] of func.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'ObjectMethod': + case 'FunctionExpression': { + lower(instr.value.loweredFunc.func); + infer(instr.value.loweredFunc); + for (const operand of instr.value.loweredFunc.func.context) { + operand.identifier.mutableRange.start = makeInstructionId(0); + operand.identifier.mutableRange.end = makeInstructionId(0); + operand.identifier.scope = null; + } + break; + } + } + } + } +} +function lower(func) { + var _a, _b; + analyseFunctions(func); + inferReferenceEffects(func, { isFunctionExpression: true }); + deadCodeElimination(func); + inferMutableRanges(func); + rewriteInstructionKindsBasedOnReassignment(func); + inferReactiveScopeVariables(func); + (_b = (_a = func.env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'hir', + name: 'AnalyseFunction (inner)', + value: func, + }); +} +function infer(loweredFunc) { + for (const operand of loweredFunc.func.context) { + const identifier = operand.identifier; + CompilerError.invariant(operand.effect === Effect.Unknown, { + reason: '[AnalyseFunctions] Expected Function context effects to not have been set', + loc: operand.loc, + }); + if (isRefOrRefValue(identifier)) { + operand.effect = Effect.Capture; + } + else if (isMutatedOrReassigned(identifier)) { + operand.effect = Effect.Capture; + } + else { + operand.effect = Effect.Read; + } + } +} +function isMutatedOrReassigned(id) { + return id.mutableRange.end > id.mutableRange.start; +} + +function collectMaybeMemoDependencies(value, maybeDeps, optional) { + var _a; + switch (value.kind) { + case 'LoadGlobal': { + return { + root: { + kind: 'Global', + identifierName: value.binding.name, + }, + path: [], + }; + } + case 'PropertyLoad': { + const object = maybeDeps.get(value.object.identifier.id); + if (object != null) { + return { + root: object.root, + path: [...object.path, { property: value.property, optional }], + }; + } + break; + } + case 'LoadLocal': + case 'LoadContext': { + const source = maybeDeps.get(value.place.identifier.id); + if (source != null) { + return source; + } + else if (value.place.identifier.name != null && + value.place.identifier.name.kind === 'named') { + return { + root: { + kind: 'NamedLocal', + value: Object.assign({}, value.place), + }, + path: [], + }; + } + break; + } + case 'StoreLocal': { + const lvalue = value.lvalue.place.identifier; + const rvalue = value.value.identifier.id; + const aliased = maybeDeps.get(rvalue); + if (aliased != null && ((_a = lvalue.name) === null || _a === void 0 ? void 0 : _a.kind) !== 'named') { + maybeDeps.set(lvalue.id, aliased); + return aliased; + } + break; + } + } + return null; +} +function collectTemporaries(instr, env, sidemap) { + const { value, lvalue } = instr; + switch (value.kind) { + case 'FunctionExpression': { + sidemap.functions.set(instr.lvalue.identifier.id, instr); + break; + } + case 'LoadGlobal': { + const global = env.getGlobalDeclaration(value.binding, value.loc); + const hookKind = global !== null ? getHookKindForType(env, global) : null; + const lvalId = instr.lvalue.identifier.id; + if (hookKind === 'useMemo' || hookKind === 'useCallback') { + sidemap.manualMemos.set(lvalId, { + kind: hookKind, + loadInstr: instr, + }); + } + else if (value.binding.name === 'React') { + sidemap.react.add(lvalId); + } + break; + } + case 'PropertyLoad': { + if (sidemap.react.has(value.object.identifier.id)) { + const property = value.property; + if (property === 'useMemo' || property === 'useCallback') { + sidemap.manualMemos.set(instr.lvalue.identifier.id, { + kind: property, + loadInstr: instr, + }); + } + } + break; + } + case 'ArrayExpression': { + if (value.elements.every(e => e.kind === 'Identifier')) { + sidemap.maybeDepsLists.set(instr.lvalue.identifier.id, value.elements); + } + break; + } + } + const maybeDep = collectMaybeMemoDependencies(value, sidemap.maybeDeps, sidemap.optionals.has(lvalue.identifier.id)); + if (maybeDep != null) { + sidemap.maybeDeps.set(lvalue.identifier.id, maybeDep); + } +} +function makeManualMemoizationMarkers(fnExpr, env, depsList, memoDecl, manualMemoId) { + return [ + { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, fnExpr.loc), + value: { + kind: 'StartMemoize', + manualMemoId, + deps: depsList, + loc: fnExpr.loc, + }, + loc: fnExpr.loc, + }, + { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, fnExpr.loc), + value: { + kind: 'FinishMemoize', + manualMemoId, + decl: Object.assign({}, memoDecl), + loc: fnExpr.loc, + }, + loc: fnExpr.loc, + }, + ]; +} +function getManualMemoizationReplacement(fn, loc, kind) { + if (kind === 'useMemo') { + return { + kind: 'CallExpression', + callee: fn, + args: [], + loc, + }; + } + else { + return { + kind: 'LoadLocal', + place: { + kind: 'Identifier', + identifier: fn.identifier, + effect: Effect.Unknown, + reactive: false, + loc, + }, + loc, + }; + } +} +function extractManualMemoizationArgs(instr, kind, sidemap) { + const [fnPlace, depsListPlace] = instr.value.args; + if (fnPlace == null) { + CompilerError.throwInvalidReact({ + reason: `Expected a callback function to be passed to ${kind}`, + loc: instr.value.loc, + suggestions: null, + }); + } + if (fnPlace.kind === 'Spread' || (depsListPlace === null || depsListPlace === void 0 ? void 0 : depsListPlace.kind) === 'Spread') { + CompilerError.throwInvalidReact({ + reason: `Unexpected spread argument to ${kind}`, + loc: instr.value.loc, + suggestions: null, + }); + } + let depsList = null; + if (depsListPlace != null) { + const maybeDepsList = sidemap.maybeDepsLists.get(depsListPlace.identifier.id); + if (maybeDepsList == null) { + CompilerError.throwInvalidReact({ + reason: `Expected the dependency list for ${kind} to be an array literal`, + suggestions: null, + loc: depsListPlace.loc, + }); + } + depsList = maybeDepsList.map(dep => { + const maybeDep = sidemap.maybeDeps.get(dep.identifier.id); + if (maybeDep == null) { + CompilerError.throwInvalidReact({ + reason: `Expected the dependency list to be an array of simple expressions (e.g. \`x\`, \`x.y.z\`, \`x?.y?.z\`)`, + suggestions: null, + loc: dep.loc, + }); + } + return maybeDep; + }); + } + return { + fnPlace, + depsList, + }; +} +function dropManualMemoization(func) { + const isValidationEnabled = func.env.config.validatePreserveExistingMemoizationGuarantees || + func.env.config.validateNoSetStateInRender || + func.env.config.enablePreserveExistingMemoizationGuarantees; + const optionals = findOptionalPlaces(func); + const sidemap = { + functions: new Map(), + manualMemos: new Map(), + react: new Set(), + maybeDeps: new Map(), + maybeDepsLists: new Map(), + optionals, + }; + let nextManualMemoId = 0; + const queuedInserts = new Map(); + for (const [_, block] of func.body.blocks) { + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + if (instr.value.kind === 'CallExpression' || + instr.value.kind === 'MethodCall') { + const id = instr.value.kind === 'CallExpression' + ? instr.value.callee.identifier.id + : instr.value.property.identifier.id; + const manualMemo = sidemap.manualMemos.get(id); + if (manualMemo != null) { + const { fnPlace, depsList } = extractManualMemoizationArgs(instr, manualMemo.kind, sidemap); + instr.value = getManualMemoizationReplacement(fnPlace, instr.value.loc, manualMemo.kind); + if (isValidationEnabled) { + if (!sidemap.functions.has(fnPlace.identifier.id)) { + CompilerError.throwInvalidReact({ + reason: `Expected the first argument to be an inline function expression`, + suggestions: [], + loc: fnPlace.loc, + }); + } + const memoDecl = manualMemo.kind === 'useMemo' + ? instr.lvalue + : { + kind: 'Identifier', + identifier: fnPlace.identifier, + effect: Effect.Unknown, + reactive: false, + loc: fnPlace.loc, + }; + const [startMarker, finishMarker] = makeManualMemoizationMarkers(fnPlace, func.env, depsList, memoDecl, nextManualMemoId++); + queuedInserts.set(manualMemo.loadInstr.id, startMarker); + queuedInserts.set(instr.id, finishMarker); + } + } + } + else { + collectTemporaries(instr, func.env, sidemap); + } + } + } + if (queuedInserts.size > 0) { + let hasChanges = false; + for (const [_, block] of func.body.blocks) { + let nextInstructions = null; + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + const insertInstr = queuedInserts.get(instr.id); + if (insertInstr != null) { + nextInstructions = nextInstructions !== null && nextInstructions !== void 0 ? nextInstructions : block.instructions.slice(0, i); + nextInstructions.push(instr); + nextInstructions.push(insertInstr); + } + else if (nextInstructions != null) { + nextInstructions.push(instr); + } + } + if (nextInstructions !== null) { + block.instructions = nextInstructions; + hasChanges = true; + } + } + if (hasChanges) { + markInstructionIds(func.body); + } + } +} +function findOptionalPlaces(fn) { + const optionals = new Set(); + for (const [, block] of fn.body.blocks) { + if (block.terminal.kind === 'optional' && block.terminal.optional) { + const optionalTerminal = block.terminal; + let testBlock = fn.body.blocks.get(block.terminal.test); + loop: while (true) { + const terminal = testBlock.terminal; + switch (terminal.kind) { + case 'branch': { + if (terminal.fallthrough === optionalTerminal.fallthrough) { + const consequent = fn.body.blocks.get(terminal.consequent); + const last = consequent.instructions.at(-1); + if (last !== undefined && last.value.kind === 'StoreLocal') { + optionals.add(last.value.value.identifier.id); + } + break loop; + } + else { + testBlock = fn.body.blocks.get(terminal.fallthrough); + } + break; + } + case 'optional': + case 'logical': + case 'sequence': + case 'ternary': { + testBlock = fn.body.blocks.get(terminal.fallthrough); + break; + } + default: { + CompilerError.invariant(false, { + reason: `Unexpected terminal in optional`, + loc: terminal.loc, + }); + } + } + } + } + } + return optionals; +} + +class StableSidemap { + constructor(env) { + this.map = new Map(); + this.env = env; + } + handleInstruction(instr) { + const { value, lvalue } = instr; + switch (value.kind) { + case 'CallExpression': + case 'MethodCall': { + if (evaluatesToStableTypeOrContainer(this.env, instr)) { + if (isStableType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + else { + this.map.set(lvalue.identifier.id, { + isStable: false, + }); + } + } + else if (this.env.config.enableTreatRefLikeIdentifiersAsRefs && + isUseRefType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + break; + } + case 'Destructure': + case 'PropertyLoad': { + const source = value.kind === 'Destructure' + ? value.value.identifier.id + : value.object.identifier.id; + const entry = this.map.get(source); + if (entry) { + for (const lvalue of eachInstructionLValue(instr)) { + if (isStableTypeContainer(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: false, + }); + } + else if (isStableType(lvalue.identifier)) { + this.map.set(lvalue.identifier.id, { + isStable: true, + }); + } + } + } + break; + } + case 'StoreLocal': { + const entry = this.map.get(value.value.identifier.id); + if (entry) { + this.map.set(lvalue.identifier.id, entry); + this.map.set(value.lvalue.place.identifier.id, entry); + } + break; + } + case 'LoadLocal': { + const entry = this.map.get(value.place.identifier.id); + if (entry) { + this.map.set(lvalue.identifier.id, entry); + } + break; + } + } + } + isStable(id) { + const entry = this.map.get(id); + return entry != null ? entry.isStable : false; + } +} +function inferReactivePlaces(fn) { + const reactiveIdentifiers = new ReactivityMap(findDisjointMutableValues(fn)); + const stableIdentifierSources = new StableSidemap(fn.env); + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + reactiveIdentifiers.markReactive(place); + } + const postDominators = computePostDominatorTree(fn, { + includeThrowsAsExitNode: false, + }); + const postDominatorFrontierCache = new Map(); + function isReactiveControlledBlock(id) { + let controlBlocks = postDominatorFrontierCache.get(id); + if (controlBlocks === undefined) { + controlBlocks = postDominatorFrontier(fn, postDominators, id); + postDominatorFrontierCache.set(id, controlBlocks); + } + for (const blockId of controlBlocks) { + const controlBlock = fn.body.blocks.get(blockId); + switch (controlBlock.terminal.kind) { + case 'if': + case 'branch': { + if (reactiveIdentifiers.isReactive(controlBlock.terminal.test)) { + return true; + } + break; + } + case 'switch': { + if (reactiveIdentifiers.isReactive(controlBlock.terminal.test)) { + return true; + } + for (const case_ of controlBlock.terminal.cases) { + if (case_.test !== null && + reactiveIdentifiers.isReactive(case_.test)) { + return true; + } + } + break; + } + } + } + return false; + } + do { + for (const [, block] of fn.body.blocks) { + let hasReactiveControl = isReactiveControlledBlock(block.id); + for (const phi of block.phis) { + if (reactiveIdentifiers.isReactive(phi.place)) { + continue; + } + let isPhiReactive = false; + for (const [, operand] of phi.operands) { + if (reactiveIdentifiers.isReactive(operand)) { + isPhiReactive = true; + break; + } + } + if (isPhiReactive) { + reactiveIdentifiers.markReactive(phi.place); + } + else { + for (const [pred] of phi.operands) { + if (isReactiveControlledBlock(pred)) { + reactiveIdentifiers.markReactive(phi.place); + break; + } + } + } + } + for (const instruction of block.instructions) { + stableIdentifierSources.handleInstruction(instruction); + const { value } = instruction; + let hasReactiveInput = false; + for (const operand of eachInstructionValueOperand(value)) { + const reactive = reactiveIdentifiers.isReactive(operand); + hasReactiveInput || (hasReactiveInput = reactive); + } + if (value.kind === 'CallExpression' && + (getHookKind(fn.env, value.callee.identifier) != null || + isUseOperator(value.callee.identifier))) { + hasReactiveInput = true; + } + else if (value.kind === 'MethodCall' && + (getHookKind(fn.env, value.property.identifier) != null || + isUseOperator(value.property.identifier))) { + hasReactiveInput = true; + } + if (hasReactiveInput) { + for (const lvalue of eachInstructionLValue(instruction)) { + if (stableIdentifierSources.isStable(lvalue.identifier.id)) { + continue; + } + reactiveIdentifiers.markReactive(lvalue); + } + } + if (hasReactiveInput || hasReactiveControl) { + for (const operand of eachInstructionValueOperand(value)) { + switch (operand.effect) { + case Effect.Capture: + case Effect.Store: + case Effect.ConditionallyMutate: + case Effect.ConditionallyMutateIterator: + case Effect.Mutate: { + if (isMutable(instruction, operand)) { + reactiveIdentifiers.markReactive(operand); + } + break; + } + case Effect.Freeze: + case Effect.Read: { + break; + } + case Effect.Unknown: { + CompilerError.invariant(false, { + reason: 'Unexpected unknown effect', + description: null, + loc: operand.loc, + suggestions: null, + }); + } + default: { + assertExhaustive$1(operand.effect, `Unexpected effect kind \`${operand.effect}\``); + } + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + reactiveIdentifiers.isReactive(operand); + } + } + } while (reactiveIdentifiers.snapshot()); +} +function postDominatorFrontier(fn, postDominators, targetId) { + const visited = new Set(); + const frontier = new Set(); + const targetPostDominators = postDominatorsOf(fn, postDominators, targetId); + for (const blockId of [...targetPostDominators, targetId]) { + if (visited.has(blockId)) { + continue; + } + visited.add(blockId); + const block = fn.body.blocks.get(blockId); + for (const pred of block.preds) { + if (!targetPostDominators.has(pred)) { + frontier.add(pred); + } + } + } + return frontier; +} +function postDominatorsOf(fn, postDominators, targetId) { + var _a; + const result = new Set(); + const visited = new Set(); + const queue = [targetId]; + while (queue.length) { + const currentId = queue.shift(); + if (visited.has(currentId)) { + continue; + } + visited.add(currentId); + const current = fn.body.blocks.get(currentId); + for (const pred of current.preds) { + const predPostDominator = (_a = postDominators.get(pred)) !== null && _a !== void 0 ? _a : pred; + if (predPostDominator === targetId || result.has(predPostDominator)) { + result.add(pred); + } + queue.push(pred); + } + } + return result; +} +class ReactivityMap { + constructor(aliasedIdentifiers) { + this.hasChanges = false; + this.reactive = new Set(); + this.aliasedIdentifiers = aliasedIdentifiers; + } + isReactive(place) { + var _a; + const identifier = (_a = this.aliasedIdentifiers.find(place.identifier)) !== null && _a !== void 0 ? _a : place.identifier; + const reactive = this.reactive.has(identifier.id); + if (reactive) { + place.reactive = true; + } + return reactive; + } + markReactive(place) { + var _a; + place.reactive = true; + const identifier = (_a = this.aliasedIdentifiers.find(place.identifier)) !== null && _a !== void 0 ? _a : place.identifier; + if (!this.reactive.has(identifier.id)) { + this.hasChanges = true; + this.reactive.add(identifier.id); + } + } + snapshot() { + const hasChanges = this.hasChanges; + this.hasChanges = false; + return hasChanges; + } +} + +function inlineImmediatelyInvokedFunctionExpressions(fn) { + const functions = new Map(); + const inlinedFunctions = new Set(); + const queue = Array.from(fn.body.blocks.values()); + queue: for (const block of queue) { + for (let ii = 0; ii < block.instructions.length; ii++) { + const instr = block.instructions[ii]; + switch (instr.value.kind) { + case 'FunctionExpression': { + if (instr.lvalue.identifier.name === null) { + functions.set(instr.lvalue.identifier.id, instr.value); + } + break; + } + case 'CallExpression': { + if (instr.value.args.length !== 0) { + continue; + } + const body = functions.get(instr.value.callee.identifier.id); + if (body === undefined) { + continue; + } + if (body.loweredFunc.func.params.length > 0 || + body.loweredFunc.func.async || + body.loweredFunc.func.generator) { + continue; + } + inlinedFunctions.add(instr.value.callee.identifier.id); + const continuationBlockId = fn.env.nextBlockId; + const continuationBlock = { + id: continuationBlockId, + instructions: block.instructions.slice(ii + 1), + kind: block.kind, + phis: new Set(), + preds: new Set(), + terminal: block.terminal, + }; + fn.body.blocks.set(continuationBlockId, continuationBlock); + block.instructions.length = ii; + const newTerminal = { + block: body.loweredFunc.func.body.entry, + id: makeInstructionId(0), + kind: 'label', + fallthrough: continuationBlockId, + loc: block.terminal.loc, + }; + block.terminal = newTerminal; + const result = instr.lvalue; + declareTemporary(fn.env, block, result); + promoteTemporary(result.identifier); + for (const [id, block] of body.loweredFunc.func.body.blocks) { + block.preds.clear(); + rewriteBlock(fn.env, block, continuationBlockId, result); + fn.body.blocks.set(id, block); + } + queue.push(continuationBlock); + continue queue; + } + default: { + for (const place of eachInstructionValueOperand(instr.value)) { + functions.delete(place.identifier.id); + } + } + } + } + } + if (inlinedFunctions.size !== 0) { + for (const [, block] of fn.body.blocks) { + retainWhere(block.instructions, instr => !inlinedFunctions.has(instr.lvalue.identifier.id)); + } + reversePostorderBlocks(fn.body); + markInstructionIds(fn.body); + markPredecessors(fn.body); + } +} +function rewriteBlock(env, block, returnTarget, returnValue) { + const { terminal } = block; + if (terminal.kind !== 'return') { + return; + } + block.instructions.push({ + id: makeInstructionId(0), + loc: terminal.loc, + lvalue: createTemporaryPlace(env, terminal.loc), + value: { + kind: 'StoreLocal', + lvalue: { kind: InstructionKind.Reassign, place: Object.assign({}, returnValue) }, + value: terminal.value, + type: null, + loc: terminal.loc, + }, + }); + block.terminal = { + kind: 'goto', + block: returnTarget, + id: makeInstructionId(0), + variant: GotoVariant.Break, + loc: block.terminal.loc, + }; +} +function declareTemporary(env, block, result) { + block.instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, result.loc), + value: { + kind: 'DeclareLocal', + lvalue: { + place: result, + kind: InstructionKind.Let, + }, + type: null, + loc: result.loc, + }, + }); +} + +function collectHoistablePropertyLoads(fn, temporaries, hoistableFromOptionals) { + const registry = new PropertyPathRegistry(); + const knownImmutableIdentifiers = new Set(); + if (fn.fnType === 'Component' || fn.fnType === 'Hook') { + for (const p of fn.params) { + if (p.kind === 'Identifier') { + knownImmutableIdentifiers.add(p.identifier.id); + } + } + } + return collectHoistablePropertyLoadsImpl(fn, { + temporaries, + knownImmutableIdentifiers, + hoistableFromOptionals, + registry, + nestedFnImmutableContext: null, + assumedInvokedFns: fn.env.config.enableTreatFunctionDepsAsConditional + ? new Set() + : getAssumedInvokedFunctions(fn), + }); +} +function collectHoistablePropertyLoadsInInnerFn(fnInstr, temporaries, hoistableFromOptionals) { + const fn = fnInstr.value.loweredFunc.func; + const initialContext = { + temporaries, + knownImmutableIdentifiers: new Set(), + hoistableFromOptionals, + registry: new PropertyPathRegistry(), + nestedFnImmutableContext: null, + assumedInvokedFns: fn.env.config.enableTreatFunctionDepsAsConditional + ? new Set() + : getAssumedInvokedFunctions(fn), + }; + const nestedFnImmutableContext = new Set(fn.context + .filter(place => isImmutableAtInstr(place.identifier, fnInstr.id, initialContext)) + .map(place => place.identifier.id)); + initialContext.nestedFnImmutableContext = nestedFnImmutableContext; + return collectHoistablePropertyLoadsImpl(fn, initialContext); +} +function collectHoistablePropertyLoadsImpl(fn, context) { + const nodes = collectNonNullsInBlocks(fn, context); + propagateNonNull(fn, nodes, context.registry); + return nodes; +} +function keyByScopeId(fn, source) { + const keyedByScopeId = new Map(); + for (const [_, block] of fn.body.blocks) { + if (block.terminal.kind === 'scope') { + keyedByScopeId.set(block.terminal.scope.id, source.get(block.terminal.block)); + } + } + return keyedByScopeId; +} +class PropertyPathRegistry { + constructor() { + this.roots = new Map(); + } + getOrCreateIdentifier(identifier) { + let rootNode = this.roots.get(identifier.id); + if (rootNode === undefined) { + rootNode = { + root: identifier.id, + properties: new Map(), + optionalProperties: new Map(), + fullPath: { + identifier, + path: [], + }, + hasOptional: false, + parent: null, + }; + this.roots.set(identifier.id, rootNode); + } + return rootNode; + } + static getOrCreatePropertyEntry(parent, entry) { + const map = entry.optional ? parent.optionalProperties : parent.properties; + let child = map.get(entry.property); + if (child == null) { + child = { + properties: new Map(), + optionalProperties: new Map(), + parent: parent, + fullPath: { + identifier: parent.fullPath.identifier, + path: parent.fullPath.path.concat(entry), + }, + hasOptional: parent.hasOptional || entry.optional, + }; + map.set(entry.property, child); + } + return child; + } + getOrCreateProperty(n) { + let currNode = this.getOrCreateIdentifier(n.identifier); + if (n.path.length === 0) { + return currNode; + } + for (let i = 0; i < n.path.length - 1; i++) { + currNode = PropertyPathRegistry.getOrCreatePropertyEntry(currNode, n.path[i]); + } + return PropertyPathRegistry.getOrCreatePropertyEntry(currNode, n.path.at(-1)); + } +} +function getMaybeNonNullInInstruction(instr, context) { + var _a, _b, _c; + let path = null; + if (instr.kind === 'PropertyLoad') { + path = (_a = context.temporaries.get(instr.object.identifier.id)) !== null && _a !== void 0 ? _a : { + identifier: instr.object.identifier, + path: [], + }; + } + else if (instr.kind === 'Destructure') { + path = (_b = context.temporaries.get(instr.value.identifier.id)) !== null && _b !== void 0 ? _b : null; + } + else if (instr.kind === 'ComputedLoad') { + path = (_c = context.temporaries.get(instr.object.identifier.id)) !== null && _c !== void 0 ? _c : null; + } + return path != null ? context.registry.getOrCreateProperty(path) : null; +} +function isImmutableAtInstr(identifier, instr, context) { + if (context.nestedFnImmutableContext != null) { + return context.nestedFnImmutableContext.has(identifier.id); + } + else { + const mutableAtInstr = identifier.mutableRange.end > identifier.mutableRange.start + 1 && + identifier.scope != null && + inRange({ + id: instr, + }, identifier.scope.range); + return (!mutableAtInstr || context.knownImmutableIdentifiers.has(identifier.id)); + } +} +function collectNonNullsInBlocks(fn, context) { + var _a; + const knownNonNullIdentifiers = new Set(); + if (fn.fnType === 'Component' && + fn.params.length > 0 && + fn.params[0].kind === 'Identifier') { + const identifier = fn.params[0].identifier; + knownNonNullIdentifiers.add(context.registry.getOrCreateIdentifier(identifier)); + } + const nodes = new Map(); + for (const [_, block] of fn.body.blocks) { + const assumedNonNullObjects = new Set(knownNonNullIdentifiers); + const maybeOptionalChain = context.hoistableFromOptionals.get(block.id); + if (maybeOptionalChain != null) { + assumedNonNullObjects.add(context.registry.getOrCreateProperty(maybeOptionalChain)); + } + for (const instr of block.instructions) { + const maybeNonNull = getMaybeNonNullInInstruction(instr.value, context); + if (maybeNonNull != null && + isImmutableAtInstr(maybeNonNull.fullPath.identifier, instr.id, context)) { + assumedNonNullObjects.add(maybeNonNull); + } + if (instr.value.kind === 'FunctionExpression') { + const innerFn = instr.value.loweredFunc; + if (context.assumedInvokedFns.has(innerFn)) { + const innerHoistableMap = collectHoistablePropertyLoadsImpl(innerFn.func, Object.assign(Object.assign({}, context), { nestedFnImmutableContext: (_a = context.nestedFnImmutableContext) !== null && _a !== void 0 ? _a : new Set(innerFn.func.context + .filter(place => isImmutableAtInstr(place.identifier, instr.id, context)) + .map(place => place.identifier.id)) })); + const innerHoistables = assertNonNull(innerHoistableMap.get(innerFn.func.body.entry)); + for (const entry of innerHoistables.assumedNonNullObjects) { + assumedNonNullObjects.add(entry); + } + } + } + } + nodes.set(block.id, { + block, + assumedNonNullObjects, + }); + } + return nodes; +} +function propagateNonNull(fn, nodes, registry) { + const blockSuccessors = new Map(); + const terminalPreds = new Set(); + for (const [blockId, block] of fn.body.blocks) { + for (const pred of block.preds) { + getOrInsertDefault(blockSuccessors, pred, new Set()).add(blockId); + } + if (block.terminal.kind === 'throw' || block.terminal.kind === 'return') { + terminalPreds.add(blockId); + } + } + function recursivelyPropagateNonNull(nodeId, direction, traversalState) { + var _a; + if (traversalState.has(nodeId)) { + return false; + } + traversalState.set(nodeId, 'active'); + const node = nodes.get(nodeId); + if (node == null) { + CompilerError.invariant(false, { + reason: `Bad node ${nodeId}, kind: ${direction}`, + loc: GeneratedSource, + }); + } + const neighbors = Array.from(direction === 'backward' + ? ((_a = blockSuccessors.get(nodeId)) !== null && _a !== void 0 ? _a : []) + : node.block.preds); + let changed = false; + for (const pred of neighbors) { + if (!traversalState.has(pred)) { + const neighborChanged = recursivelyPropagateNonNull(pred, direction, traversalState); + changed || (changed = neighborChanged); + } + } + const neighborAccesses = Set_intersect(Array.from(neighbors) + .filter(n => traversalState.get(n) === 'done') + .map(n => assertNonNull(nodes.get(n)).assumedNonNullObjects)); + const prevObjects = assertNonNull(nodes.get(nodeId)).assumedNonNullObjects; + const mergedObjects = Set_union(prevObjects, neighborAccesses); + reduceMaybeOptionalChains(mergedObjects, registry); + assertNonNull(nodes.get(nodeId)).assumedNonNullObjects = mergedObjects; + traversalState.set(nodeId, 'done'); + changed || (changed = !Set_equal(prevObjects, mergedObjects)); + return changed; + } + const traversalState = new Map(); + const reversedBlocks = [...fn.body.blocks]; + reversedBlocks.reverse(); + let changed; + let i = 0; + do { + CompilerError.invariant(i++ < 100, { + reason: '[CollectHoistablePropertyLoads] fixed point iteration did not terminate after 100 loops', + loc: GeneratedSource, + }); + changed = false; + for (const [blockId] of fn.body.blocks) { + const forwardChanged = recursivelyPropagateNonNull(blockId, 'forward', traversalState); + changed || (changed = forwardChanged); + } + traversalState.clear(); + for (const [blockId] of reversedBlocks) { + const backwardChanged = recursivelyPropagateNonNull(blockId, 'backward', traversalState); + changed || (changed = backwardChanged); + } + traversalState.clear(); + } while (changed); +} +function assertNonNull(value, source) { + CompilerError.invariant(value != null, { + reason: 'Unexpected null', + description: source != null ? `(from ${source})` : null, + loc: GeneratedSource, + }); + return value; +} +function reduceMaybeOptionalChains(nodes, registry) { + let optionalChainNodes = Set_filter(nodes, n => n.hasOptional); + if (optionalChainNodes.size === 0) { + return; + } + let changed; + do { + changed = false; + for (const original of optionalChainNodes) { + let { identifier, path: origPath } = original.fullPath; + let currNode = registry.getOrCreateIdentifier(identifier); + for (let i = 0; i < origPath.length; i++) { + const entry = origPath[i]; + const nextEntry = entry.optional && nodes.has(currNode) + ? { property: entry.property, optional: false } + : entry; + currNode = PropertyPathRegistry.getOrCreatePropertyEntry(currNode, nextEntry); + } + if (currNode !== original) { + changed = true; + optionalChainNodes.delete(original); + optionalChainNodes.add(currNode); + nodes.delete(original); + nodes.add(currNode); + } + } + } while (changed); +} +function getAssumedInvokedFunctions(fn, temporaries = new Map()) { + var _a; + const hoistableFunctions = new Set(); + for (const block of fn.body.blocks.values()) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'FunctionExpression') { + temporaries.set(lvalue.identifier.id, { + fn: value.loweredFunc, + mayInvoke: new Set(), + }); + } + else if (value.kind === 'StoreLocal') { + const lvalue = value.lvalue.place.identifier; + const maybeLoweredFunc = temporaries.get(value.value.identifier.id); + if (maybeLoweredFunc != null) { + temporaries.set(lvalue.id, maybeLoweredFunc); + } + } + else if (value.kind === 'LoadLocal') { + const maybeLoweredFunc = temporaries.get(value.place.identifier.id); + if (maybeLoweredFunc != null) { + temporaries.set(lvalue.identifier.id, maybeLoweredFunc); + } + } + } + } + for (const block of fn.body.blocks.values()) { + for (const { lvalue, value } of block.instructions) { + if (value.kind === 'CallExpression') { + const callee = value.callee; + const maybeHook = getHookKind(fn.env, callee.identifier); + const maybeLoweredFunc = temporaries.get(callee.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + else if (maybeHook != null) { + for (const arg of value.args) { + if (arg.kind === 'Identifier') { + const maybeLoweredFunc = temporaries.get(arg.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + } + } + else if (value.kind === 'JsxExpression') { + for (const attr of value.props) { + if (attr.kind === 'JsxSpreadAttribute') { + continue; + } + const maybeLoweredFunc = temporaries.get(attr.place.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + for (const child of (_a = value.children) !== null && _a !== void 0 ? _a : []) { + const maybeLoweredFunc = temporaries.get(child.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + else if (value.kind === 'FunctionExpression') { + const loweredFunc = value.loweredFunc.func; + const lambdasCalled = getAssumedInvokedFunctions(loweredFunc, temporaries); + const maybeLoweredFunc = temporaries.get(lvalue.identifier.id); + if (maybeLoweredFunc != null) { + for (const called of lambdasCalled) { + maybeLoweredFunc.mayInvoke.add(called); + } + } + } + } + if (block.terminal.kind === 'return') { + const maybeLoweredFunc = temporaries.get(block.terminal.value.identifier.id); + if (maybeLoweredFunc != null) { + hoistableFunctions.add(maybeLoweredFunc.fn); + } + } + } + for (const [_, { fn, mayInvoke }] of temporaries) { + if (hoistableFunctions.has(fn)) { + for (const called of mayInvoke) { + hoistableFunctions.add(called); + } + } + } + return hoistableFunctions; +} + +function collectOptionalChainSidemap(fn) { + const context = { + currFn: fn, + blocks: fn.body.blocks, + seenOptionals: new Set(), + processedInstrsInOptional: new Set(), + temporariesReadInOptional: new Map(), + hoistableObjects: new Map(), + }; + traverseFunction(fn, context); + return { + temporariesReadInOptional: context.temporariesReadInOptional, + processedInstrsInOptional: context.processedInstrsInOptional, + hoistableObjects: context.hoistableObjects, + }; +} +function traverseFunction(fn, context) { + for (const [_, block] of fn.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + traverseFunction(instr.value.loweredFunc.func, Object.assign(Object.assign({}, context), { currFn: instr.value.loweredFunc.func, blocks: instr.value.loweredFunc.func.body.blocks })); + } + } + if (block.terminal.kind === 'optional' && + !context.seenOptionals.has(block.id)) { + traverseOptionalBlock(block, context, null); + } + } +} +function matchOptionalTestBlock(terminal, blocks) { + const consequentBlock = assertNonNull(blocks.get(terminal.consequent)); + if (consequentBlock.instructions.length === 2 && + consequentBlock.instructions[0].value.kind === 'PropertyLoad' && + consequentBlock.instructions[1].value.kind === 'StoreLocal') { + const propertyLoad = consequentBlock + .instructions[0]; + const storeLocal = consequentBlock.instructions[1].value; + const storeLocalInstr = consequentBlock.instructions[1]; + CompilerError.invariant(propertyLoad.value.object.identifier.id === terminal.test.identifier.id, { + reason: '[OptionalChainDeps] Inconsistent optional chaining property load', + description: `Test=${printIdentifier(terminal.test.identifier)} PropertyLoad base=${printIdentifier(propertyLoad.value.object.identifier)}`, + loc: propertyLoad.loc, + }); + CompilerError.invariant(storeLocal.value.identifier.id === propertyLoad.lvalue.identifier.id, { + reason: '[OptionalChainDeps] Unexpected storeLocal', + loc: propertyLoad.loc, + }); + if (consequentBlock.terminal.kind !== 'goto' || + consequentBlock.terminal.variant !== GotoVariant.Break) { + return null; + } + const alternate = assertNonNull(blocks.get(terminal.alternate)); + CompilerError.invariant(alternate.instructions.length === 2 && + alternate.instructions[0].value.kind === 'Primitive' && + alternate.instructions[1].value.kind === 'StoreLocal', { + reason: 'Unexpected alternate structure', + loc: terminal.loc, + }); + return { + consequentId: storeLocal.lvalue.place.identifier.id, + property: propertyLoad.value.property, + propertyId: propertyLoad.lvalue.identifier.id, + storeLocalInstr, + consequentGoto: consequentBlock.terminal.block, + }; + } + return null; +} +function traverseOptionalBlock(optional, context, outerAlternate) { + context.seenOptionals.add(optional.id); + const maybeTest = context.blocks.get(optional.terminal.test); + let test; + let baseObject; + if (maybeTest.terminal.kind === 'branch') { + CompilerError.invariant(optional.terminal.optional, { + reason: '[OptionalChainDeps] Expect base case to be always optional', + loc: optional.terminal.loc, + }); + if (maybeTest.instructions.length === 0 || + maybeTest.instructions[0].value.kind !== 'LoadLocal') { + return null; + } + const path = []; + for (let i = 1; i < maybeTest.instructions.length; i++) { + const instrVal = maybeTest.instructions[i].value; + const prevInstr = maybeTest.instructions[i - 1]; + if (instrVal.kind === 'PropertyLoad' && + instrVal.object.identifier.id === prevInstr.lvalue.identifier.id) { + path.push({ property: instrVal.property, optional: false }); + } + else { + return null; + } + } + CompilerError.invariant(maybeTest.terminal.test.identifier.id === + maybeTest.instructions.at(-1).lvalue.identifier.id, { + reason: '[OptionalChainDeps] Unexpected test expression', + loc: maybeTest.terminal.loc, + }); + baseObject = { + identifier: maybeTest.instructions[0].value.place.identifier, + path, + }; + test = maybeTest.terminal; + } + else if (maybeTest.terminal.kind === 'optional') { + const testBlock = context.blocks.get(maybeTest.terminal.fallthrough); + if (testBlock.terminal.kind !== 'branch') { + CompilerError.throwTodo({ + reason: `Unexpected terminal kind \`${testBlock.terminal.kind}\` for optional fallthrough block`, + loc: maybeTest.terminal.loc, + }); + } + const innerOptional = traverseOptionalBlock(maybeTest, context, testBlock.terminal.alternate); + if (innerOptional == null) { + return null; + } + if (testBlock.terminal.test.identifier.id !== innerOptional) { + return null; + } + if (!optional.terminal.optional) { + context.hoistableObjects.set(optional.id, assertNonNull(context.temporariesReadInOptional.get(innerOptional))); + } + baseObject = assertNonNull(context.temporariesReadInOptional.get(innerOptional)); + test = testBlock.terminal; + } + else { + return null; + } + if (test.alternate === outerAlternate) { + CompilerError.invariant(optional.instructions.length === 0, { + reason: '[OptionalChainDeps] Unexpected instructions an inner optional block. ' + + 'This indicates that the compiler may be incorrectly concatenating two unrelated optional chains', + loc: optional.terminal.loc, + }); + } + const matchConsequentResult = matchOptionalTestBlock(test, context.blocks); + if (!matchConsequentResult) { + return null; + } + CompilerError.invariant(matchConsequentResult.consequentGoto === optional.terminal.fallthrough, { + reason: '[OptionalChainDeps] Unexpected optional goto-fallthrough', + description: `${matchConsequentResult.consequentGoto} != ${optional.terminal.fallthrough}`, + loc: optional.terminal.loc, + }); + const load = { + identifier: baseObject.identifier, + path: [ + ...baseObject.path, + { + property: matchConsequentResult.property, + optional: optional.terminal.optional, + }, + ], + }; + context.processedInstrsInOptional.add(matchConsequentResult.storeLocalInstr); + context.processedInstrsInOptional.add(test); + context.temporariesReadInOptional.set(matchConsequentResult.consequentId, load); + context.temporariesReadInOptional.set(matchConsequentResult.propertyId, load); + return matchConsequentResult.consequentId; +} + +var _a, _ReactiveScopeDependencyTreeHIR_hoistableObjects, _ReactiveScopeDependencyTreeHIR_deps, _ReactiveScopeDependencyTreeHIR_getOrCreateRoot, _ReactiveScopeDependencyTreeHIR_debugImpl; +class ReactiveScopeDependencyTreeHIR { + constructor(hoistableObjects) { + var _b; + _ReactiveScopeDependencyTreeHIR_hoistableObjects.set(this, new Map()); + _ReactiveScopeDependencyTreeHIR_deps.set(this, new Map()); + for (const { path, identifier } of hoistableObjects) { + let currNode = __classPrivateFieldGet(_a, _a, "m", _ReactiveScopeDependencyTreeHIR_getOrCreateRoot).call(_a, identifier, __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_hoistableObjects, "f"), path.length > 0 && path[0].optional ? 'Optional' : 'NonNull'); + for (let i = 0; i < path.length; i++) { + const prevAccessType = (_b = currNode.properties.get(path[i].property)) === null || _b === void 0 ? void 0 : _b.accessType; + const accessType = i + 1 < path.length && path[i + 1].optional ? 'Optional' : 'NonNull'; + CompilerError.invariant(prevAccessType == null || prevAccessType === accessType, { + reason: 'Conflicting access types', + loc: GeneratedSource, + }); + let nextNode = currNode.properties.get(path[i].property); + if (nextNode == null) { + nextNode = { + properties: new Map(), + accessType, + }; + currNode.properties.set(path[i].property, nextNode); + } + currNode = nextNode; + } + } + } + addDependency(dep) { + const { identifier, path } = dep; + let depCursor = __classPrivateFieldGet(_a, _a, "m", _ReactiveScopeDependencyTreeHIR_getOrCreateRoot).call(_a, identifier, __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f"), PropertyAccessType.UnconditionalAccess); + let hoistableCursor = __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_hoistableObjects, "f").get(identifier); + for (const entry of path) { + let nextHoistableCursor; + let nextDepCursor; + if (entry.optional) { + if (hoistableCursor != null) { + nextHoistableCursor = hoistableCursor === null || hoistableCursor === void 0 ? void 0 : hoistableCursor.properties.get(entry.property); + } + let accessType; + if (hoistableCursor != null && + hoistableCursor.accessType === 'NonNull') { + accessType = PropertyAccessType.UnconditionalAccess; + } + else { + accessType = PropertyAccessType.OptionalAccess; + } + nextDepCursor = makeOrMergeProperty(depCursor, entry.property, accessType); + } + else if (hoistableCursor != null && + hoistableCursor.accessType === 'NonNull') { + nextHoistableCursor = hoistableCursor.properties.get(entry.property); + nextDepCursor = makeOrMergeProperty(depCursor, entry.property, PropertyAccessType.UnconditionalAccess); + } + else { + break; + } + depCursor = nextDepCursor; + hoistableCursor = nextHoistableCursor; + } + depCursor.accessType = merge(depCursor.accessType, PropertyAccessType.OptionalDependency); + } + deriveMinimalDependencies() { + const results = new Set(); + for (const [rootId, rootNode] of __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f").entries()) { + collectMinimalDependenciesInSubtree(rootNode, rootId, [], results); + } + return results; + } + printDeps(includeAccesses) { + let res = []; + for (const [rootId, rootNode] of __classPrivateFieldGet(this, _ReactiveScopeDependencyTreeHIR_deps, "f").entries()) { + const rootResults = printSubtree(rootNode, includeAccesses).map(result => `${printIdentifier(rootId)}.${result}`); + res.push(rootResults); + } + return res.flat().join('\n'); + } + static debug(roots) { + const buf = [`tree() [`]; + for (const [rootId, rootNode] of roots) { + buf.push(`${printIdentifier(rootId)} (${rootNode.accessType}):`); + __classPrivateFieldGet(this, _a, "m", _ReactiveScopeDependencyTreeHIR_debugImpl).call(this, buf, rootNode, 1); + } + buf.push(']'); + return buf.length > 2 ? buf.join('\n') : buf.join(''); + } +} +_a = ReactiveScopeDependencyTreeHIR, _ReactiveScopeDependencyTreeHIR_hoistableObjects = new WeakMap(), _ReactiveScopeDependencyTreeHIR_deps = new WeakMap(), _ReactiveScopeDependencyTreeHIR_getOrCreateRoot = function _ReactiveScopeDependencyTreeHIR_getOrCreateRoot(identifier, roots, defaultAccessType) { + let rootNode = roots.get(identifier); + if (rootNode === undefined) { + rootNode = { + properties: new Map(), + accessType: defaultAccessType, + }; + roots.set(identifier, rootNode); + } + return rootNode; +}, _ReactiveScopeDependencyTreeHIR_debugImpl = function _ReactiveScopeDependencyTreeHIR_debugImpl(buf, node, depth = 0) { + for (const [property, childNode] of node.properties) { + buf.push(`${' '.repeat(depth)}.${property} (${childNode.accessType}):`); + __classPrivateFieldGet(this, _a, "m", _ReactiveScopeDependencyTreeHIR_debugImpl).call(this, buf, childNode, depth + 1); + } +}; +var PropertyAccessType; +(function (PropertyAccessType) { + PropertyAccessType["OptionalAccess"] = "OptionalAccess"; + PropertyAccessType["UnconditionalAccess"] = "UnconditionalAccess"; + PropertyAccessType["OptionalDependency"] = "OptionalDependency"; + PropertyAccessType["UnconditionalDependency"] = "UnconditionalDependency"; +})(PropertyAccessType || (PropertyAccessType = {})); +function isOptional(access) { + return (access === PropertyAccessType.OptionalAccess || + access === PropertyAccessType.OptionalDependency); +} +function isDependency(access) { + return (access === PropertyAccessType.OptionalDependency || + access === PropertyAccessType.UnconditionalDependency); +} +function merge(access1, access2) { + const resultIsUnconditional = !(isOptional(access1) && isOptional(access2)); + const resultIsDependency = isDependency(access1) || isDependency(access2); + if (resultIsUnconditional) { + if (resultIsDependency) { + return PropertyAccessType.UnconditionalDependency; + } + else { + return PropertyAccessType.UnconditionalAccess; + } + } + else { + if (resultIsDependency) { + return PropertyAccessType.OptionalDependency; + } + else { + return PropertyAccessType.OptionalAccess; + } + } +} +function collectMinimalDependenciesInSubtree(node, rootIdentifier, path, results) { + if (isDependency(node.accessType)) { + results.add({ identifier: rootIdentifier, path }); + } + else { + for (const [childName, childNode] of node.properties) { + collectMinimalDependenciesInSubtree(childNode, rootIdentifier, [ + ...path, + { + property: childName, + optional: isOptional(childNode.accessType), + }, + ], results); + } + } +} +function printSubtree(node, includeAccesses) { + const results = []; + for (const [propertyName, propertyNode] of node.properties) { + if (includeAccesses || isDependency(propertyNode.accessType)) { + results.push(`${propertyName} (${propertyNode.accessType})`); + } + const propertyResults = printSubtree(propertyNode, includeAccesses); + results.push(...propertyResults.map(result => `${propertyName}.${result}`)); + } + return results; +} +function makeOrMergeProperty(node, property, accessType) { + let child = node.properties.get(property); + if (child == null) { + child = { + properties: new Map(), + accessType, + }; + node.properties.set(property, child); + } + else { + child.accessType = merge(child.accessType, accessType); + } + return child; +} + +var _DependencyCollectionContext_instances, _DependencyCollectionContext_declarations, _DependencyCollectionContext_reassignments, _DependencyCollectionContext_scopes, _DependencyCollectionContext_dependencies, _DependencyCollectionContext_temporaries, _DependencyCollectionContext_temporariesUsedOutsideScope, _DependencyCollectionContext_processedInstrsInOptional, _DependencyCollectionContext_innerFnContext, _DependencyCollectionContext_checkValidDependency, _DependencyCollectionContext_isScopeActive; +function propagateScopeDependenciesHIR(fn) { + const usedOutsideDeclaringScope = findTemporariesUsedOutsideDeclaringScope(fn); + const temporaries = collectTemporariesSidemap(fn, usedOutsideDeclaringScope); + const { temporariesReadInOptional, processedInstrsInOptional, hoistableObjects, } = collectOptionalChainSidemap(fn); + const hoistablePropertyLoads = keyByScopeId(fn, collectHoistablePropertyLoads(fn, temporaries, hoistableObjects)); + const scopeDeps = collectDependencies(fn, usedOutsideDeclaringScope, new Map([...temporaries, ...temporariesReadInOptional]), processedInstrsInOptional); + for (const [scope, deps] of scopeDeps) { + if (deps.length === 0) { + continue; + } + const hoistables = hoistablePropertyLoads.get(scope.id); + CompilerError.invariant(hoistables != null, { + reason: '[PropagateScopeDependencies] Scope not found in tracked blocks', + loc: GeneratedSource, + }); + const tree = new ReactiveScopeDependencyTreeHIR([...hoistables.assumedNonNullObjects].map(o => o.fullPath)); + for (const dep of deps) { + tree.addDependency(Object.assign({}, dep)); + } + const candidates = tree.deriveMinimalDependencies(); + for (const candidateDep of candidates) { + if (!Iterable_some(scope.dependencies, existingDep => existingDep.identifier.declarationId === + candidateDep.identifier.declarationId && + areEqualPaths(existingDep.path, candidateDep.path))) + scope.dependencies.add(candidateDep); + } + } +} +function findTemporariesUsedOutsideDeclaringScope(fn) { + const declarations = new Map(); + const prunedScopes = new Set(); + const scopeTraversal = new ScopeBlockTraversal(); + const usedOutsideDeclaringScope = new Set(); + function handlePlace(place) { + const declaringScope = declarations.get(place.identifier.declarationId); + if (declaringScope != null && + !scopeTraversal.isScopeActive(declaringScope) && + !prunedScopes.has(declaringScope)) { + usedOutsideDeclaringScope.add(place.identifier.declarationId); + } + } + function handleInstruction(instr) { + const scope = scopeTraversal.currentScope; + if (scope == null || prunedScopes.has(scope)) { + return; + } + switch (instr.value.kind) { + case 'LoadLocal': + case 'LoadContext': + case 'PropertyLoad': { + declarations.set(instr.lvalue.identifier.declarationId, scope); + break; + } + } + } + for (const [blockId, block] of fn.body.blocks) { + scopeTraversal.recordScopes(block); + const scopeStartInfo = scopeTraversal.blockInfos.get(blockId); + if ((scopeStartInfo === null || scopeStartInfo === void 0 ? void 0 : scopeStartInfo.kind) === 'begin' && scopeStartInfo.pruned) { + prunedScopes.add(scopeStartInfo.scope.id); + } + for (const instr of block.instructions) { + for (const place of eachInstructionOperand(instr)) { + handlePlace(place); + } + handleInstruction(instr); + } + for (const place of eachTerminalOperand(block.terminal)) { + handlePlace(place); + } + } + return usedOutsideDeclaringScope; +} +function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) { + const temporaries = new Map(); + collectTemporariesSidemapImpl(fn, usedOutsideDeclaringScope, temporaries, null); + return temporaries; +} +function isLoadContextMutable(instrValue, id) { + if (instrValue.kind === 'LoadContext') { + return (instrValue.place.identifier.scope != null && + id >= instrValue.place.identifier.scope.range.end); + } + return false; +} +function collectTemporariesSidemapImpl(fn, usedOutsideDeclaringScope, temporaries, innerFnContext) { + for (const [_, block] of fn.body.blocks) { + for (const { value, lvalue, id: origInstrId } of block.instructions) { + const instrId = innerFnContext != null ? innerFnContext.instrId : origInstrId; + const usedOutside = usedOutsideDeclaringScope.has(lvalue.identifier.declarationId); + if (value.kind === 'PropertyLoad' && !usedOutside) { + if (innerFnContext == null || + temporaries.has(value.object.identifier.id)) { + const property = getProperty(value.object, value.property, false, temporaries); + temporaries.set(lvalue.identifier.id, property); + } + } + else if ((value.kind === 'LoadLocal' || isLoadContextMutable(value, instrId)) && + lvalue.identifier.name == null && + value.place.identifier.name !== null && + !usedOutside) { + if (innerFnContext == null || + fn.context.some(context => context.identifier.id === value.place.identifier.id)) { + temporaries.set(lvalue.identifier.id, { + identifier: value.place.identifier, + path: [], + }); + } + } + else if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + collectTemporariesSidemapImpl(value.loweredFunc.func, usedOutsideDeclaringScope, temporaries, innerFnContext !== null && innerFnContext !== void 0 ? innerFnContext : { instrId }); + } + } + } +} +function getProperty(object, propertyName, optional, temporaries) { + const resolvedDependency = temporaries.get(object.identifier.id); + let property; + if (resolvedDependency == null) { + property = { + identifier: object.identifier, + path: [{ property: propertyName, optional }], + }; + } + else { + property = { + identifier: resolvedDependency.identifier, + path: [...resolvedDependency.path, { property: propertyName, optional }], + }; + } + return property; +} +class DependencyCollectionContext { + constructor(temporariesUsedOutsideScope, temporaries, processedInstrsInOptional) { + _DependencyCollectionContext_instances.add(this); + _DependencyCollectionContext_declarations.set(this, new Map()); + _DependencyCollectionContext_reassignments.set(this, new Map()); + _DependencyCollectionContext_scopes.set(this, empty()); + _DependencyCollectionContext_dependencies.set(this, empty()); + this.deps = new Map(); + _DependencyCollectionContext_temporaries.set(this, void 0); + _DependencyCollectionContext_temporariesUsedOutsideScope.set(this, void 0); + _DependencyCollectionContext_processedInstrsInOptional.set(this, void 0); + _DependencyCollectionContext_innerFnContext.set(this, null); + __classPrivateFieldSet(this, _DependencyCollectionContext_temporariesUsedOutsideScope, temporariesUsedOutsideScope, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_temporaries, temporaries, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_processedInstrsInOptional, processedInstrsInOptional, "f"); + } + enterScope(scope) { + __classPrivateFieldSet(this, _DependencyCollectionContext_dependencies, __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").push([]), "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_scopes, __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").push(scope), "f"); + } + exitScope(scope, pruned) { + var _a; + const scopedDependencies = __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value; + CompilerError.invariant(scopedDependencies != null, { + reason: '[PropagateScopeDeps]: Unexpected scope mismatch', + loc: scope.loc, + }); + __classPrivateFieldSet(this, _DependencyCollectionContext_scopes, __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").pop(), "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_dependencies, __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").pop(), "f"); + for (const dep of scopedDependencies) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, dep)) { + (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value) === null || _a === void 0 ? void 0 : _a.push(dep); + } + } + if (!pruned) { + this.deps.set(scope, scopedDependencies); + } + } + isUsedOutsideDeclaringScope(place) { + return __classPrivateFieldGet(this, _DependencyCollectionContext_temporariesUsedOutsideScope, "f").has(place.identifier.declarationId); + } + declare(identifier, decl) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f") != null) + return; + if (!__classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").has(identifier.declarationId)) { + __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").set(identifier.declarationId, decl); + } + __classPrivateFieldGet(this, _DependencyCollectionContext_reassignments, "f").set(identifier, decl); + } + hasDeclared(identifier) { + return __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").has(identifier.declarationId); + } + get currentScope() { + return __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f"); + } + visitOperand(place) { + var _a; + this.visitDependency((_a = __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f").get(place.identifier.id)) !== null && _a !== void 0 ? _a : { + identifier: place.identifier, + path: [], + }); + } + visitProperty(object, property, optional) { + const nextDependency = getProperty(object, property, optional, __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f")); + this.visitDependency(nextDependency); + } + visitDependency(maybeDependency) { + var _a; + const originalDeclaration = __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").get(maybeDependency.identifier.declarationId); + if (originalDeclaration !== undefined && + originalDeclaration.scope.value !== null) { + originalDeclaration.scope.each(scope => { + if (!__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_isScopeActive).call(this, scope) && + !Iterable_some(scope.declarations.values(), decl => decl.identifier.declarationId === + maybeDependency.identifier.declarationId)) { + scope.declarations.set(maybeDependency.identifier.id, { + identifier: maybeDependency.identifier, + scope: originalDeclaration.scope.value, + }); + } + }); + } + if (isUseRefType(maybeDependency.identifier) && + ((_a = maybeDependency.path.at(0)) === null || _a === void 0 ? void 0 : _a.property) === 'current') { + maybeDependency = { + identifier: maybeDependency.identifier, + path: [], + }; + } + if (__classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, maybeDependency)) { + __classPrivateFieldGet(this, _DependencyCollectionContext_dependencies, "f").value.push(maybeDependency); + } + } + visitReassignment(place) { + const currentScope = this.currentScope.value; + if (currentScope != null && + !Iterable_some(currentScope.reassignments, identifier => identifier.declarationId === place.identifier.declarationId) && + __classPrivateFieldGet(this, _DependencyCollectionContext_instances, "m", _DependencyCollectionContext_checkValidDependency).call(this, { identifier: place.identifier, path: [] })) { + currentScope.reassignments.add(place.identifier); + } + } + enterInnerFn(innerFn, cb) { + var _a; + const prevContext = __classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f"); + __classPrivateFieldSet(this, _DependencyCollectionContext_innerFnContext, (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_innerFnContext, "f")) !== null && _a !== void 0 ? _a : { outerInstrId: innerFn.id }, "f"); + const result = cb(); + __classPrivateFieldSet(this, _DependencyCollectionContext_innerFnContext, prevContext, "f"); + return result; + } + isDeferredDependency(instr) { + return (__classPrivateFieldGet(this, _DependencyCollectionContext_processedInstrsInOptional, "f").has(instr.value) || + (instr.kind === HIRValue.Instruction && + __classPrivateFieldGet(this, _DependencyCollectionContext_temporaries, "f").has(instr.value.lvalue.identifier.id))); + } +} +_DependencyCollectionContext_declarations = new WeakMap(), _DependencyCollectionContext_reassignments = new WeakMap(), _DependencyCollectionContext_scopes = new WeakMap(), _DependencyCollectionContext_dependencies = new WeakMap(), _DependencyCollectionContext_temporaries = new WeakMap(), _DependencyCollectionContext_temporariesUsedOutsideScope = new WeakMap(), _DependencyCollectionContext_processedInstrsInOptional = new WeakMap(), _DependencyCollectionContext_innerFnContext = new WeakMap(), _DependencyCollectionContext_instances = new WeakSet(), _DependencyCollectionContext_checkValidDependency = function _DependencyCollectionContext_checkValidDependency(maybeDependency) { + var _a; + if (isRefValueType(maybeDependency.identifier)) { + return false; + } + if (isObjectMethodType(maybeDependency.identifier)) { + return false; + } + const identifier = maybeDependency.identifier; + const currentDeclaration = (_a = __classPrivateFieldGet(this, _DependencyCollectionContext_reassignments, "f").get(identifier)) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _DependencyCollectionContext_declarations, "f").get(identifier.declarationId); + const currentScope = this.currentScope.value; + return (currentScope != null && + currentDeclaration !== undefined && + currentDeclaration.id < currentScope.range.start); +}, _DependencyCollectionContext_isScopeActive = function _DependencyCollectionContext_isScopeActive(scope) { + if (__classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f") === null) { + return false; + } + return __classPrivateFieldGet(this, _DependencyCollectionContext_scopes, "f").find(state => state === scope); +}; +var HIRValue; +(function (HIRValue) { + HIRValue[HIRValue["Instruction"] = 1] = "Instruction"; + HIRValue[HIRValue["Terminal"] = 2] = "Terminal"; +})(HIRValue || (HIRValue = {})); +function handleInstruction(instr, context) { + const { id, value, lvalue } = instr; + context.declare(lvalue.identifier, { + id, + scope: context.currentScope, + }); + if (context.isDeferredDependency({ kind: HIRValue.Instruction, value: instr })) { + return; + } + if (value.kind === 'PropertyLoad') { + context.visitProperty(value.object, value.property, false); + } + else if (value.kind === 'StoreLocal') { + context.visitOperand(value.value); + if (value.lvalue.kind === InstructionKind.Reassign) { + context.visitReassignment(value.lvalue.place); + } + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + else if (value.kind === 'DeclareLocal' || value.kind === 'DeclareContext') { + if (convertHoistedLValueKind(value.lvalue.kind) === null) { + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + } + else if (value.kind === 'Destructure') { + context.visitOperand(value.value); + for (const place of eachPatternOperand(value.lvalue.pattern)) { + if (value.lvalue.kind === InstructionKind.Reassign) { + context.visitReassignment(place); + } + context.declare(place.identifier, { + id, + scope: context.currentScope, + }); + } + } + else if (value.kind === 'StoreContext') { + if (!context.hasDeclared(value.lvalue.place.identifier) || + value.lvalue.kind !== InstructionKind.Reassign) { + context.declare(value.lvalue.place.identifier, { + id, + scope: context.currentScope, + }); + } + for (const operand of eachInstructionValueOperand(value)) { + context.visitOperand(operand); + } + } + else { + for (const operand of eachInstructionValueOperand(value)) { + context.visitOperand(operand); + } + } +} +function collectDependencies(fn, usedOutsideDeclaringScope, temporaries, processedInstrsInOptional) { + const context = new DependencyCollectionContext(usedOutsideDeclaringScope, temporaries, processedInstrsInOptional); + for (const param of fn.params) { + if (param.kind === 'Identifier') { + context.declare(param.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + else { + context.declare(param.place.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + } + const scopeTraversal = new ScopeBlockTraversal(); + const handleFunction = (fn) => { + for (const [blockId, block] of fn.body.blocks) { + scopeTraversal.recordScopes(block); + const scopeBlockInfo = scopeTraversal.blockInfos.get(blockId); + if ((scopeBlockInfo === null || scopeBlockInfo === void 0 ? void 0 : scopeBlockInfo.kind) === 'begin') { + context.enterScope(scopeBlockInfo.scope); + } + else if ((scopeBlockInfo === null || scopeBlockInfo === void 0 ? void 0 : scopeBlockInfo.kind) === 'end') { + context.exitScope(scopeBlockInfo.scope, scopeBlockInfo.pruned); + } + for (const phi of block.phis) { + for (const operand of phi.operands) { + const maybeOptionalChain = temporaries.get(operand[1].identifier.id); + if (maybeOptionalChain) { + context.visitDependency(maybeOptionalChain); + } + } + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + context.declare(instr.lvalue.identifier, { + id: instr.id, + scope: context.currentScope, + }); + const innerFn = instr.value.loweredFunc.func; + context.enterInnerFn(instr, () => { + handleFunction(innerFn); + }); + } + else { + handleInstruction(instr, context); + } + } + if (!context.isDeferredDependency({ + kind: HIRValue.Terminal, + value: block.terminal, + })) { + for (const place of eachTerminalOperand(block.terminal)) { + context.visitOperand(place); + } + } + } + }; + handleFunction(fn); + return context.deps; +} + +function inferEffectDependencies(fn) { + var _a, _b; + let hasRewrite = false; + const fnExpressions = new Map(); + const autodepFnConfigs = new Map(); + for (const effectTarget of fn.env.config.inferEffectDependencies) { + const moduleTargets = getOrInsertWith(autodepFnConfigs, effectTarget.function.source, () => new Map()); + moduleTargets.set(effectTarget.function.importSpecifierName, effectTarget.numRequiredArgs); + } + const autodepFnLoads = new Map(); + const autodepModuleLoads = new Map(); + const scopeInfos = new Map(); + const loadGlobals = new Set(); + const reactiveIds = inferReactiveIdentifiers(fn); + for (const [, block] of fn.body.blocks) { + if (block.terminal.kind === 'scope') { + const scopeBlock = fn.body.blocks.get(block.terminal.block); + if (scopeBlock.instructions.length === 1 && + scopeBlock.terminal.kind === 'goto' && + scopeBlock.terminal.block === block.terminal.fallthrough) { + scopeInfos.set(block.terminal.scope.id, block.terminal.scope.dependencies); + } + } + const rewriteInstrs = new Map(); + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'FunctionExpression') { + fnExpressions.set(lvalue.identifier.id, instr); + } + else if (value.kind === 'PropertyLoad') { + if (typeof value.property === 'string' && + autodepModuleLoads.has(value.object.identifier.id)) { + const moduleTargets = autodepModuleLoads.get(value.object.identifier.id); + const propertyName = value.property; + const numRequiredArgs = moduleTargets.get(propertyName); + if (numRequiredArgs != null) { + autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs); + } + } + } + else if (value.kind === 'LoadGlobal') { + loadGlobals.add(lvalue.identifier.id); + if (value.binding.kind === 'ImportNamespace') { + const moduleTargets = autodepFnConfigs.get(value.binding.module); + if (moduleTargets != null) { + autodepModuleLoads.set(lvalue.identifier.id, moduleTargets); + } + } + if (value.binding.kind === 'ImportSpecifier' || + value.binding.kind === 'ImportDefault') { + const moduleTargets = autodepFnConfigs.get(value.binding.module); + if (moduleTargets != null) { + const importSpecifierName = value.binding.kind === 'ImportSpecifier' + ? value.binding.imported + : DEFAULT_EXPORT; + const numRequiredArgs = moduleTargets.get(importSpecifierName); + if (numRequiredArgs != null) { + autodepFnLoads.set(lvalue.identifier.id, numRequiredArgs); + } + } + } + } + else if (value.kind === 'CallExpression' || + value.kind === 'MethodCall') { + const callee = value.kind === 'CallExpression' ? value.callee : value.property; + if (value.args.length === autodepFnLoads.get(callee.identifier.id) && + value.args[0].kind === 'Identifier') { + const effectDeps = []; + const newInstructions = []; + const deps = { + kind: 'ArrayExpression', + elements: effectDeps, + loc: GeneratedSource, + }; + const depsPlace = createTemporaryPlace(fn.env, GeneratedSource); + depsPlace.effect = Effect.Read; + const fnExpr = fnExpressions.get(value.args[0].identifier.id); + if (fnExpr != null) { + const scopeInfo = fnExpr.lvalue.identifier.scope != null + ? scopeInfos.get(fnExpr.lvalue.identifier.scope.id) + : null; + let minimalDeps; + if (scopeInfo != null) { + minimalDeps = new Set(scopeInfo); + } + else { + minimalDeps = inferMinimalDependencies(fnExpr); + } + const usedDeps = []; + for (const dep of minimalDeps) { + if (((isUseRefType(dep.identifier) || + isSetStateType(dep.identifier)) && + !reactiveIds.has(dep.identifier.id)) || + isFireFunctionType(dep.identifier)) { + continue; + } + const { place, instructions } = writeDependencyToInstructions(dep, reactiveIds.has(dep.identifier.id), fn.env, fnExpr.loc); + newInstructions.push(...instructions); + effectDeps.push(place); + usedDeps.push(dep); + } + const decorations = []; + for (const loc of collectDepUsages(usedDeps, fnExpr.value)) { + if (typeof loc === 'symbol') { + continue; + } + decorations.push(loc); + } + if (typeof value.loc !== 'symbol') { + (_a = fn.env.logger) === null || _a === void 0 ? void 0 : _a.logEvent(fn.env.filename, { + kind: 'AutoDepsDecorations', + fnLoc: value.loc, + decorations, + }); + } + newInstructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, depsPlace), { effect: Effect.Mutate }), + value: deps, + }); + value.args.push(Object.assign(Object.assign({}, depsPlace), { effect: Effect.Freeze })); + rewriteInstrs.set(instr.id, newInstructions); + fn.env.inferredEffectLocations.add(callee.loc); + } + else if (loadGlobals.has(value.args[0].identifier.id)) { + newInstructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, depsPlace), { effect: Effect.Mutate }), + value: deps, + }); + value.args.push(Object.assign(Object.assign({}, depsPlace), { effect: Effect.Freeze })); + rewriteInstrs.set(instr.id, newInstructions); + fn.env.inferredEffectLocations.add(callee.loc); + } + } + else if (value.args.length >= 2 && + value.args.length - 1 === autodepFnLoads.get(callee.identifier.id) && + value.args[0] != null && + value.args[0].kind === 'Identifier') { + const penultimateArg = value.args[value.args.length - 2]; + const depArrayArg = value.args[value.args.length - 1]; + if (depArrayArg.kind !== 'Spread' && + penultimateArg.kind !== 'Spread' && + typeof depArrayArg.loc !== 'symbol' && + typeof penultimateArg.loc !== 'symbol' && + typeof value.loc !== 'symbol') { + (_b = fn.env.logger) === null || _b === void 0 ? void 0 : _b.logEvent(fn.env.filename, { + kind: 'AutoDepsEligible', + fnLoc: value.loc, + depArrayLoc: Object.assign(Object.assign({}, depArrayArg.loc), { start: penultimateArg.loc.end, end: depArrayArg.loc.end }), + }); + } + } + } + } + if (rewriteInstrs.size > 0) { + hasRewrite = true; + const newInstrs = []; + for (const instr of block.instructions) { + const newInstr = rewriteInstrs.get(instr.id); + if (newInstr != null) { + newInstrs.push(...newInstr, instr); + } + else { + newInstrs.push(instr); + } + } + block.instructions = newInstrs; + } + } + if (hasRewrite) { + markInstructionIds(fn.body); + fixScopeAndIdentifierRanges(fn.body); + fn.env.hasInferredEffect = true; + } +} +function writeDependencyToInstructions(dep, reactive, env, loc) { + const instructions = []; + let currValue = createTemporaryPlace(env, GeneratedSource); + currValue.reactive = reactive; + instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, currValue), { effect: Effect.Mutate }), + value: { + kind: 'LoadLocal', + place: { + kind: 'Identifier', + identifier: dep.identifier, + effect: Effect.Capture, + reactive, + loc: loc, + }, + loc: loc, + }, + }); + for (const path of dep.path) { + if (path.optional) { + break; + } + if (path.property === 'current') { + break; + } + const nextValue = createTemporaryPlace(env, GeneratedSource); + nextValue.reactive = reactive; + instructions.push({ + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: Object.assign(Object.assign({}, nextValue), { effect: Effect.Mutate }), + value: { + kind: 'PropertyLoad', + object: Object.assign(Object.assign({}, currValue), { effect: Effect.Capture }), + property: path.property, + loc: loc, + }, + }); + currValue = nextValue; + } + currValue.effect = Effect.Freeze; + return { place: currValue, instructions }; +} +function inferReactiveIdentifiers(fn) { + const reactiveIds = new Set(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const place of eachInstructionOperand(instr)) { + if (place.reactive) { + reactiveIds.add(place.identifier.id); + } + } + } + for (const place of eachTerminalOperand(block.terminal)) { + if (place.reactive) { + reactiveIds.add(place.identifier.id); + } + } + } + return reactiveIds; +} +function collectDepUsages(deps, fnExpr) { + const identifiers = new Map(); + const loadedDeps = new Set(); + const sourceLocations = []; + for (const dep of deps) { + identifiers.set(dep.identifier.id, dep); + } + for (const [, block] of fnExpr.loweredFunc.func.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'LoadLocal' && + identifiers.has(instr.value.place.identifier.id)) { + loadedDeps.add(instr.lvalue.identifier.id); + } + for (const place of eachInstructionOperand(instr)) { + if (loadedDeps.has(place.identifier.id)) { + sourceLocations.push(place.identifier.loc); + } + } + } + } + return sourceLocations; +} +function inferMinimalDependencies(fnInstr) { + const fn = fnInstr.value.loweredFunc.func; + const temporaries = collectTemporariesSidemap(fn, new Set()); + const { hoistableObjects, processedInstrsInOptional, temporariesReadInOptional, } = collectOptionalChainSidemap(fn); + const hoistablePropertyLoads = collectHoistablePropertyLoadsInInnerFn(fnInstr, temporaries, hoistableObjects); + const hoistableToFnEntry = hoistablePropertyLoads.get(fn.body.entry); + CompilerError.invariant(hoistableToFnEntry != null, { + reason: '[InferEffectDependencies] Internal invariant broken: missing entry block', + loc: fnInstr.loc, + }); + const dependencies = inferDependencies(fnInstr, new Map([...temporaries, ...temporariesReadInOptional]), processedInstrsInOptional); + const tree = new ReactiveScopeDependencyTreeHIR([...hoistableToFnEntry.assumedNonNullObjects].map(o => o.fullPath)); + for (const dep of dependencies) { + tree.addDependency(Object.assign({}, dep)); + } + return tree.deriveMinimalDependencies(); +} +function inferDependencies(fnInstr, temporaries, processedInstrsInOptional) { + const fn = fnInstr.value.loweredFunc.func; + const context = new DependencyCollectionContext(new Set(), temporaries, processedInstrsInOptional); + for (const dep of fn.context) { + context.declare(dep.identifier, { + id: makeInstructionId(0), + scope: empty(), + }); + } + const placeholderScope = { + id: makeScopeId(0), + range: { + start: fnInstr.id, + end: makeInstructionId(fnInstr.id + 1), + }, + dependencies: new Set(), + reassignments: new Set(), + declarations: new Map(), + earlyReturnValue: null, + merged: new Set(), + loc: GeneratedSource, + }; + context.enterScope(placeholderScope); + inferDependenciesInFn(fn, context, temporaries); + context.exitScope(placeholderScope, false); + const resultUnfiltered = context.deps.get(placeholderScope); + CompilerError.invariant(resultUnfiltered != null, { + reason: '[InferEffectDependencies] Internal invariant broken: missing scope dependencies', + loc: fn.loc, + }); + const fnContext = new Set(fn.context.map(dep => dep.identifier.id)); + const result = new Set(); + for (const dep of resultUnfiltered) { + if (fnContext.has(dep.identifier.id)) { + result.add(dep); + } + } + return result; +} +function inferDependenciesInFn(fn, context, temporaries) { + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + for (const operand of phi.operands) { + const maybeOptionalChain = temporaries.get(operand[1].identifier.id); + if (maybeOptionalChain) { + context.visitDependency(maybeOptionalChain); + } + } + } + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + context.declare(instr.lvalue.identifier, { + id: instr.id, + scope: context.currentScope, + }); + const innerFn = instr.value.loweredFunc.func; + context.enterInnerFn(instr, () => { + inferDependenciesInFn(innerFn, context, temporaries); + }); + } + else { + handleInstruction(instr, context); + } + } + } +} + +function instructionReordering(fn) { + var _a; + const shared = new Map(); + const references = findReferencedRangeOfTemporaries(fn); + for (const [, block] of fn.body.blocks) { + reorderBlock(fn.env, block, shared, references); + } + CompilerError.invariant(shared.size === 0, { + reason: `InstructionReordering: expected all reorderable nodes to have been emitted`, + loc: (_a = [...shared.values()] + .map(node => { var _a; return (_a = node.instruction) === null || _a === void 0 ? void 0 : _a.loc; }) + .filter(loc => loc != null)[0]) !== null && _a !== void 0 ? _a : GeneratedSource, + }); + markInstructionIds(fn.body); +} +var ReferenceKind; +(function (ReferenceKind) { + ReferenceKind[ReferenceKind["Read"] = 0] = "Read"; + ReferenceKind[ReferenceKind["Write"] = 1] = "Write"; +})(ReferenceKind || (ReferenceKind = {})); +function findReferencedRangeOfTemporaries(fn) { + const singleUseIdentifiers = new Map(); + const lastAssignments = new Map(); + function reference(instr, place, kind) { + var _a; + if (place.identifier.name !== null && + place.identifier.name.kind === 'named') { + if (kind === ReferenceKind.Write) { + const name = place.identifier.name.value; + const previous = lastAssignments.get(name); + if (previous === undefined) { + lastAssignments.set(name, instr); + } + else { + lastAssignments.set(name, makeInstructionId(Math.max(previous, instr))); + } + } + return; + } + else if (kind === ReferenceKind.Read) { + const previousCount = (_a = singleUseIdentifiers.get(place.identifier.id)) !== null && _a !== void 0 ? _a : 0; + singleUseIdentifiers.set(place.identifier.id, previousCount + 1); + } + } + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const operand of eachInstructionValueLValue(instr.value)) { + reference(instr.id, operand, ReferenceKind.Read); + } + for (const lvalue of eachInstructionLValue(instr)) { + reference(instr.id, lvalue, ReferenceKind.Write); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + reference(block.terminal.id, operand, ReferenceKind.Read); + } + } + return { + singleUseIdentifiers: new Set([...singleUseIdentifiers] + .filter(([, count]) => count === 1) + .map(([id]) => id)), + lastAssignments, + }; +} +function reorderBlock(env, block, shared, references) { + var _a, _b; + const locals = new Map(); + const named = new Map(); + let previous = null; + for (const instr of block.instructions) { + const { lvalue, value } = instr; + const reorderability = getReorderability(instr, references); + const node = getOrInsertWith(locals, lvalue.identifier.id, () => ({ + instruction: instr, + dependencies: new Set(), + reorderability, + depth: null, + })); + if (reorderability === Reorderability.Nonreorderable) { + if (previous !== null) { + node.dependencies.add(previous); + } + previous = lvalue.identifier.id; + } + for (const operand of eachInstructionValueOperand(value)) { + const { name, id } = operand.identifier; + if (name !== null && name.kind === 'named') { + const previous = named.get(name.value); + if (previous !== undefined) { + node.dependencies.add(previous); + } + named.set(name.value, lvalue.identifier.id); + } + else if (locals.has(id) || shared.has(id)) { + node.dependencies.add(id); + } + } + for (const lvalueOperand of eachInstructionValueLValue(value)) { + const lvalueNode = getOrInsertWith(locals, lvalueOperand.identifier.id, () => ({ + instruction: null, + dependencies: new Set(), + depth: null, + })); + lvalueNode.dependencies.add(lvalue.identifier.id); + const name = lvalueOperand.identifier.name; + if (name !== null && name.kind === 'named') { + const previous = named.get(name.value); + if (previous !== undefined) { + node.dependencies.add(previous); + } + named.set(name.value, lvalue.identifier.id); + } + } + } + const nextInstructions = []; + if (isExpressionBlockKind(block.kind)) { + if (previous !== null) { + emit(env, locals, shared, nextInstructions, previous); + } + if (block.instructions.length !== 0) { + emit(env, locals, shared, nextInstructions, block.instructions.at(-1).lvalue.identifier.id); + } + for (const operand of eachTerminalOperand(block.terminal)) { + emit(env, locals, shared, nextInstructions, operand.identifier.id); + } + for (const [id, node] of locals) { + if (node.instruction == null) { + continue; + } + CompilerError.invariant(node.reorderability === Reorderability.Reorderable, { + reason: `Expected all remaining instructions to be reorderable`, + loc: (_b = (_a = node.instruction) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : block.terminal.loc, + description: node.instruction != null + ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable` + : `Lvalue $${id} was not emitted yet but is not reorderable`, + }); + shared.set(id, node); + } + } + else { + for (const operand of eachTerminalOperand(block.terminal)) { + emit(env, locals, shared, nextInstructions, operand.identifier.id); + } + for (const id of Array.from(locals.keys()).reverse()) { + const node = locals.get(id); + if (node === undefined) { + continue; + } + if (node.reorderability === Reorderability.Reorderable) { + shared.set(id, node); + } + else { + emit(env, locals, shared, nextInstructions, id); + } + } + } + block.instructions = nextInstructions; +} +function getDepth(env, nodes, id) { + const node = nodes.get(id); + if (node == null) { + return 0; + } + if (node.depth != null) { + return node.depth; + } + node.depth = 0; + let depth = node.reorderability === Reorderability.Reorderable ? 1 : 10; + for (const dep of node.dependencies) { + depth += getDepth(env, nodes, dep); + } + node.depth = depth; + return depth; +} +function emit(env, locals, shared, instructions, id) { + var _a; + const node = (_a = locals.get(id)) !== null && _a !== void 0 ? _a : shared.get(id); + if (node == null) { + return; + } + locals.delete(id); + shared.delete(id); + const deps = [...node.dependencies]; + deps.sort((a, b) => { + const aDepth = getDepth(env, locals, a); + const bDepth = getDepth(env, locals, b); + return bDepth - aDepth; + }); + for (const dep of deps) { + emit(env, locals, shared, instructions, dep); + } + if (node.instruction !== null) { + instructions.push(node.instruction); + } +} +var Reorderability; +(function (Reorderability) { + Reorderability[Reorderability["Reorderable"] = 0] = "Reorderable"; + Reorderability[Reorderability["Nonreorderable"] = 1] = "Nonreorderable"; +})(Reorderability || (Reorderability = {})); +function getReorderability(instr, references) { + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': + case 'JSXText': + case 'LoadGlobal': + case 'Primitive': + case 'TemplateLiteral': + case 'BinaryExpression': + case 'UnaryExpression': { + return Reorderability.Reorderable; + } + case 'LoadLocal': { + const name = instr.value.place.identifier.name; + if (name !== null && name.kind === 'named') { + const lastAssignment = references.lastAssignments.get(name.value); + if (lastAssignment !== undefined && + lastAssignment < instr.id && + references.singleUseIdentifiers.has(instr.lvalue.identifier.id)) { + return Reorderability.Reorderable; + } + } + return Reorderability.Nonreorderable; + } + default: { + return Reorderability.Nonreorderable; + } + } +} + +function alignMethodCallScopes(fn) { + const scopeMapping = new Map(); + const mergedScopes = new DisjointSet(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { lvalue, value } = instr; + if (value.kind === 'MethodCall') { + const lvalueScope = lvalue.identifier.scope; + const propertyScope = value.property.identifier.scope; + if (lvalueScope !== null) { + if (propertyScope !== null) { + mergedScopes.union([lvalueScope, propertyScope]); + } + else { + scopeMapping.set(value.property.identifier.id, lvalueScope); + } + } + else if (propertyScope !== null) { + scopeMapping.set(value.property.identifier.id, null); + } + } + else if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + alignMethodCallScopes(value.loweredFunc.func); + } + } + } + mergedScopes.forEach((scope, root) => { + if (scope === root) { + return; + } + root.range.start = makeInstructionId(Math.min(scope.range.start, root.range.start)); + root.range.end = makeInstructionId(Math.max(scope.range.end, root.range.end)); + }); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const mappedScope = scopeMapping.get(instr.lvalue.identifier.id); + if (mappedScope !== undefined) { + instr.lvalue.identifier.scope = mappedScope; + } + else if (instr.lvalue.identifier.scope !== null) { + const mergedScope = mergedScopes.find(instr.lvalue.identifier.scope); + if (mergedScope != null) { + instr.lvalue.identifier.scope = mergedScope; + } + } + } + } +} + +function alignReactiveScopesToBlockScopesHIR(fn) { + var _a, _b, _c, _d, _e; + const activeBlockFallthroughRanges = []; + const activeScopes = new Set(); + const seen = new Set(); + const valueBlockNodes = new Map(); + const placeScopes = new Map(); + function recordPlace(id, place, node) { + if (place.identifier.scope !== null) { + placeScopes.set(place, place.identifier.scope); + } + const scope = getPlaceScope(id, place); + if (scope == null) { + return; + } + activeScopes.add(scope); + node === null || node === void 0 ? void 0 : node.children.push({ kind: 'scope', scope, id }); + if (seen.has(scope)) { + return; + } + seen.add(scope); + if (node != null && node.valueRange !== null) { + scope.range.start = makeInstructionId(Math.min(node.valueRange.start, scope.range.start)); + scope.range.end = makeInstructionId(Math.max(node.valueRange.end, scope.range.end)); + } + } + for (const [, block] of fn.body.blocks) { + const startingId = (_b = (_a = block.instructions[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : block.terminal.id; + retainWhere_Set(activeScopes, scope => scope.range.end > startingId); + const top = activeBlockFallthroughRanges.at(-1); + if ((top === null || top === void 0 ? void 0 : top.fallthrough) === block.id) { + activeBlockFallthroughRanges.pop(); + for (const scope of activeScopes) { + scope.range.start = makeInstructionId(Math.min(scope.range.start, top.range.start)); + } + } + const { instructions, terminal } = block; + const node = (_c = valueBlockNodes.get(block.id)) !== null && _c !== void 0 ? _c : null; + for (const instr of instructions) { + for (const lvalue of eachInstructionLValue(instr)) { + recordPlace(instr.id, lvalue, node); + } + for (const operand of eachInstructionValueOperand(instr.value)) { + recordPlace(instr.id, operand, node); + } + } + for (const operand of eachTerminalOperand(terminal)) { + recordPlace(terminal.id, operand, node); + } + const fallthrough = terminalFallthrough(terminal); + if (fallthrough !== null && terminal.kind !== 'branch') { + const fallthroughBlock = fn.body.blocks.get(fallthrough); + const nextId = (_e = (_d = fallthroughBlock.instructions[0]) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : fallthroughBlock.terminal.id; + for (const scope of activeScopes) { + if (scope.range.end > terminal.id) { + scope.range.end = makeInstructionId(Math.max(scope.range.end, nextId)); + } + } + activeBlockFallthroughRanges.push({ + fallthrough, + range: { + start: terminal.id, + end: nextId, + }, + }); + CompilerError.invariant(!valueBlockNodes.has(fallthrough), { + reason: 'Expect hir blocks to have unique fallthroughs', + loc: terminal.loc, + }); + if (node != null) { + valueBlockNodes.set(fallthrough, node); + } + } + mapTerminalSuccessors(terminal, successor => { + var _a, _b; + if (valueBlockNodes.has(successor)) { + return successor; + } + const successorBlock = fn.body.blocks.get(successor); + if (successorBlock.kind === 'block' || successorBlock.kind === 'catch') ; + else if (node == null || + terminal.kind === 'ternary' || + terminal.kind === 'logical' || + terminal.kind === 'optional') { + let valueRange; + if (node == null) { + CompilerError.invariant(fallthrough !== null, { + reason: `Expected a fallthrough for value block`, + loc: terminal.loc, + }); + const fallthroughBlock = fn.body.blocks.get(fallthrough); + const nextId = (_b = (_a = fallthroughBlock.instructions[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : fallthroughBlock.terminal.id; + valueRange = { + start: terminal.id, + end: nextId, + }; + } + else { + valueRange = node.valueRange; + } + const childNode = { + kind: 'node', + id: terminal.id, + children: [], + valueRange, + }; + node === null || node === void 0 ? void 0 : node.children.push(childNode); + valueBlockNodes.set(successor, childNode); + } + else { + valueBlockNodes.set(successor, node); + } + return successor; + }); + } +} + +function flattenReactiveLoopsHIR(fn) { + const activeLoops = Array(); + for (const [, block] of fn.body.blocks) { + retainWhere(activeLoops, id => id !== block.id); + const { terminal } = block; + switch (terminal.kind) { + case 'do-while': + case 'for': + case 'for-in': + case 'for-of': + case 'while': { + activeLoops.push(terminal.fallthrough); + break; + } + case 'scope': { + if (activeLoops.length !== 0) { + block.terminal = { + kind: 'pruned-scope', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + scope: terminal.scope, + }; + } + break; + } + case 'branch': + case 'goto': + case 'if': + case 'label': + case 'logical': + case 'maybe-throw': + case 'optional': + case 'pruned-scope': + case 'return': + case 'sequence': + case 'switch': + case 'ternary': + case 'throw': + case 'try': + case 'unreachable': + case 'unsupported': { + break; + } + default: { + assertExhaustive$1(terminal, `Unexpected terminal kind \`${terminal.kind}\``); + } + } + } +} + +function flattenScopesWithHooksOrUseHIR(fn) { + const activeScopes = []; + const prune = []; + for (const [, block] of fn.body.blocks) { + retainWhere(activeScopes, current => current.fallthrough !== block.id); + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'MethodCall': + case 'CallExpression': { + const callee = value.kind === 'MethodCall' ? value.property : value.callee; + if (getHookKind(fn.env, callee.identifier) != null || + isUseOperator(callee.identifier)) { + prune.push(...activeScopes.map(entry => entry.block)); + activeScopes.length = 0; + } + } + } + } + if (block.terminal.kind === 'scope') { + activeScopes.push({ + block: block.id, + fallthrough: block.terminal.fallthrough, + }); + } + } + for (const id of prune) { + const block = fn.body.blocks.get(id); + const terminal = block.terminal; + CompilerError.invariant(terminal.kind === 'scope', { + reason: `Expected block to have a scope terminal`, + description: `Expected block bb${block.id} to end in a scope terminal`, + loc: terminal.loc, + }); + const body = fn.body.blocks.get(terminal.block); + if (body.instructions.length === 1 && + body.terminal.kind === 'goto' && + body.terminal.block === terminal.fallthrough) { + block.terminal = { + kind: 'label', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + }; + continue; + } + block.terminal = { + kind: 'pruned-scope', + block: terminal.block, + fallthrough: terminal.fallthrough, + id: terminal.id, + loc: terminal.loc, + scope: terminal.scope, + }; + } +} + +function pruneAlwaysInvalidatingScopes(fn) { + visitReactiveFunction(fn, new Transform(), false); +} +class Transform extends ReactiveFunctionTransform { + constructor() { + super(...arguments); + this.alwaysInvalidatingValues = new Set(); + this.unmemoizedValues = new Set(); + } + transformInstruction(instruction, withinScope) { + this.visitInstruction(instruction, withinScope); + const { lvalue, value } = instruction; + switch (value.kind) { + case 'ArrayExpression': + case 'ObjectExpression': + case 'JsxExpression': + case 'JsxFragment': + case 'NewExpression': { + if (lvalue !== null) { + this.alwaysInvalidatingValues.add(lvalue.identifier); + if (!withinScope) { + this.unmemoizedValues.add(lvalue.identifier); + } + } + break; + } + case 'StoreLocal': { + if (this.alwaysInvalidatingValues.has(value.value.identifier)) { + this.alwaysInvalidatingValues.add(value.lvalue.place.identifier); + } + if (this.unmemoizedValues.has(value.value.identifier)) { + this.unmemoizedValues.add(value.lvalue.place.identifier); + } + break; + } + case 'LoadLocal': { + if (lvalue !== null && + this.alwaysInvalidatingValues.has(value.place.identifier)) { + this.alwaysInvalidatingValues.add(lvalue.identifier); + } + if (lvalue !== null && + this.unmemoizedValues.has(value.place.identifier)) { + this.unmemoizedValues.add(lvalue.identifier); + } + break; + } + } + return { kind: 'keep' }; + } + transformScope(scopeBlock, _withinScope) { + this.visitScope(scopeBlock, true); + for (const dep of scopeBlock.scope.dependencies) { + if (this.unmemoizedValues.has(dep.identifier)) { + for (const [_, decl] of scopeBlock.scope.declarations) { + if (this.alwaysInvalidatingValues.has(decl.identifier)) { + this.unmemoizedValues.add(decl.identifier); + } + } + for (const identifier of scopeBlock.scope.reassignments) { + if (this.alwaysInvalidatingValues.has(identifier)) { + this.unmemoizedValues.add(identifier); + } + } + return { + kind: 'replace', + value: { + kind: 'pruned-scope', + scope: scopeBlock.scope, + instructions: scopeBlock.instructions, + }, + }; + } + } + return { kind: 'keep' }; + } +} + +let Visitor$2 = class Visitor extends ReactiveFunctionVisitor { + constructor(env, aliases, paths) { + super(); + this.map = new Map(); + this.aliases = aliases; + this.paths = paths; + this.env = env; + } + join(values) { + function join2(l, r) { + if (l === 'Update' || r === 'Update') { + return 'Update'; + } + else if (l === 'Create' || r === 'Create') { + return 'Create'; + } + else if (l === 'Unknown' || r === 'Unknown') { + return 'Unknown'; + } + assertExhaustive$1(r, `Unhandled variable kind ${r}`); + } + return values.reduce(join2, 'Unknown'); + } + isCreateOnlyHook(id) { + return isUseStateType(id) || isUseRefType(id); + } + visitPlace(_, place, state) { + var _a; + this.map.set(place.identifier.id, this.join([state, (_a = this.map.get(place.identifier.id)) !== null && _a !== void 0 ? _a : 'Unknown'])); + } + visitBlock(block, state) { + super.visitBlock([...block].reverse(), state); + } + visitInstruction(instruction) { + const state = this.join([...eachInstructionLValue(instruction)].map(operand => { var _a; return (_a = this.map.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : 'Unknown'; })); + const visitCallOrMethodNonArgs = () => { + switch (instruction.value.kind) { + case 'CallExpression': { + this.visitPlace(instruction.id, instruction.value.callee, state); + break; + } + case 'MethodCall': { + this.visitPlace(instruction.id, instruction.value.property, state); + this.visitPlace(instruction.id, instruction.value.receiver, state); + break; + } + } + }; + const isHook = () => { + let callee = null; + switch (instruction.value.kind) { + case 'CallExpression': { + callee = instruction.value.callee.identifier; + break; + } + case 'MethodCall': { + callee = instruction.value.property.identifier; + break; + } + } + return callee != null && getHookKind(this.env, callee) != null; + }; + switch (instruction.value.kind) { + case 'CallExpression': + case 'MethodCall': { + if (instruction.lvalue && + this.isCreateOnlyHook(instruction.lvalue.identifier)) { + [...eachCallArgument(instruction.value.args)].forEach(operand => this.visitPlace(instruction.id, operand, 'Create')); + visitCallOrMethodNonArgs(); + } + else { + this.traverseInstruction(instruction, isHook() ? 'Update' : state); + } + break; + } + default: { + this.traverseInstruction(instruction, state); + } + } + } + visitScope(scope) { + const state = this.join([ + ...scope.scope.declarations.keys(), + ...[...scope.scope.reassignments.values()].map(ident => ident.id), + ].map(id => { var _a; return (_a = this.map.get(id)) !== null && _a !== void 0 ? _a : 'Unknown'; })); + super.visitScope(scope, state); + [...scope.scope.dependencies].forEach(ident => { + var _a; + let target = (_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0 ? _a : ident.identifier.id; + ident.path.forEach(token => { + var _a; + target && (target = (_a = this.paths.get(target)) === null || _a === void 0 ? void 0 : _a.get(token.property)); + }); + if (target && this.map.get(target) === 'Create') { + scope.scope.dependencies.delete(ident); + } + }); + } + visitTerminal(stmt, state) { + CompilerError.invariant(state !== 'Create', { + reason: "Visiting a terminal statement with state 'Create'", + loc: stmt.terminal.loc, + }); + super.visitTerminal(stmt, state); + } + visitReactiveFunctionValue(_id, _dependencies, fn, state) { + visitReactiveFunction(fn, this, state); + } +}; +function pruneInitializationDependencies(fn) { + const [aliases, paths] = getAliases(fn); + visitReactiveFunction(fn, new Visitor$2(fn.env, aliases, paths), 'Update'); +} +function update(map, key, path, value) { + var _a; + const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map(); + inner.set(path, value); + map.set(key, inner); +} +class AliasVisitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopeIdentifiers = new DisjointSet(); + this.scopePaths = new Map(); + } + visitInstruction(instr) { + if (instr.value.kind === 'StoreLocal' || + instr.value.kind === 'StoreContext') { + this.scopeIdentifiers.union([ + instr.value.lvalue.place.identifier.id, + instr.value.value.identifier.id, + ]); + } + else if (instr.value.kind === 'LoadLocal' || + instr.value.kind === 'LoadContext') { + instr.lvalue && + this.scopeIdentifiers.union([ + instr.lvalue.identifier.id, + instr.value.place.identifier.id, + ]); + } + else if (instr.value.kind === 'PropertyLoad') { + instr.lvalue && + update(this.scopePaths, instr.value.object.identifier.id, instr.value.property, instr.lvalue.identifier.id); + } + else if (instr.value.kind === 'PropertyStore') { + update(this.scopePaths, instr.value.object.identifier.id, instr.value.property, instr.value.value.identifier.id); + } + } +} +function getAliases(fn) { + var _a, _b; + const visitor = new AliasVisitor(); + visitReactiveFunction(fn, visitor, null); + let disjoint = visitor.scopeIdentifiers; + let scopePaths = new Map(); + for (const [key, value] of visitor.scopePaths) { + for (const [path, id] of value) { + update(scopePaths, (_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key, path, (_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id); + } + } + return [disjoint, scopePaths]; +} + +function isPrimitiveBinaryOp(op) { + switch (op) { + case '+': + case '-': + case '/': + case '%': + case '*': + case '**': + case '&': + case '|': + case '>>': + case '<<': + case '^': + case '>': + case '<': + case '>=': + case '<=': + case '|>': + return true; + default: + return false; + } +} +function inferTypes(func) { + const unifier = new Unifier(func.env); + for (const e of generate(func)) { + unifier.unify(e.left, e.right); + } + apply(func, unifier); +} +function apply(func, unifier) { + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + phi.place.identifier.type = unifier.get(phi.place.identifier.type); + } + for (const instr of block.instructions) { + for (const operand of eachInstructionLValue(instr)) { + operand.identifier.type = unifier.get(operand.identifier.type); + } + for (const place of eachInstructionOperand(instr)) { + place.identifier.type = unifier.get(place.identifier.type); + } + const { lvalue, value } = instr; + lvalue.identifier.type = unifier.get(lvalue.identifier.type); + if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + apply(value.loweredFunc.func, unifier); + } + } + } + func.returnType = unifier.get(func.returnType); +} +function equation(left, right) { + return { + left, + right, + }; +} +function* generate(func) { + if (func.fnType === 'Component') { + const [props, ref] = func.params; + if (props && props.kind === 'Identifier') { + yield equation(props.identifier.type, { + kind: 'Object', + shapeId: BuiltInPropsId, + }); + } + if (ref && ref.kind === 'Identifier') { + yield equation(ref.identifier.type, { + kind: 'Object', + shapeId: BuiltInUseRefId, + }); + } + } + const names = new Map(); + const returnTypes = []; + for (const [_, block] of func.body.blocks) { + for (const phi of block.phis) { + yield equation(phi.place.identifier.type, { + kind: 'Phi', + operands: [...phi.operands.values()].map(id => id.identifier.type), + }); + } + for (const instr of block.instructions) { + yield* generateInstructionTypes(func.env, names, instr); + } + const terminal = block.terminal; + if (terminal.kind === 'return') { + returnTypes.push(terminal.value.identifier.type); + } + } + if (returnTypes.length > 1) { + yield equation(func.returnType, { + kind: 'Phi', + operands: returnTypes, + }); + } + else if (returnTypes.length === 1) { + yield equation(func.returnType, returnTypes[0]); + } +} +function setName(names, id, name) { + var _a; + if (((_a = name.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named') { + names.set(id, name.name.value); + } +} +function getName(names, id) { + var _a; + return (_a = names.get(id)) !== null && _a !== void 0 ? _a : ''; +} +function* generateInstructionTypes(env, names, instr) { + const { lvalue, value } = instr; + const left = lvalue.identifier.type; + switch (value.kind) { + case 'TemplateLiteral': + case 'JSXText': + case 'Primitive': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'UnaryExpression': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'LoadLocal': { + setName(names, lvalue.identifier.id, value.place.identifier); + yield equation(left, value.place.identifier.type); + break; + } + case 'DeclareContext': + case 'StoreContext': + case 'LoadContext': { + break; + } + case 'StoreLocal': { + if (env.config.enableUseTypeAnnotations) { + yield equation(value.lvalue.place.identifier.type, value.value.identifier.type); + const valueType = value.type === null ? makeType() : lowerType(value.type); + yield equation(valueType, value.lvalue.place.identifier.type); + yield equation(left, valueType); + } + else { + yield equation(left, value.value.identifier.type); + yield equation(value.lvalue.place.identifier.type, value.value.identifier.type); + } + break; + } + case 'StoreGlobal': { + yield equation(left, value.value.identifier.type); + break; + } + case 'BinaryExpression': { + if (isPrimitiveBinaryOp(value.operator)) { + yield equation(value.left.identifier.type, { kind: 'Primitive' }); + yield equation(value.right.identifier.type, { kind: 'Primitive' }); + } + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + yield equation(value.value.identifier.type, { kind: 'Primitive' }); + yield equation(value.lvalue.identifier.type, { kind: 'Primitive' }); + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'LoadGlobal': { + const globalType = env.getGlobalDeclaration(value.binding, value.loc); + if (globalType) { + yield equation(left, globalType); + } + break; + } + case 'CallExpression': { + const returnType = makeType(); + yield equation(value.callee.identifier.type, { + kind: 'Function', + shapeId: null, + return: returnType, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'TaggedTemplateExpression': { + const returnType = makeType(); + yield equation(value.tag.identifier.type, { + kind: 'Function', + shapeId: null, + return: returnType, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'ObjectExpression': { + for (const property of value.properties) { + if (property.kind === 'ObjectProperty' && + property.key.kind === 'computed') { + yield equation(property.key.name.identifier.type, { + kind: 'Primitive', + }); + } + } + yield equation(left, { kind: 'Object', shapeId: BuiltInObjectId }); + break; + } + case 'ArrayExpression': { + yield equation(left, { kind: 'Object', shapeId: BuiltInArrayId }); + break; + } + case 'PropertyLoad': { + yield equation(left, { + kind: 'Property', + objectType: value.object.identifier.type, + objectName: getName(names, value.object.identifier.id), + propertyName: { + kind: 'literal', + value: value.property, + }, + }); + break; + } + case 'ComputedLoad': { + yield equation(left, { + kind: 'Property', + objectType: value.object.identifier.type, + objectName: getName(names, value.object.identifier.id), + propertyName: { + kind: 'computed', + value: value.property.identifier.type, + }, + }); + break; + } + case 'MethodCall': { + const returnType = makeType(); + yield equation(value.property.identifier.type, { + kind: 'Function', + return: returnType, + shapeId: null, + isConstructor: false, + }); + yield equation(left, returnType); + break; + } + case 'Destructure': { + const pattern = value.lvalue.pattern; + if (pattern.kind === 'ArrayPattern') { + for (let i = 0; i < pattern.items.length; i++) { + const item = pattern.items[i]; + if (item.kind === 'Identifier') { + const propertyName = String(i); + yield equation(item.identifier.type, { + kind: 'Property', + objectType: value.value.identifier.type, + objectName: getName(names, value.value.identifier.id), + propertyName: { + kind: 'literal', + value: makePropertyLiteral(propertyName), + }, + }); + } + else { + break; + } + } + } + else { + for (const property of pattern.properties) { + if (property.kind === 'ObjectProperty') { + if (property.key.kind === 'identifier' || + property.key.kind === 'string') { + yield equation(property.place.identifier.type, { + kind: 'Property', + objectType: value.value.identifier.type, + objectName: getName(names, value.value.identifier.id), + propertyName: { + kind: 'literal', + value: makePropertyLiteral(property.key.name), + }, + }); + } + } + } + } + break; + } + case 'TypeCastExpression': { + if (env.config.enableUseTypeAnnotations) { + yield equation(value.type, value.value.identifier.type); + yield equation(left, value.type); + } + else { + yield equation(left, value.value.identifier.type); + } + break; + } + case 'PropertyDelete': + case 'ComputedDelete': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'FunctionExpression': { + yield* generate(value.loweredFunc.func); + yield equation(left, { + kind: 'Function', + shapeId: BuiltInFunctionId, + return: value.loweredFunc.func.returnType, + isConstructor: false, + }); + break; + } + case 'NextPropertyOf': { + yield equation(left, { kind: 'Primitive' }); + break; + } + case 'ObjectMethod': { + yield* generate(value.loweredFunc.func); + yield equation(left, { kind: 'ObjectMethod' }); + break; + } + case 'JsxExpression': + case 'JsxFragment': { + yield equation(left, { kind: 'Object', shapeId: BuiltInJsxId }); + break; + } + case 'NewExpression': { + const returnType = makeType(); + yield equation(value.callee.identifier.type, { + kind: 'Function', + return: returnType, + shapeId: null, + isConstructor: true, + }); + yield equation(left, returnType); + break; + } + case 'PropertyStore': + case 'DeclareLocal': + case 'RegExpLiteral': + case 'MetaProperty': + case 'ComputedStore': + case 'Await': + case 'GetIterator': + case 'IteratorNext': + case 'UnsupportedNode': + case 'Debugger': + case 'FinishMemoize': + case 'StartMemoize': { + break; + } + default: + assertExhaustive$1(value, `Unhandled instruction value kind: ${value.kind}`); + } +} +class Unifier { + constructor(env) { + this.substitutions = new Map(); + this.env = env; + } + unify(tA, tB) { + if (tB.kind === 'Property') { + if (this.env.config.enableTreatRefLikeIdentifiersAsRefs && + isRefLikeName(tB)) { + this.unify(tB.objectType, { + kind: 'Object', + shapeId: BuiltInUseRefId, + }); + this.unify(tA, { + kind: 'Object', + shapeId: BuiltInRefValueId, + }); + return; + } + const objectType = this.get(tB.objectType); + const propertyType = tB.propertyName.kind === 'literal' + ? this.env.getPropertyType(objectType, tB.propertyName.value) + : this.env.getFallthroughPropertyType(objectType, tB.propertyName.value); + if (propertyType !== null) { + this.unify(tA, propertyType); + } + return; + } + if (typeEquals(tA, tB)) { + return; + } + if (tA.kind === 'Type') { + this.bindVariableTo(tA, tB); + return; + } + if (tB.kind === 'Type') { + this.bindVariableTo(tB, tA); + return; + } + if (tB.kind === 'Function' && + tA.kind === 'Function' && + tA.isConstructor === tB.isConstructor) { + this.unify(tA.return, tB.return); + return; + } + } + bindVariableTo(v, type) { + if (type.kind === 'Poly') { + return; + } + if (this.substitutions.has(v.id)) { + this.unify(this.substitutions.get(v.id), type); + return; + } + if (type.kind === 'Type' && this.substitutions.has(type.id)) { + this.unify(v, this.substitutions.get(type.id)); + return; + } + if (type.kind === 'Phi') { + CompilerError.invariant(type.operands.length > 0, { + reason: 'there should be at least one operand', + description: null, + loc: null, + suggestions: null, + }); + let candidateType = null; + for (const operand of type.operands) { + const resolved = this.get(operand); + if (candidateType === null) { + candidateType = resolved; + } + else if (!typeEquals(resolved, candidateType)) { + const unionType = tryUnionTypes(resolved, candidateType); + if (unionType === null) { + candidateType = null; + break; + } + else { + candidateType = unionType; + } + } + } + if (candidateType !== null) { + this.unify(v, candidateType); + return; + } + } + if (this.occursCheck(v, type)) { + const resolvedType = this.tryResolveType(v, type); + if (resolvedType !== null) { + this.substitutions.set(v.id, resolvedType); + return; + } + throw new Error('cycle detected'); + } + this.substitutions.set(v.id, type); + } + tryResolveType(v, type) { + switch (type.kind) { + case 'Phi': { + const operands = []; + for (const operand of type.operands) { + if (operand.kind === 'Type' && operand.id === v.id) { + continue; + } + const resolved = this.tryResolveType(v, operand); + if (resolved === null) { + return null; + } + operands.push(resolved); + } + return { kind: 'Phi', operands }; + } + case 'Type': { + const substitution = this.get(type); + if (substitution !== type) { + const resolved = this.tryResolveType(v, substitution); + if (resolved !== null) { + this.substitutions.set(type.id, resolved); + } + return resolved; + } + return type; + } + case 'Property': { + const objectType = this.tryResolveType(v, this.get(type.objectType)); + if (objectType === null) { + return null; + } + return { + kind: 'Property', + objectName: type.objectName, + objectType, + propertyName: type.propertyName, + }; + } + case 'Function': { + const returnType = this.tryResolveType(v, this.get(type.return)); + if (returnType === null) { + return null; + } + return { + kind: 'Function', + return: returnType, + shapeId: type.shapeId, + isConstructor: type.isConstructor, + }; + } + case 'ObjectMethod': + case 'Object': + case 'Primitive': + case 'Poly': { + return type; + } + default: { + assertExhaustive$1(type, `Unexpected type kind '${type.kind}'`); + } + } + } + occursCheck(v, type) { + if (typeEquals(v, type)) + return true; + if (type.kind === 'Type' && this.substitutions.has(type.id)) { + return this.occursCheck(v, this.substitutions.get(type.id)); + } + if (type.kind === 'Phi') { + return type.operands.some(o => this.occursCheck(v, o)); + } + if (type.kind === 'Function') { + return this.occursCheck(v, type.return); + } + return false; + } + get(type) { + if (type.kind === 'Type') { + if (this.substitutions.has(type.id)) { + return this.get(this.substitutions.get(type.id)); + } + } + if (type.kind === 'Phi') { + return { kind: 'Phi', operands: type.operands.map(o => this.get(o)) }; + } + return type; + } +} +const RefLikeNameRE = /^(?:[a-zA-Z$_][a-zA-Z$_0-9]*)Ref$|^ref$/; +function isRefLikeName(t) { + return (t.propertyName.kind === 'literal' && + RefLikeNameRE.test(t.objectName) && + t.propertyName.value === 'current'); +} +function tryUnionTypes(ty1, ty2) { + let readonlyType; + let otherType; + if (ty1.kind === 'Object' && ty1.shapeId === BuiltInMixedReadonlyId) { + readonlyType = ty1; + otherType = ty2; + } + else if (ty2.kind === 'Object' && ty2.shapeId === BuiltInMixedReadonlyId) { + readonlyType = ty2; + otherType = ty1; + } + else { + return null; + } + if (otherType.kind === 'Primitive') { + return readonlyType; + } + else if (otherType.kind === 'Object' && + otherType.shapeId === BuiltInArrayId) { + return otherType; + } + return null; +} + +function validateContextVariableLValues(fn) { + const identifierKinds = new Map(); + validateContextVariableLValuesImpl(fn, identifierKinds); +} +function validateContextVariableLValuesImpl(fn, identifierKinds) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'DeclareContext': + case 'StoreContext': { + visit(identifierKinds, value.lvalue.place, 'context'); + break; + } + case 'LoadContext': { + visit(identifierKinds, value.place, 'context'); + break; + } + case 'StoreLocal': + case 'DeclareLocal': { + visit(identifierKinds, value.lvalue.place, 'local'); + break; + } + case 'LoadLocal': { + visit(identifierKinds, value.place, 'local'); + break; + } + case 'PostfixUpdate': + case 'PrefixUpdate': { + visit(identifierKinds, value.lvalue, 'local'); + break; + } + case 'Destructure': { + for (const lvalue of eachPatternOperand(value.lvalue.pattern)) { + visit(identifierKinds, lvalue, 'destructure'); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + validateContextVariableLValuesImpl(value.loweredFunc.func, identifierKinds); + break; + } + default: { + for (const _ of eachInstructionValueLValue(value)) { + CompilerError.throwTodo({ + reason: 'ValidateContextVariableLValues: unhandled instruction variant', + loc: value.loc, + description: `Handle '${value.kind} lvalues`, + suggestions: null, + }); + } + } + } + } + } +} +function visit(identifiers, place, kind) { + const prev = identifiers.get(place.identifier.id); + if (prev !== undefined) { + const wasContext = prev.kind === 'context'; + const isContext = kind === 'context'; + if (wasContext !== isContext) { + if (prev.kind === 'destructure' || kind === 'destructure') { + CompilerError.throwTodo({ + reason: `Support destructuring of context variables`, + loc: kind === 'destructure' ? place.loc : prev.place.loc, + description: null, + suggestions: null, + }); + } + CompilerError.invariant(false, { + reason: `Expected all references to a variable to be consistently local or context references`, + loc: place.loc, + description: `Identifier ${printPlace(place)} is referenced as a ${kind} variable, but was previously referenced as a ${prev} variable`, + suggestions: null, + }); + } + } + identifiers.set(place.identifier.id, { place, kind }); +} + +function computeUnconditionalBlocks(fn) { + const unconditionalBlocks = new Set(); + const dominators = computePostDominatorTree(fn, { + includeThrowsAsExitNode: false, + }); + const exit = dominators.exit; + let current = fn.body.entry; + while (current !== null && current !== exit) { + CompilerError.invariant(!unconditionalBlocks.has(current), { + reason: 'Internal error: non-terminating loop in ComputeUnconditionalBlocks', + loc: null, + suggestions: null, + }); + unconditionalBlocks.add(current); + current = dominators.get(current); + } + return unconditionalBlocks; +} + +var Kind; +(function (Kind) { + Kind["Error"] = "Error"; + Kind["KnownHook"] = "KnownHook"; + Kind["PotentialHook"] = "PotentialHook"; + Kind["Global"] = "Global"; + Kind["Local"] = "Local"; +})(Kind || (Kind = {})); +function joinKinds(a, b) { + if (a === Kind.Error || b === Kind.Error) { + return Kind.Error; + } + else if (a === Kind.KnownHook || b === Kind.KnownHook) { + return Kind.KnownHook; + } + else if (a === Kind.PotentialHook || b === Kind.PotentialHook) { + return Kind.PotentialHook; + } + else if (a === Kind.Global || b === Kind.Global) { + return Kind.Global; + } + else { + return Kind.Local; + } +} +function validateHooksUsage(fn) { + const unconditionalBlocks = computeUnconditionalBlocks(fn); + const errors = new CompilerError(); + const errorsByPlace = new Map(); + function recordError(loc, errorDetail) { + if (typeof loc === 'symbol') { + errors.pushErrorDetail(errorDetail); + } + else { + errorsByPlace.set(loc, errorDetail); + } + } + function recordConditionalHookError(place) { + setKind(place, Kind.Error); + const reason = 'Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)'; + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined || previousError.reason !== reason) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason, + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + function recordInvalidHookUsageError(place) { + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason: 'Hooks may not be referenced as normal values, they must be called. See https://react.dev/reference/rules/react-calls-components-and-hooks#never-pass-around-hooks-as-regular-values', + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + function recordDynamicHookUsageError(place) { + const previousError = typeof place.loc !== 'symbol' ? errorsByPlace.get(place.loc) : undefined; + if (previousError === undefined) { + recordError(place.loc, new CompilerErrorDetail({ + description: null, + reason: 'Hooks must be the same function on every render, but this value may change over time to a different function. See https://react.dev/reference/rules/react-calls-components-and-hooks#dont-dynamically-use-hooks', + loc: place.loc, + severity: ErrorSeverity.InvalidReact, + suggestions: null, + })); + } + } + const valueKinds = new Map(); + function getKindForPlace(place) { + const knownKind = valueKinds.get(place.identifier.id); + if (place.identifier.name !== null && + isHookName$2(place.identifier.name.value)) { + return joinKinds(knownKind !== null && knownKind !== void 0 ? knownKind : Kind.Local, Kind.PotentialHook); + } + else { + return knownKind !== null && knownKind !== void 0 ? knownKind : Kind.Local; + } + } + function visitPlace(place) { + const kind = valueKinds.get(place.identifier.id); + if (kind === Kind.KnownHook) { + recordInvalidHookUsageError(place); + } + } + function setKind(place, kind) { + valueKinds.set(place.identifier.id, kind); + } + for (const param of fn.params) { + const place = param.kind === 'Identifier' ? param : param.place; + const kind = getKindForPlace(place); + setKind(place, kind); + } + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + let kind = phi.place.identifier.name !== null && + isHookName$2(phi.place.identifier.name.value) + ? Kind.PotentialHook + : Kind.Local; + for (const [, operand] of phi.operands) { + const operandKind = valueKinds.get(operand.identifier.id); + if (operandKind !== undefined) { + kind = joinKinds(kind, operandKind); + } + } + valueKinds.set(phi.place.identifier.id, kind); + } + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadGlobal': { + if (getHookKind(fn.env, instr.lvalue.identifier) != null) { + setKind(instr.lvalue, Kind.KnownHook); + } + else { + setKind(instr.lvalue, Kind.Global); + } + break; + } + case 'LoadContext': + case 'LoadLocal': { + visitPlace(instr.value.place); + const kind = getKindForPlace(instr.value.place); + setKind(instr.lvalue, kind); + break; + } + case 'StoreLocal': + case 'StoreContext': { + visitPlace(instr.value.value); + const kind = joinKinds(getKindForPlace(instr.value.value), getKindForPlace(instr.value.lvalue.place)); + setKind(instr.value.lvalue.place, kind); + setKind(instr.lvalue, kind); + break; + } + case 'ComputedLoad': { + visitPlace(instr.value.object); + const kind = getKindForPlace(instr.value.object); + setKind(instr.lvalue, joinKinds(getKindForPlace(instr.lvalue), kind)); + break; + } + case 'PropertyLoad': { + const objectKind = getKindForPlace(instr.value.object); + const isHookProperty = typeof instr.value.property === 'string' && + isHookName$2(instr.value.property); + let kind; + switch (objectKind) { + case Kind.Error: { + kind = Kind.Error; + break; + } + case Kind.KnownHook: { + kind = isHookProperty ? Kind.KnownHook : Kind.Local; + break; + } + case Kind.PotentialHook: { + kind = Kind.PotentialHook; + break; + } + case Kind.Global: { + kind = isHookProperty ? Kind.KnownHook : Kind.Global; + break; + } + case Kind.Local: { + kind = isHookProperty ? Kind.PotentialHook : Kind.Local; + break; + } + default: { + assertExhaustive$1(objectKind, `Unexpected kind \`${objectKind}\``); + } + } + setKind(instr.lvalue, kind); + break; + } + case 'CallExpression': { + const calleeKind = getKindForPlace(instr.value.callee); + const isHookCallee = calleeKind === Kind.KnownHook || calleeKind === Kind.PotentialHook; + if (isHookCallee && !unconditionalBlocks.has(block.id)) { + recordConditionalHookError(instr.value.callee); + } + else if (calleeKind === Kind.PotentialHook) { + recordDynamicHookUsageError(instr.value.callee); + } + for (const operand of eachInstructionOperand(instr)) { + if (operand === instr.value.callee) { + continue; + } + visitPlace(operand); + } + break; + } + case 'MethodCall': { + const calleeKind = getKindForPlace(instr.value.property); + const isHookCallee = calleeKind === Kind.KnownHook || calleeKind === Kind.PotentialHook; + if (isHookCallee && !unconditionalBlocks.has(block.id)) { + recordConditionalHookError(instr.value.property); + } + else if (calleeKind === Kind.PotentialHook) { + recordDynamicHookUsageError(instr.value.property); + } + for (const operand of eachInstructionOperand(instr)) { + if (operand === instr.value.property) { + continue; + } + visitPlace(operand); + } + break; + } + case 'Destructure': { + visitPlace(instr.value.value); + const objectKind = getKindForPlace(instr.value.value); + for (const lvalue of eachInstructionLValue(instr)) { + const isHookProperty = lvalue.identifier.name !== null && + isHookName$2(lvalue.identifier.name.value); + let kind; + switch (objectKind) { + case Kind.Error: { + kind = Kind.Error; + break; + } + case Kind.KnownHook: { + kind = Kind.KnownHook; + break; + } + case Kind.PotentialHook: { + kind = Kind.PotentialHook; + break; + } + case Kind.Global: { + kind = isHookProperty ? Kind.KnownHook : Kind.Global; + break; + } + case Kind.Local: { + kind = isHookProperty ? Kind.PotentialHook : Kind.Local; + break; + } + default: { + assertExhaustive$1(objectKind, `Unexpected kind \`${objectKind}\``); + } + } + setKind(lvalue, kind); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + visitFunctionExpression(errors, instr.value.loweredFunc.func); + break; + } + default: { + for (const operand of eachInstructionOperand(instr)) { + visitPlace(operand); + } + for (const lvalue of eachInstructionLValue(instr)) { + const kind = getKindForPlace(lvalue); + setKind(lvalue, kind); + } + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + visitPlace(operand); + } + } + for (const [, error] of errorsByPlace) { + errors.push(error); + } + return errors.asResult(); +} +function visitFunctionExpression(errors, fn) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'ObjectMethod': + case 'FunctionExpression': { + visitFunctionExpression(errors, instr.value.loweredFunc.func); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'CallExpression' + ? instr.value.callee + : instr.value.property; + const hookKind = getHookKind(fn.env, callee.identifier); + if (hookKind != null) { + errors.pushErrorDetail(new CompilerErrorDetail({ + severity: ErrorSeverity.InvalidReact, + reason: 'Hooks must be called at the top level in the body of a function component or custom hook, and may not be called within function expressions. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning)', + loc: callee.loc, + description: `Cannot call ${hookKind} within a function component`, + suggestions: null, + })); + } + break; + } + } + } + } +} + +function validateMemoizedEffectDependencies(fn) { + const errors = new CompilerError(); + visitReactiveFunction(fn, new Visitor$1(), errors); + return errors.asResult(); +} +let Visitor$1 = class Visitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopes = new Set(); + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + let areDependenciesMemoized = true; + for (const dep of scopeBlock.scope.dependencies) { + if (isUnmemoized$1(dep.identifier, this.scopes)) { + areDependenciesMemoized = false; + break; + } + } + if (areDependenciesMemoized) { + this.scopes.add(scopeBlock.scope.id); + for (const id of scopeBlock.scope.merged) { + this.scopes.add(id); + } + } + } + visitInstruction(instruction, state) { + this.traverseInstruction(instruction, state); + if (instruction.value.kind === 'CallExpression' && + isEffectHook(instruction.value.callee.identifier) && + instruction.value.args.length >= 2) { + const deps = instruction.value.args[1]; + if (deps.kind === 'Identifier' && + (isMutable(instruction, deps) || + isUnmemoized$1(deps.identifier, this.scopes))) { + state.push({ + reason: 'React Compiler has skipped optimizing this component because the effect dependencies could not be memoized. Unmemoized effect dependencies can trigger an infinite loop or other unexpected behavior', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc: typeof instruction.loc !== 'symbol' ? instruction.loc : null, + suggestions: null, + }); + } + } + } +}; +function isUnmemoized$1(operand, scopes) { + return operand.scope != null && !scopes.has(operand.scope.id); +} +function isEffectHook(identifier) { + return (isUseEffectHookType(identifier) || + isUseLayoutEffectHookType(identifier) || + isUseInsertionEffectHookType(identifier)); +} + +function validateNoCapitalizedCalls(fn) { + var _a; + const envConfig = fn.env.config; + const ALLOW_LIST = new Set([ + ...DEFAULT_GLOBALS.keys(), + ...((_a = envConfig.validateNoCapitalizedCalls) !== null && _a !== void 0 ? _a : []), + ]); + const hookPattern = envConfig.hookPattern != null ? new RegExp(envConfig.hookPattern) : null; + const isAllowed = (name) => { + return (ALLOW_LIST.has(name) || (hookPattern != null && hookPattern.test(name))); + }; + const errors = new CompilerError(); + const capitalLoadGlobals = new Map(); + const capitalizedProperties = new Map(); + const reason = 'Capitalized functions are reserved for components, which must be invoked with JSX. If this is a component, render it with JSX. Otherwise, ensure that it has no hook calls and rename it to begin with a lowercase letter. Alternatively, if you know for a fact that this function is not a component, you can allowlist it via the compiler config'; + for (const [, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + switch (value.kind) { + case 'LoadGlobal': { + if (value.binding.name != '' && + /^[A-Z]/.test(value.binding.name) && + !(value.binding.name.toUpperCase() === value.binding.name) && + !isAllowed(value.binding.name)) { + capitalLoadGlobals.set(lvalue.identifier.id, value.binding.name); + } + break; + } + case 'CallExpression': { + const calleeIdentifier = value.callee.identifier.id; + const calleeName = capitalLoadGlobals.get(calleeIdentifier); + if (calleeName != null) { + CompilerError.throwInvalidReact({ + reason, + description: `${calleeName} may be a component.`, + loc: value.loc, + suggestions: null, + }); + } + break; + } + case 'PropertyLoad': { + if (typeof value.property === 'string' && + /^[A-Z]/.test(value.property)) { + capitalizedProperties.set(lvalue.identifier.id, value.property); + } + break; + } + case 'MethodCall': { + const propertyIdentifier = value.property.identifier.id; + const propertyName = capitalizedProperties.get(propertyIdentifier); + if (propertyName != null) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason, + description: `${propertyName} may be a component.`, + loc: value.loc, + suggestions: null, + }); + } + break; + } + } + } + } + return errors.asResult(); +} + +var _Env_changed; +function makeRefId(id) { + CompilerError.invariant(id >= 0 && Number.isInteger(id), { + reason: 'Expected identifier id to be a non-negative integer', + description: null, + loc: null, + suggestions: null, + }); + return id; +} +let _refId = 0; +function nextRefId() { + return makeRefId(_refId++); +} +class Env extends Map { + constructor() { + super(...arguments); + _Env_changed.set(this, false); + } + resetChanged() { + __classPrivateFieldSet(this, _Env_changed, false, "f"); + } + hasChanged() { + return __classPrivateFieldGet(this, _Env_changed, "f"); + } + set(key, value) { + const cur = this.get(key); + const widenedValue = joinRefAccessTypes(value, cur !== null && cur !== void 0 ? cur : { kind: 'None' }); + if (!(cur == null && widenedValue.kind === 'None') && + (cur == null || !tyEqual(cur, widenedValue))) { + __classPrivateFieldSet(this, _Env_changed, true, "f"); + } + return super.set(key, widenedValue); + } +} +_Env_changed = new WeakMap(); +function validateNoRefAccessInRender(fn) { + const env = new Env(); + return validateNoRefAccessInRenderImpl(fn, env).map(_ => undefined); +} +function refTypeOfType(place) { + if (isRefValueType(place.identifier)) { + return { kind: 'RefValue' }; + } + else if (isUseRefType(place.identifier)) { + return { kind: 'Ref', refId: nextRefId() }; + } + else { + return { kind: 'None' }; + } +} +function tyEqual(a, b) { + if (a.kind !== b.kind) { + return false; + } + switch (a.kind) { + case 'None': + return true; + case 'Ref': + return true; + case 'Nullable': + return true; + case 'Guard': + CompilerError.invariant(b.kind === 'Guard', { + reason: 'Expected ref value', + loc: null, + }); + return a.refId === b.refId; + case 'RefValue': + CompilerError.invariant(b.kind === 'RefValue', { + reason: 'Expected ref value', + loc: null, + }); + return a.loc == b.loc; + case 'Structure': { + CompilerError.invariant(b.kind === 'Structure', { + reason: 'Expected structure', + loc: null, + }); + const fnTypesEqual = (a.fn === null && b.fn === null) || + (a.fn !== null && + b.fn !== null && + a.fn.readRefEffect === b.fn.readRefEffect && + tyEqual(a.fn.returnType, b.fn.returnType)); + return (fnTypesEqual && + (a.value === b.value || + (a.value !== null && b.value !== null && tyEqual(a.value, b.value)))); + } + } +} +function joinRefAccessTypes(...types) { + function joinRefAccessRefTypes(a, b) { + if (a.kind === 'RefValue') { + if (b.kind === 'RefValue' && a.refId === b.refId) { + return a; + } + return { kind: 'RefValue' }; + } + else if (b.kind === 'RefValue') { + return b; + } + else if (a.kind === 'Ref' || b.kind === 'Ref') { + if (a.kind === 'Ref' && b.kind === 'Ref' && a.refId === b.refId) { + return a; + } + return { kind: 'Ref', refId: nextRefId() }; + } + else { + CompilerError.invariant(a.kind === 'Structure' && b.kind === 'Structure', { + reason: 'Expected structure', + loc: null, + }); + const fn = a.fn === null + ? b.fn + : b.fn === null + ? a.fn + : { + readRefEffect: a.fn.readRefEffect || b.fn.readRefEffect, + returnType: joinRefAccessTypes(a.fn.returnType, b.fn.returnType), + }; + const value = a.value === null + ? b.value + : b.value === null + ? a.value + : joinRefAccessRefTypes(a.value, b.value); + return { + kind: 'Structure', + fn, + value, + }; + } + } + return types.reduce((a, b) => { + if (a.kind === 'None') { + return b; + } + else if (b.kind === 'None') { + return a; + } + else if (a.kind === 'Guard') { + if (b.kind === 'Guard' && a.refId === b.refId) { + return a; + } + else if (b.kind === 'Nullable' || b.kind === 'Guard') { + return { kind: 'None' }; + } + else { + return b; + } + } + else if (b.kind === 'Guard') { + if (a.kind === 'Nullable') { + return { kind: 'None' }; + } + else { + return b; + } + } + else if (a.kind === 'Nullable') { + return b; + } + else if (b.kind === 'Nullable') { + return a; + } + else { + return joinRefAccessRefTypes(a, b); + } + }, { kind: 'None' }); +} +function validateNoRefAccessInRenderImpl(fn, env) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + let returnValues = []; + let place; + for (const param of fn.params) { + if (param.kind === 'Identifier') { + place = param; + } + else { + place = param.place; + } + const type = refTypeOfType(place); + env.set(place.identifier.id, type); + } + for (let i = 0; (i == 0 || env.hasChanged()) && i < 10; i++) { + env.resetChanged(); + returnValues = []; + const safeBlocks = new Map(); + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + env.set(phi.place.identifier.id, joinRefAccessTypes(...Array(...phi.operands.values()).map(operand => { var _a; return (_a = env.get(operand.identifier.id)) !== null && _a !== void 0 ? _a : { kind: 'None' }; }))); + } + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoDirectRefValueAccess(errors, operand, env); + } + break; + } + case 'ComputedLoad': + case 'PropertyLoad': { + if (instr.value.kind === 'ComputedLoad') { + validateNoDirectRefValueAccess(errors, instr.value.property, env); + } + const objType = env.get(instr.value.object.identifier.id); + let lookupType = null; + if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Structure') { + lookupType = objType.value; + } + else if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Ref') { + lookupType = { + kind: 'RefValue', + loc: instr.loc, + refId: objType.refId, + }; + } + env.set(instr.lvalue.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(instr.lvalue)); + break; + } + case 'TypeCastExpression': { + env.set(instr.lvalue.identifier.id, (_a = env.get(instr.value.value.identifier.id)) !== null && _a !== void 0 ? _a : refTypeOfType(instr.lvalue)); + break; + } + case 'LoadContext': + case 'LoadLocal': { + env.set(instr.lvalue.identifier.id, (_b = env.get(instr.value.place.identifier.id)) !== null && _b !== void 0 ? _b : refTypeOfType(instr.lvalue)); + break; + } + case 'StoreContext': + case 'StoreLocal': { + env.set(instr.value.lvalue.place.identifier.id, (_c = env.get(instr.value.value.identifier.id)) !== null && _c !== void 0 ? _c : refTypeOfType(instr.value.lvalue.place)); + env.set(instr.lvalue.identifier.id, (_d = env.get(instr.value.value.identifier.id)) !== null && _d !== void 0 ? _d : refTypeOfType(instr.lvalue)); + break; + } + case 'Destructure': { + const objType = env.get(instr.value.value.identifier.id); + let lookupType = null; + if ((objType === null || objType === void 0 ? void 0 : objType.kind) === 'Structure') { + lookupType = objType.value; + } + env.set(instr.lvalue.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(instr.lvalue)); + for (const lval of eachPatternOperand(instr.value.lvalue.pattern)) { + env.set(lval.identifier.id, lookupType !== null && lookupType !== void 0 ? lookupType : refTypeOfType(lval)); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + let returnType = { kind: 'None' }; + let readRefEffect = false; + const result = validateNoRefAccessInRenderImpl(instr.value.loweredFunc.func, env); + if (result.isOk()) { + returnType = result.unwrap(); + } + else if (result.isErr()) { + readRefEffect = true; + } + env.set(instr.lvalue.identifier.id, { + kind: 'Structure', + fn: { + readRefEffect, + returnType, + }, + value: null, + }); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'CallExpression' + ? instr.value.callee + : instr.value.property; + const hookKind = getHookKindForType(fn.env, callee.identifier.type); + let returnType = { kind: 'None' }; + const fnType = env.get(callee.identifier.id); + if ((fnType === null || fnType === void 0 ? void 0 : fnType.kind) === 'Structure' && fnType.fn !== null) { + returnType = fnType.fn.returnType; + if (fnType.fn.readRefEffect) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'This function accesses a ref value (the `current` property), which may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: callee.loc, + description: callee.identifier.name !== null && + callee.identifier.name.kind === 'named' + ? `Function \`${callee.identifier.name.value}\` accesses a ref` + : null, + suggestions: null, + }); + } + } + for (const operand of eachInstructionValueOperand(instr.value)) { + if (hookKind != null) { + validateNoDirectRefValueAccess(errors, operand, env); + } + else { + validateNoRefAccess(errors, env, operand, operand.loc); + } + } + env.set(instr.lvalue.identifier.id, returnType); + break; + } + case 'ObjectExpression': + case 'ArrayExpression': { + const types = []; + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoDirectRefValueAccess(errors, operand, env); + types.push((_e = env.get(operand.identifier.id)) !== null && _e !== void 0 ? _e : { kind: 'None' }); + } + const value = joinRefAccessTypes(...types); + if (value.kind === 'None' || + value.kind === 'Guard' || + value.kind === 'Nullable') { + env.set(instr.lvalue.identifier.id, { kind: 'None' }); + } + else { + env.set(instr.lvalue.identifier.id, { + kind: 'Structure', + value, + fn: null, + }); + } + break; + } + case 'PropertyDelete': + case 'PropertyStore': + case 'ComputedDelete': + case 'ComputedStore': { + const safe = safeBlocks.get(block.id); + const target = env.get(instr.value.object.identifier.id); + if (instr.value.kind === 'PropertyStore' && + safe != null && + (target === null || target === void 0 ? void 0 : target.kind) === 'Ref' && + target.refId === safe) { + safeBlocks.delete(block.id); + } + else { + validateNoRefAccess(errors, env, instr.value.object, instr.loc); + } + for (const operand of eachInstructionValueOperand(instr.value)) { + if (operand === instr.value.object) { + continue; + } + validateNoRefValueAccess(errors, env, operand); + } + break; + } + case 'StartMemoize': + case 'FinishMemoize': + break; + case 'Primitive': { + if (instr.value.value == null) { + env.set(instr.lvalue.identifier.id, { kind: 'Nullable' }); + } + break; + } + case 'BinaryExpression': { + const left = env.get(instr.value.left.identifier.id); + const right = env.get(instr.value.right.identifier.id); + let nullish = false; + let refId = null; + if ((left === null || left === void 0 ? void 0 : left.kind) === 'RefValue' && left.refId != null) { + refId = left.refId; + } + else if ((right === null || right === void 0 ? void 0 : right.kind) === 'RefValue' && right.refId != null) { + refId = right.refId; + } + if ((left === null || left === void 0 ? void 0 : left.kind) === 'Nullable') { + nullish = true; + } + else if ((right === null || right === void 0 ? void 0 : right.kind) === 'Nullable') { + nullish = true; + } + if (refId !== null && nullish) { + env.set(instr.lvalue.identifier.id, { kind: 'Guard', refId }); + } + else { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoRefValueAccess(errors, env, operand); + } + } + break; + } + default: { + for (const operand of eachInstructionValueOperand(instr.value)) { + validateNoRefValueAccess(errors, env, operand); + } + break; + } + } + for (const operand of eachInstructionOperand(instr)) { + guardCheck(errors, operand, env); + } + if (isUseRefType(instr.lvalue.identifier) && + ((_f = env.get(instr.lvalue.identifier.id)) === null || _f === void 0 ? void 0 : _f.kind) !== 'Ref') { + env.set(instr.lvalue.identifier.id, joinRefAccessTypes((_g = env.get(instr.lvalue.identifier.id)) !== null && _g !== void 0 ? _g : { kind: 'None' }, { kind: 'Ref', refId: nextRefId() })); + } + if (isRefValueType(instr.lvalue.identifier) && + ((_h = env.get(instr.lvalue.identifier.id)) === null || _h === void 0 ? void 0 : _h.kind) !== 'RefValue') { + env.set(instr.lvalue.identifier.id, joinRefAccessTypes((_j = env.get(instr.lvalue.identifier.id)) !== null && _j !== void 0 ? _j : { kind: 'None' }, { kind: 'RefValue', loc: instr.loc })); + } + } + if (block.terminal.kind === 'if') { + const test = env.get(block.terminal.test.identifier.id); + if ((test === null || test === void 0 ? void 0 : test.kind) === 'Guard') { + safeBlocks.set(block.terminal.consequent, test.refId); + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + if (block.terminal.kind !== 'return') { + validateNoRefValueAccess(errors, env, operand); + if (block.terminal.kind !== 'if') { + guardCheck(errors, operand, env); + } + } + else { + validateNoDirectRefValueAccess(errors, operand, env); + guardCheck(errors, operand, env); + returnValues.push(env.get(operand.identifier.id)); + } + } + } + if (errors.hasErrors()) { + return Err(errors); + } + } + CompilerError.invariant(!env.hasChanged(), { + reason: 'Ref type environment did not converge', + loc: null, + }); + return Ok(joinRefAccessTypes(...returnValues.filter((env) => env !== undefined))); +} +function destructure(type) { + if ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && type.value !== null) { + return destructure(type.value); + } + return type; +} +function guardCheck(errors, operand, env) { + var _a; + if (((_a = env.get(operand.identifier.id)) === null || _a === void 0 ? void 0 : _a.kind) === 'Guard') { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoRefValueAccess(errors, env, operand) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'RefValue' || + ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && ((_a = type.fn) === null || _a === void 0 ? void 0 : _a.readRefEffect))) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (type.kind === 'RefValue' && type.loc) || operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoRefAccess(errors, env, operand, loc) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'Ref' || + (type === null || type === void 0 ? void 0 : type.kind) === 'RefValue' || + ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && ((_a = type.fn) === null || _a === void 0 ? void 0 : _a.readRefEffect))) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (type.kind === 'RefValue' && type.loc) || loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} +function validateNoDirectRefValueAccess(errors, operand, env) { + var _a; + const type = destructure(env.get(operand.identifier.id)); + if ((type === null || type === void 0 ? void 0 : type.kind) === 'RefValue') { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)', + loc: (_a = type.loc) !== null && _a !== void 0 ? _a : operand.loc, + description: operand.identifier.name !== null && + operand.identifier.name.kind === 'named' + ? `Cannot access ref value \`${operand.identifier.name.value}\`` + : null, + suggestions: null, + }); + } +} + +function validateNoSetStateInRender(fn) { + const unconditionalSetStateFunctions = new Set(); + return validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions); +} +function validateNoSetStateInRenderImpl(fn, unconditionalSetStateFunctions) { + const unconditionalBlocks = computeUnconditionalBlocks(fn); + let activeManualMemoId = null; + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (unconditionalSetStateFunctions.has(instr.value.place.identifier.id)) { + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'StoreLocal': { + if (unconditionalSetStateFunctions.has(instr.value.value.identifier.id)) { + unconditionalSetStateFunctions.add(instr.value.lvalue.place.identifier.id); + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'ObjectMethod': + case 'FunctionExpression': { + if ([...eachInstructionValueOperand(instr.value)].some(operand => isSetStateType(operand.identifier) || + unconditionalSetStateFunctions.has(operand.identifier.id)) && + validateNoSetStateInRenderImpl(instr.value.loweredFunc.func, unconditionalSetStateFunctions).isErr()) { + unconditionalSetStateFunctions.add(instr.lvalue.identifier.id); + } + break; + } + case 'StartMemoize': { + CompilerError.invariant(activeManualMemoId === null, { + reason: 'Unexpected nested StartMemoize instructions', + loc: instr.value.loc, + }); + activeManualMemoId = instr.value.manualMemoId; + break; + } + case 'FinishMemoize': { + CompilerError.invariant(activeManualMemoId === instr.value.manualMemoId, { + reason: 'Expected FinishMemoize to align with previous StartMemoize instruction', + loc: instr.value.loc, + }); + activeManualMemoId = null; + break; + } + case 'CallExpression': { + const callee = instr.value.callee; + if (isSetStateType(callee.identifier) || + unconditionalSetStateFunctions.has(callee.identifier.id)) { + if (activeManualMemoId !== null) { + errors.push({ + reason: 'Calling setState from useMemo may trigger an infinite loop. (https://react.dev/reference/react/useState)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + else if (unconditionalBlocks.has(block.id)) { + errors.push({ + reason: 'This is an unconditional set state during render, which will trigger an infinite loop. (https://react.dev/reference/react/useState)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + } + break; + } + } + } + } + return errors.asResult(); +} + +function validatePreservedManualMemoization(fn) { + const state = { + errors: new CompilerError(), + manualMemoState: null, + }; + visitReactiveFunction(fn, new Visitor(), state); + return state.errors.asResult(); +} +var CompareDependencyResult; +(function (CompareDependencyResult) { + CompareDependencyResult[CompareDependencyResult["Ok"] = 0] = "Ok"; + CompareDependencyResult[CompareDependencyResult["RootDifference"] = 1] = "RootDifference"; + CompareDependencyResult[CompareDependencyResult["PathDifference"] = 2] = "PathDifference"; + CompareDependencyResult[CompareDependencyResult["Subpath"] = 3] = "Subpath"; + CompareDependencyResult[CompareDependencyResult["RefAccessDifference"] = 4] = "RefAccessDifference"; +})(CompareDependencyResult || (CompareDependencyResult = {})); +function compareDeps(inferred, source) { + const rootsEqual = (inferred.root.kind === 'Global' && + source.root.kind === 'Global' && + inferred.root.identifierName === source.root.identifierName) || + (inferred.root.kind === 'NamedLocal' && + source.root.kind === 'NamedLocal' && + inferred.root.value.identifier.id === source.root.value.identifier.id); + if (!rootsEqual) { + return CompareDependencyResult.RootDifference; + } + let isSubpath = true; + for (let i = 0; i < Math.min(inferred.path.length, source.path.length); i++) { + if (inferred.path[i].property !== source.path[i].property) { + isSubpath = false; + break; + } + else if (inferred.path[i].optional !== source.path[i].optional) { + return CompareDependencyResult.PathDifference; + } + } + if (isSubpath && + (source.path.length === inferred.path.length || + (inferred.path.length >= source.path.length && + !inferred.path.some(token => token.property === 'current')))) { + return CompareDependencyResult.Ok; + } + else { + if (isSubpath) { + if (source.path.some(token => token.property === 'current') || + inferred.path.some(token => token.property === 'current')) { + return CompareDependencyResult.RefAccessDifference; + } + else { + return CompareDependencyResult.Subpath; + } + } + else { + return CompareDependencyResult.PathDifference; + } + } +} +function validateInferredDep(dep, temporaries, declsWithinMemoBlock, validDepsInMemoBlock, errorState, memoLocation) { + var _a; + let normalizedDep; + const maybeNormalizedRoot = temporaries.get(dep.identifier.id); + if (maybeNormalizedRoot != null) { + normalizedDep = { + root: maybeNormalizedRoot.root, + path: [...maybeNormalizedRoot.path, ...dep.path], + }; + } + else { + CompilerError.invariant(((_a = dep.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named', { + reason: 'ValidatePreservedManualMemoization: expected scope dependency to be named', + loc: GeneratedSource, + suggestions: null, + }); + normalizedDep = { + root: { + kind: 'NamedLocal', + value: { + kind: 'Identifier', + identifier: dep.identifier, + loc: GeneratedSource, + effect: Effect.Read, + reactive: false, + }, + }, + path: [...dep.path], + }; + } + for (const decl of declsWithinMemoBlock) { + if (normalizedDep.root.kind === 'NamedLocal' && + decl === normalizedDep.root.value.identifier.declarationId) { + return; + } + } + for (const originalDep of validDepsInMemoBlock) { + const compareResult = compareDeps(normalizedDep, originalDep); + if (compareResult === CompareDependencyResult.Ok) { + return; + } + } + errorState.push({ + severity: ErrorSeverity.CannotPreserveMemoization, + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected', + description: null, + loc: memoLocation, + suggestions: null, + }); +} +class Visitor extends ReactiveFunctionVisitor { + constructor() { + super(...arguments); + this.scopes = new Set(); + this.prunedScopes = new Set(); + this.temporaries = new Map(); + } + recordDepsInValue(value, state) { + var _a, _b; + switch (value.kind) { + case 'SequenceExpression': { + for (const instr of value.instructions) { + this.visitInstruction(instr, state); + } + const result = this.recordDepsInValue(value.value, state); + return result; + } + case 'OptionalExpression': { + return this.recordDepsInValue(value.value, state); + } + case 'ConditionalExpression': { + this.recordDepsInValue(value.test, state); + this.recordDepsInValue(value.consequent, state); + this.recordDepsInValue(value.alternate, state); + return null; + } + case 'LogicalExpression': { + this.recordDepsInValue(value.left, state); + this.recordDepsInValue(value.right, state); + return null; + } + default: { + const dep = collectMaybeMemoDependencies(value, this.temporaries, false); + if (value.kind === 'StoreLocal' || value.kind === 'StoreContext') { + const storeTarget = value.lvalue.place; + (_a = state.manualMemoState) === null || _a === void 0 ? void 0 : _a.decls.add(storeTarget.identifier.declarationId); + if (((_b = storeTarget.identifier.name) === null || _b === void 0 ? void 0 : _b.kind) === 'named' && dep == null) { + const dep = { + root: { + kind: 'NamedLocal', + value: storeTarget, + }, + path: [], + }; + this.temporaries.set(storeTarget.identifier.id, dep); + return dep; + } + } + return dep; + } + } + } + recordTemporaries(instr, state) { + var _a; + const temporaries = this.temporaries; + const { lvalue, value } = instr; + const lvalId = lvalue === null || lvalue === void 0 ? void 0 : lvalue.identifier.id; + if (lvalId != null && temporaries.has(lvalId)) { + return; + } + const isNamedLocal = ((_a = lvalue === null || lvalue === void 0 ? void 0 : lvalue.identifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named'; + if (lvalue !== null && isNamedLocal && state.manualMemoState != null) { + state.manualMemoState.decls.add(lvalue.identifier.declarationId); + } + const maybeDep = this.recordDepsInValue(value, state); + if (lvalId != null) { + if (maybeDep != null) { + temporaries.set(lvalId, maybeDep); + } + else if (isNamedLocal) { + temporaries.set(lvalId, { + root: { + kind: 'NamedLocal', + value: Object.assign({}, instr.lvalue), + }, + path: [], + }); + } + } + } + visitScope(scopeBlock, state) { + this.traverseScope(scopeBlock, state); + if (state.manualMemoState != null && + state.manualMemoState.depsFromSource != null) { + for (const dep of scopeBlock.scope.dependencies) { + validateInferredDep(dep, this.temporaries, state.manualMemoState.decls, state.manualMemoState.depsFromSource, state.errors, state.manualMemoState.loc); + } + } + this.scopes.add(scopeBlock.scope.id); + for (const id of scopeBlock.scope.merged) { + this.scopes.add(id); + } + } + visitPrunedScope(scopeBlock, state) { + this.traversePrunedScope(scopeBlock, state); + this.prunedScopes.add(scopeBlock.scope.id); + } + visitInstruction(instruction, state) { + var _a, _b, _c; + this.recordTemporaries(instruction, state); + const value = instruction.value; + if (value.kind === 'StoreLocal' && + value.lvalue.kind === 'Reassign' && + state.manualMemoState != null) { + const ids = getOrInsertDefault(state.manualMemoState.reassignments, value.lvalue.place.identifier.declarationId, new Set()); + ids.add(value.value.identifier); + } + if (value.kind === 'StartMemoize') { + let depsFromSource = null; + if (value.deps != null) { + depsFromSource = value.deps; + } + CompilerError.invariant(state.manualMemoState == null, { + reason: 'Unexpected nested StartMemoize instructions', + description: `Bad manual memoization ids: ${(_a = state.manualMemoState) === null || _a === void 0 ? void 0 : _a.manualMemoId}, ${value.manualMemoId}`, + loc: value.loc, + suggestions: null, + }); + state.manualMemoState = { + loc: instruction.loc, + decls: new Set(), + depsFromSource, + manualMemoId: value.manualMemoId, + reassignments: new Map(), + }; + for (const { identifier, loc } of eachInstructionValueOperand(value)) { + if (identifier.scope != null && + !this.scopes.has(identifier.scope.id) && + !this.prunedScopes.has(identifier.scope.id)) { + state.errors.push({ + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This dependency may be mutated later, which could cause the value to change unexpectedly', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc, + suggestions: null, + }); + } + } + } + if (value.kind === 'FinishMemoize') { + CompilerError.invariant(state.manualMemoState != null && + state.manualMemoState.manualMemoId === value.manualMemoId, { + reason: 'Unexpected mismatch between StartMemoize and FinishMemoize', + description: `Encountered StartMemoize id=${(_b = state.manualMemoState) === null || _b === void 0 ? void 0 : _b.manualMemoId} followed by FinishMemoize id=${value.manualMemoId}`, + loc: value.loc, + suggestions: null, + }); + const reassignments = state.manualMemoState.reassignments; + state.manualMemoState = null; + if (!value.pruned) { + for (const { identifier, loc } of eachInstructionValueOperand(value)) { + let decls; + if (identifier.scope == null) { + decls = (_c = reassignments.get(identifier.declarationId)) !== null && _c !== void 0 ? _c : [identifier]; + } + else { + decls = [identifier]; + } + for (const identifier of decls) { + if (isUnmemoized(identifier, this.scopes)) { + state.errors.push({ + reason: 'React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.', + description: null, + severity: ErrorSeverity.CannotPreserveMemoization, + loc, + suggestions: null, + }); + } + } + } + } + } + } +} +function isUnmemoized(operand, scopes) { + return operand.scope != null && !scopes.has(operand.scope.id); +} + +function validateUseMemo(fn) { + const errors = new CompilerError(); + const useMemos = new Set(); + const react = new Set(); + const functions = new Map(); + for (const [, block] of fn.body.blocks) { + for (const { lvalue, value } of block.instructions) { + switch (value.kind) { + case 'LoadGlobal': { + if (value.binding.name === 'useMemo') { + useMemos.add(lvalue.identifier.id); + } + else if (value.binding.name === 'React') { + react.add(lvalue.identifier.id); + } + break; + } + case 'PropertyLoad': { + if (react.has(value.object.identifier.id)) { + if (value.property === 'useMemo') { + useMemos.add(lvalue.identifier.id); + } + } + break; + } + case 'FunctionExpression': { + functions.set(lvalue.identifier.id, value); + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = value.kind === 'CallExpression' + ? value.callee.identifier.id + : value.property.identifier.id; + const isUseMemo = useMemos.has(callee); + if (!isUseMemo || value.args.length === 0) { + continue; + } + const [arg] = value.args; + if (arg.kind !== 'Identifier') { + continue; + } + const body = functions.get(arg.identifier.id); + if (body === undefined) { + continue; + } + if (body.loweredFunc.func.params.length > 0) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'useMemo callbacks may not accept any arguments', + description: null, + loc: body.loc, + suggestions: null, + }); + } + if (body.loweredFunc.func.async || body.loweredFunc.func.generator) { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: 'useMemo callbacks may not be async or generator functions', + description: null, + loc: body.loc, + suggestions: null, + }); + } + break; + } + } + } + } + return errors.asResult(); +} + +function validateLocalsNotReassignedAfterRender(fn) { + const contextVariables = new Set(); + const reassignment = getContextReassignment(fn, contextVariables, false, false); + if (reassignment !== null) { + CompilerError.throwInvalidReact({ + reason: 'Reassigning a variable after render has completed can cause inconsistent behavior on subsequent renders. Consider using state instead', + description: reassignment.identifier.name !== null && + reassignment.identifier.name.kind === 'named' + ? `Variable \`${reassignment.identifier.name.value}\` cannot be reassigned after render` + : '', + loc: reassignment.loc, + }); + } +} +function getContextReassignment(fn, contextVariables, isFunctionExpression, isAsync) { + const reassigningFunctions = new Map(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { lvalue, value } = instr; + switch (value.kind) { + case 'FunctionExpression': + case 'ObjectMethod': { + let reassignment = getContextReassignment(value.loweredFunc.func, contextVariables, true, isAsync || value.loweredFunc.func.async); + if (reassignment === null) { + for (const operand of eachInstructionValueOperand(value)) { + const reassignmentFromOperand = reassigningFunctions.get(operand.identifier.id); + if (reassignmentFromOperand !== undefined) { + reassignment = reassignmentFromOperand; + break; + } + } + } + if (reassignment !== null) { + if (isAsync || value.loweredFunc.func.async) { + CompilerError.throwInvalidReact({ + reason: 'Reassigning a variable in an async function can cause inconsistent behavior on subsequent renders. Consider using state instead', + description: reassignment.identifier.name !== null && + reassignment.identifier.name.kind === 'named' + ? `Variable \`${reassignment.identifier.name.value}\` cannot be reassigned after render` + : '', + loc: reassignment.loc, + }); + } + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'StoreLocal': { + const reassignment = reassigningFunctions.get(value.value.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(value.lvalue.place.identifier.id, reassignment); + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'LoadLocal': { + const reassignment = reassigningFunctions.get(value.place.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + case 'DeclareContext': { + if (!isFunctionExpression) { + contextVariables.add(value.lvalue.place.identifier.id); + } + break; + } + case 'StoreContext': { + if (isFunctionExpression) { + if (contextVariables.has(value.lvalue.place.identifier.id)) { + return value.lvalue.place; + } + } + else { + contextVariables.add(value.lvalue.place.identifier.id); + } + const reassignment = reassigningFunctions.get(value.value.identifier.id); + if (reassignment !== undefined) { + reassigningFunctions.set(value.lvalue.place.identifier.id, reassignment); + reassigningFunctions.set(lvalue.identifier.id, reassignment); + } + break; + } + default: { + let operands = eachInstructionValueOperand(value); + if (value.kind === 'CallExpression') { + const signature = getFunctionCallSignature(fn.env, value.callee.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.callee]; + } + } + else if (value.kind === 'MethodCall') { + const signature = getFunctionCallSignature(fn.env, value.property.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.receiver, value.property]; + } + } + else if (value.kind === 'TaggedTemplateExpression') { + const signature = getFunctionCallSignature(fn.env, value.tag.identifier.type); + if (signature === null || signature === void 0 ? void 0 : signature.noAlias) { + operands = [value.tag]; + } + } + for (const operand of operands) { + CompilerError.invariant(operand.effect !== Effect.Unknown, { + reason: `Expected effects to be inferred prior to ValidateLocalsNotReassignedAfterRender`, + loc: operand.loc, + }); + const reassignment = reassigningFunctions.get(operand.identifier.id); + if (reassignment !== undefined) { + if (operand.effect === Effect.Freeze) { + return reassignment; + } + else { + for (const lval of eachInstructionLValue(instr)) { + reassigningFunctions.set(lval.identifier.id, reassignment); + } + } + } + } + break; + } + } + } + for (const operand of eachTerminalOperand(block.terminal)) { + const reassignment = reassigningFunctions.get(operand.identifier.id); + if (reassignment !== undefined) { + return reassignment; + } + } + } + return null; +} + +function outlineFunctions(fn, fbtOperands) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'FunctionExpression' || + value.kind === 'ObjectMethod') { + outlineFunctions(value.loweredFunc.func, fbtOperands); + } + if (value.kind === 'FunctionExpression' && + value.loweredFunc.func.context.length === 0 && + value.loweredFunc.func.id === null && + !fbtOperands.has(lvalue.identifier.id)) { + const loweredFunc = value.loweredFunc.func; + const id = fn.env.generateGloballyUniqueIdentifierName(loweredFunc.id); + loweredFunc.id = id.value; + fn.env.outlineFunction(loweredFunc, null); + instr.value = { + kind: 'LoadGlobal', + binding: { + kind: 'Global', + name: id.value, + }, + loc: value.loc, + }; + } + } + } +} + +function propagatePhiTypes(fn) { + const propagated = new Set(); + for (const [, block] of fn.body.blocks) { + for (const phi of block.phis) { + if (phi.place.identifier.type.kind !== 'Type' || + phi.place.identifier.name !== null) { + continue; + } + let type = null; + for (const [, operand] of phi.operands) { + if (type === null) { + type = operand.identifier.type; + } + else if (!typeEquals(type, operand.identifier.type)) { + type = null; + break; + } + } + if (type !== null) { + phi.place.identifier.type = type; + propagated.add(phi.place.identifier.id); + } + } + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'StoreLocal': { + const lvalue = value.lvalue.place; + if (propagated.has(value.value.identifier.id) && + lvalue.identifier.type.kind === 'Type' && + lvalue.identifier.name === null) { + lvalue.identifier.type = value.value.identifier.type; + propagated.add(lvalue.identifier.id); + } + } + } + } + } +} + +function lowerContextAccess(fn, loweredContextCalleeConfig) { + const contextAccess = new Map(); + const contextKeys = new Map(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'CallExpression' && + isUseContextHookType(value.callee.identifier)) { + contextAccess.set(lvalue.identifier.id, value); + continue; + } + if (value.kind !== 'Destructure') { + continue; + } + const destructureId = value.value.identifier.id; + if (!contextAccess.has(destructureId)) { + continue; + } + const keys = getContextKeys(value); + if (keys === null) { + return; + } + if (contextKeys.has(destructureId)) { + return; + } + else { + contextKeys.set(destructureId, keys); + } + } + } + let importLoweredContextCallee = null; + if (contextAccess.size > 0 && contextKeys.size > 0) { + for (const [, block] of fn.body.blocks) { + let nextInstructions = null; + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + const { lvalue, value } = instr; + if (value.kind === 'CallExpression' && + isUseContextHookType(value.callee.identifier) && + contextKeys.has(lvalue.identifier.id)) { + importLoweredContextCallee !== null && importLoweredContextCallee !== void 0 ? importLoweredContextCallee : (importLoweredContextCallee = fn.env.programContext.addImportSpecifier(loweredContextCalleeConfig)); + const loweredContextCalleeInstr = emitLoadLoweredContextCallee(fn.env, importLoweredContextCallee); + if (nextInstructions === null) { + nextInstructions = block.instructions.slice(0, i); + } + nextInstructions.push(loweredContextCalleeInstr); + const keys = contextKeys.get(lvalue.identifier.id); + const selectorFnInstr = emitSelectorFn(fn.env, keys); + nextInstructions.push(selectorFnInstr); + const lowerContextCallId = loweredContextCalleeInstr.lvalue; + value.callee = lowerContextCallId; + const selectorFn = selectorFnInstr.lvalue; + value.args.push(selectorFn); + } + if (nextInstructions) { + nextInstructions.push(instr); + } + } + if (nextInstructions) { + block.instructions = nextInstructions; + } + } + markInstructionIds(fn.body); + inferTypes(fn); + } +} +function emitLoadLoweredContextCallee(env, importedLowerContextCallee) { + const loadGlobal = { + kind: 'LoadGlobal', + binding: Object.assign({}, importedLowerContextCallee), + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, GeneratedSource), + value: loadGlobal, + }; +} +function getContextKeys(value) { + const keys = []; + const pattern = value.lvalue.pattern; + switch (pattern.kind) { + case 'ArrayPattern': { + return null; + } + case 'ObjectPattern': { + for (const place of pattern.properties) { + if (place.kind !== 'ObjectProperty' || + place.type !== 'property' || + place.key.kind !== 'identifier' || + place.place.identifier.name === null || + place.place.identifier.name.kind !== 'named') { + return null; + } + keys.push(place.key.name); + } + return keys; + } + } +} +function emitPropertyLoad(env, obj, property) { + const loadObj = { + kind: 'LoadLocal', + place: obj, + loc: GeneratedSource, + }; + const object = createTemporaryPlace(env, GeneratedSource); + const loadLocalInstr = { + lvalue: object, + value: loadObj, + id: makeInstructionId(0), + loc: GeneratedSource, + }; + const loadProp = { + kind: 'PropertyLoad', + object, + property: makePropertyLiteral(property), + loc: GeneratedSource, + }; + const element = createTemporaryPlace(env, GeneratedSource); + const loadPropInstr = { + lvalue: element, + value: loadProp, + id: makeInstructionId(0), + loc: GeneratedSource, + }; + return { + instructions: [loadLocalInstr, loadPropInstr], + element: element, + }; +} +function emitSelectorFn(env, keys) { + const obj = createTemporaryPlace(env, GeneratedSource); + promoteTemporary(obj.identifier); + const instr = []; + const elements = []; + for (const key of keys) { + const { instructions, element: prop } = emitPropertyLoad(env, obj, key); + instr.push(...instructions); + elements.push(prop); + } + const arrayInstr = emitArrayInstr(elements, env); + instr.push(arrayInstr); + const block = { + kind: 'block', + id: makeBlockId(0), + instructions: instr, + terminal: { + id: makeInstructionId(0), + kind: 'return', + loc: GeneratedSource, + value: arrayInstr.lvalue, + }, + preds: new Set(), + phis: new Set(), + }; + const fn = { + loc: GeneratedSource, + id: null, + fnType: 'Other', + env, + params: [obj], + returnTypeAnnotation: null, + returnType: makeType(), + context: [], + effects: null, + body: { + entry: block.id, + blocks: new Map([[block.id, block]]), + }, + generator: false, + async: false, + directives: [], + }; + reversePostorderBlocks(fn.body); + markInstructionIds(fn.body); + enterSSA(fn); + inferTypes(fn); + const fnInstr = { + id: makeInstructionId(0), + value: { + kind: 'FunctionExpression', + name: null, + loweredFunc: { + func: fn, + }, + type: 'ArrowFunctionExpression', + loc: GeneratedSource, + }, + lvalue: createTemporaryPlace(env, GeneratedSource), + loc: GeneratedSource, + }; + return fnInstr; +} +function emitArrayInstr(elements, env) { + const array = { + kind: 'ArrayExpression', + elements, + loc: GeneratedSource, + }; + const arrayLvalue = createTemporaryPlace(env, GeneratedSource); + const arrayInstr = { + id: makeInstructionId(0), + value: array, + lvalue: arrayLvalue, + loc: GeneratedSource, + }; + return arrayInstr; +} + +function validateNoSetStateInPassiveEffects(fn) { + const setStateFunctions = new Map(); + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (setStateFunctions.has(instr.value.place.identifier.id)) { + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.place); + } + break; + } + case 'StoreLocal': { + if (setStateFunctions.has(instr.value.value.identifier.id)) { + setStateFunctions.set(instr.value.lvalue.place.identifier.id, instr.value.value); + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.value); + } + break; + } + case 'FunctionExpression': { + if ([...eachInstructionValueOperand(instr.value)].some(operand => isSetStateType(operand.identifier) || + setStateFunctions.has(operand.identifier.id))) { + const callee = getSetStateCall(instr.value.loweredFunc.func, setStateFunctions); + if (callee !== null) { + setStateFunctions.set(instr.lvalue.identifier.id, callee); + } + } + break; + } + case 'MethodCall': + case 'CallExpression': { + const callee = instr.value.kind === 'MethodCall' + ? instr.value.receiver + : instr.value.callee; + if (isUseEffectHookType(callee.identifier)) { + const arg = instr.value.args[0]; + if (arg !== undefined && arg.kind === 'Identifier') { + const setState = setStateFunctions.get(arg.identifier.id); + if (setState !== undefined) { + errors.push({ + reason: 'Calling setState directly within a useEffect causes cascading renders and is not recommended. Consider alternatives to useEffect. (https://react.dev/learn/you-might-not-need-an-effect)', + description: null, + severity: ErrorSeverity.InvalidReact, + loc: setState.loc, + suggestions: null, + }); + } + } + } + break; + } + } + } + } + return errors.asResult(); +} +function getSetStateCall(fn, setStateFunctions) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + switch (instr.value.kind) { + case 'LoadLocal': { + if (setStateFunctions.has(instr.value.place.identifier.id)) { + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.place); + } + break; + } + case 'StoreLocal': { + if (setStateFunctions.has(instr.value.value.identifier.id)) { + setStateFunctions.set(instr.value.lvalue.place.identifier.id, instr.value.value); + setStateFunctions.set(instr.lvalue.identifier.id, instr.value.value); + } + break; + } + case 'CallExpression': { + const callee = instr.value.callee; + if (isSetStateType(callee.identifier) || + setStateFunctions.has(callee.identifier.id)) { + return callee; + } + } + } + } + } + return null; +} + +function validateNoJSXInTryStatement(fn) { + const activeTryBlocks = []; + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + retainWhere(activeTryBlocks, id => id !== block.id); + if (activeTryBlocks.length !== 0) { + for (const instr of block.instructions) { + const { value } = instr; + switch (value.kind) { + case 'JsxExpression': + case 'JsxFragment': { + errors.push({ + severity: ErrorSeverity.InvalidReact, + reason: `Unexpected JSX element within a try statement. To catch errors in rendering a given component, wrap that component in an error boundary. (https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary)`, + loc: value.loc, + }); + break; + } + } + } + } + if (block.terminal.kind === 'try') { + activeTryBlocks.push(block.terminal.handler); + } + } + return errors.asResult(); +} + +function outlineJSX(fn) { + const outlinedFns = []; + outlineJsxImpl(fn, outlinedFns); + for (const outlinedFn of outlinedFns) { + fn.env.outlineFunction(outlinedFn, 'Component'); + } +} +function outlineJsxImpl(fn, outlinedFns) { + const globals = new Map(); + function processAndOutlineJSX(state, rewriteInstr) { + if (state.jsx.length <= 1) { + return; + } + const result = process$1(fn, [...state.jsx].sort((a, b) => a.id - b.id), globals); + if (result) { + outlinedFns.push(result.fn); + rewriteInstr.set(state.jsx.at(0).id, result.instrs); + } + } + for (const [, block] of fn.body.blocks) { + const rewriteInstr = new Map(); + let state = { + jsx: [], + children: new Set(), + }; + for (let i = block.instructions.length - 1; i >= 0; i--) { + const instr = block.instructions[i]; + const { value, lvalue } = instr; + switch (value.kind) { + case 'LoadGlobal': { + globals.set(lvalue.identifier.id, instr); + break; + } + case 'FunctionExpression': { + outlineJsxImpl(value.loweredFunc.func, outlinedFns); + break; + } + case 'JsxExpression': { + if (!state.children.has(lvalue.identifier.id)) { + processAndOutlineJSX(state, rewriteInstr); + state = { + jsx: [], + children: new Set(), + }; + } + state.jsx.push(instr); + if (value.children) { + for (const child of value.children) { + state.children.add(child.identifier.id); + } + } + break; + } + case 'ArrayExpression': + case 'Await': + case 'BinaryExpression': + case 'CallExpression': + case 'ComputedDelete': + case 'ComputedLoad': + case 'ComputedStore': + case 'Debugger': + case 'DeclareContext': + case 'DeclareLocal': + case 'Destructure': + case 'FinishMemoize': + case 'GetIterator': + case 'IteratorNext': + case 'JSXText': + case 'JsxFragment': + case 'LoadContext': + case 'LoadLocal': + case 'MetaProperty': + case 'MethodCall': + case 'NewExpression': + case 'NextPropertyOf': + case 'ObjectExpression': + case 'ObjectMethod': + case 'PostfixUpdate': + case 'PrefixUpdate': + case 'Primitive': + case 'PropertyDelete': + case 'PropertyLoad': + case 'PropertyStore': + case 'RegExpLiteral': + case 'StartMemoize': + case 'StoreContext': + case 'StoreGlobal': + case 'StoreLocal': + case 'TaggedTemplateExpression': + case 'TemplateLiteral': + case 'TypeCastExpression': + case 'UnsupportedNode': + case 'UnaryExpression': { + break; + } + default: { + assertExhaustive$1(value, `Unexpected instruction: ${value}`); + } + } + } + processAndOutlineJSX(state, rewriteInstr); + if (rewriteInstr.size > 0) { + const newInstrs = []; + for (let i = 0; i < block.instructions.length; i++) { + const id = i + 1; + if (rewriteInstr.has(id)) { + const instrs = rewriteInstr.get(id); + newInstrs.push(...instrs); + } + else { + newInstrs.push(block.instructions[i]); + } + } + block.instructions = newInstrs; + } + deadCodeElimination(fn); + } +} +function process$1(fn, jsx, globals) { + if (fn.fnType === 'Component') { + return null; + } + const props = collectProps(fn.env, jsx); + if (!props) + return null; + const outlinedTag = fn.env.generateGloballyUniqueIdentifierName(null).value; + const newInstrs = emitOutlinedJsx(fn.env, jsx, props, outlinedTag); + if (!newInstrs) + return null; + const outlinedFn = emitOutlinedFn(fn.env, jsx, props, globals); + if (!outlinedFn) + return null; + outlinedFn.id = outlinedTag; + return { instrs: newInstrs, fn: outlinedFn }; +} +function collectProps(env, instructions) { + let id = 1; + function generateName(oldName) { + let newName = oldName; + while (seen.has(newName)) { + newName = `${oldName}${id++}`; + } + seen.add(newName); + env.programContext.addNewReference(newName); + return newName; + } + const attributes = []; + const jsxIds = new Set(instructions.map(i => i.lvalue.identifier.id)); + const seen = new Set(); + for (const instr of instructions) { + const { value } = instr; + for (const at of value.props) { + if (at.kind === 'JsxSpreadAttribute') { + return null; + } + if (at.kind === 'JsxAttribute') { + const newName = generateName(at.name); + attributes.push({ + originalName: at.name, + newName, + place: at.place, + }); + } + } + if (value.children) { + for (const child of value.children) { + if (jsxIds.has(child.identifier.id)) { + continue; + } + promoteTemporary(child.identifier); + const newName = generateName('t'); + attributes.push({ + originalName: child.identifier.name.value, + newName: newName, + place: child, + }); + } + } + } + return attributes; +} +function emitOutlinedJsx(env, instructions, outlinedProps, outlinedTag) { + const props = outlinedProps.map(p => ({ + kind: 'JsxAttribute', + name: p.newName, + place: p.place, + })); + const loadJsx = { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: createTemporaryPlace(env, GeneratedSource), + value: { + kind: 'LoadGlobal', + binding: { + kind: 'ModuleLocal', + name: outlinedTag, + }, + loc: GeneratedSource, + }, + }; + promoteTemporaryJsxTag(loadJsx.lvalue.identifier); + const jsxExpr = { + id: makeInstructionId(0), + loc: GeneratedSource, + lvalue: instructions.at(-1).lvalue, + value: { + kind: 'JsxExpression', + tag: Object.assign({}, loadJsx.lvalue), + props, + children: null, + loc: GeneratedSource, + openingLoc: GeneratedSource, + closingLoc: GeneratedSource, + }, + }; + return [loadJsx, jsxExpr]; +} +function emitOutlinedFn(env, jsx, oldProps, globals) { + const instructions = []; + const oldToNewProps = createOldToNewPropsMapping(env, oldProps); + const propsObj = createTemporaryPlace(env, GeneratedSource); + promoteTemporary(propsObj.identifier); + const destructurePropsInstr = emitDestructureProps(env, propsObj, oldToNewProps); + instructions.push(destructurePropsInstr); + const updatedJsxInstructions = emitUpdatedJsx(jsx, oldToNewProps); + const loadGlobalInstrs = emitLoadGlobals(jsx, globals); + if (!loadGlobalInstrs) { + return null; + } + instructions.push(...loadGlobalInstrs); + instructions.push(...updatedJsxInstructions); + const block = { + kind: 'block', + id: makeBlockId(0), + instructions, + terminal: { + id: makeInstructionId(0), + kind: 'return', + loc: GeneratedSource, + value: instructions.at(-1).lvalue, + }, + preds: new Set(), + phis: new Set(), + }; + const fn = { + loc: GeneratedSource, + id: null, + fnType: 'Other', + env, + params: [propsObj], + returnTypeAnnotation: null, + returnType: makeType(), + context: [], + effects: null, + body: { + entry: block.id, + blocks: new Map([[block.id, block]]), + }, + generator: false, + async: false, + directives: [], + }; + return fn; +} +function emitLoadGlobals(jsx, globals) { + const instructions = []; + for (const { value } of jsx) { + if (value.tag.kind === 'Identifier') { + const loadGlobalInstr = globals.get(value.tag.identifier.id); + if (!loadGlobalInstr) { + return null; + } + instructions.push(loadGlobalInstr); + } + } + return instructions; +} +function emitUpdatedJsx(jsx, oldToNewProps) { + const newInstrs = []; + const jsxIds = new Set(jsx.map(i => i.lvalue.identifier.id)); + for (const instr of jsx) { + const { value } = instr; + const newProps = []; + for (const prop of value.props) { + invariant(prop.kind === 'JsxAttribute', `Expected only attributes but found ${prop.kind}`); + if (prop.name === 'key') { + continue; + } + const newProp = oldToNewProps.get(prop.place.identifier.id); + invariant(newProp !== undefined, `Expected a new property for ${printIdentifier(prop.place.identifier)}`); + newProps.push({ + kind: 'JsxAttribute', + name: newProp.originalName, + place: newProp.place, + }); + } + let newChildren = null; + if (value.children) { + newChildren = []; + for (const child of value.children) { + if (jsxIds.has(child.identifier.id)) { + newChildren.push(Object.assign({}, child)); + continue; + } + const newChild = oldToNewProps.get(child.identifier.id); + invariant(newChild !== undefined, `Expected a new prop for ${printIdentifier(child.identifier)}`); + newChildren.push(Object.assign({}, newChild.place)); + } + } + newInstrs.push(Object.assign(Object.assign({}, instr), { value: Object.assign(Object.assign({}, value), { props: newProps, children: newChildren }) })); + } + return newInstrs; +} +function createOldToNewPropsMapping(env, oldProps) { + const oldToNewProps = new Map(); + for (const oldProp of oldProps) { + if (oldProp.originalName === 'key') { + continue; + } + const newProp = Object.assign(Object.assign({}, oldProp), { place: createTemporaryPlace(env, GeneratedSource) }); + newProp.place.identifier.name = makeIdentifierName(oldProp.newName); + oldToNewProps.set(oldProp.place.identifier.id, newProp); + } + return oldToNewProps; +} +function emitDestructureProps(env, propsObj, oldToNewProps) { + const properties = []; + for (const [_, prop] of oldToNewProps) { + properties.push({ + kind: 'ObjectProperty', + key: { + kind: 'string', + name: prop.newName, + }, + type: 'property', + place: prop.place, + }); + } + const destructurePropsInstr = { + id: makeInstructionId(0), + lvalue: createTemporaryPlace(env, GeneratedSource), + loc: GeneratedSource, + value: { + kind: 'Destructure', + lvalue: { + pattern: { + kind: 'ObjectPattern', + properties, + }, + kind: InstructionKind.Let, + }, + loc: GeneratedSource, + value: propsObj, + }, + }; + return destructurePropsInstr; +} + +function optimizePropsMethodCalls(fn) { + for (const [, block] of fn.body.blocks) { + for (let i = 0; i < block.instructions.length; i++) { + const instr = block.instructions[i]; + if (instr.value.kind === 'MethodCall' && + isPropsType(instr.value.receiver.identifier)) { + instr.value = { + kind: 'CallExpression', + callee: instr.value.property, + args: instr.value.args, + loc: instr.value.loc, + }; + } + } + } +} + +var _Context_env, _Context_errors, _Context_callExpressions, _Context_functionExpressions, _Context_loadLocals, _Context_fireCalleesToFireFunctions, _Context_calleesWithInsertedFire, _Context_capturedCalleeIdentifierIds, _Context_inUseEffectLambda, _Context_loadGlobalInstructionIds, _Context_arrayExpressions; +const CANNOT_COMPILE_FIRE = 'Cannot compile `fire`'; +function transformFire(fn) { + const context = new Context(fn.env); + replaceFireFunctions(fn, context); + if (!context.hasErrors()) { + ensureNoMoreFireUses(fn, context); + } + context.throwIfErrorsFound(); +} +function replaceFireFunctions(fn, context) { + let importedUseFire = null; + let hasRewrite = false; + for (const [, block] of fn.body.blocks) { + const rewriteInstrs = new Map(); + const deleteInstrs = new Set(); + for (const instr of block.instructions) { + const { value, lvalue } = instr; + if (value.kind === 'CallExpression' && + isUseEffectHookType(value.callee.identifier) && + value.args.length > 0 && + value.args[0].kind === 'Identifier') { + const lambda = context.getFunctionExpression(value.args[0].identifier.id); + if (lambda != null) { + const capturedCallees = visitFunctionExpressionAndPropagateFireDependencies(lambda, context, true); + const newInstrs = []; + for (const [fireCalleePlace, fireCalleeInfo,] of capturedCallees.entries()) { + if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) { + context.addCalleeWithInsertedFire(fireCalleePlace); + importedUseFire !== null && importedUseFire !== void 0 ? importedUseFire : (importedUseFire = fn.env.programContext.addImportSpecifier({ + source: fn.env.programContext.reactRuntimeModule, + importSpecifierName: USE_FIRE_FUNCTION_NAME, + })); + const loadUseFireInstr = makeLoadUseFireInstruction(fn.env, importedUseFire); + const loadFireCalleeInstr = makeLoadFireCalleeInstruction(fn.env, fireCalleeInfo.capturedCalleeIdentifier); + const callUseFireInstr = makeCallUseFireInstruction(fn.env, loadUseFireInstr.lvalue, loadFireCalleeInstr.lvalue); + const storeUseFireInstr = makeStoreUseFireInstruction(fn.env, callUseFireInstr.lvalue, fireCalleeInfo.fireFunctionBinding); + newInstrs.push(loadUseFireInstr, loadFireCalleeInstr, callUseFireInstr, storeUseFireInstr); + const loadUseEffectInstrId = context.getLoadGlobalInstrId(value.callee.identifier.id); + if (loadUseEffectInstrId == null) { + context.pushError({ + loc: value.loc, + description: null, + severity: ErrorSeverity.Invariant, + reason: '[InsertFire] No LoadGlobal found for useEffect call', + suggestions: null, + }); + continue; + } + rewriteInstrs.set(loadUseEffectInstrId, newInstrs); + } + } + ensureNoRemainingCalleeCaptures(lambda.loweredFunc.func, context, capturedCallees); + if (value.args.length > 1 && + value.args[1] != null && + value.args[1].kind === 'Identifier') { + const depArray = value.args[1]; + const depArrayExpression = context.getArrayExpression(depArray.identifier.id); + if (depArrayExpression != null) { + for (const dependency of depArrayExpression.elements) { + if (dependency.kind === 'Identifier') { + const loadOfDependency = context.getLoadLocalInstr(dependency.identifier.id); + if (loadOfDependency != null) { + const replacedDepArrayItem = capturedCallees.get(loadOfDependency.place.identifier.id); + if (replacedDepArrayItem != null) { + loadOfDependency.place = + replacedDepArrayItem.fireFunctionBinding; + } + } + } + } + } + else { + context.pushError({ + loc: value.args[1].loc, + description: 'You must use an array literal for an effect dependency array when that effect uses `fire()`', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else if (value.args.length > 1 && value.args[1].kind === 'Spread') { + context.pushError({ + loc: value.args[1].place.loc, + description: 'You must use an array literal for an effect dependency array when that effect uses `fire()`', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + } + else if (value.kind === 'CallExpression' && + value.callee.identifier.type.kind === 'Function' && + value.callee.identifier.type.shapeId === BuiltInFireId && + context.inUseEffectLambda()) { + if (value.args.length === 1 && value.args[0].kind === 'Identifier') { + const callExpr = context.getCallExpression(value.args[0].identifier.id); + if (callExpr != null) { + const calleeId = callExpr.callee.identifier.id; + const loadLocal = context.getLoadLocalInstr(calleeId); + if (loadLocal == null) { + context.pushError({ + loc: value.loc, + description: null, + severity: ErrorSeverity.Invariant, + reason: '[InsertFire] No loadLocal found for fire call argument', + suggestions: null, + }); + continue; + } + const fireFunctionBinding = context.getOrGenerateFireFunctionBinding(loadLocal.place, value.loc); + loadLocal.place = Object.assign({}, fireFunctionBinding); + deleteInstrs.add(instr.id); + } + else { + context.pushError({ + loc: value.loc, + description: '`fire()` can only receive a function call such as `fire(fn(a,b)). Method calls and other expressions are not allowed', + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else { + let description = 'fire() can only take in a single call expression as an argument'; + if (value.args.length === 0) { + description += ' but received none'; + } + else if (value.args.length > 1) { + description += ' but received multiple arguments'; + } + else if (value.args[0].kind === 'Spread') { + description += ' but received a spread argument'; + } + context.pushError({ + loc: value.loc, + description, + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } + else if (value.kind === 'CallExpression') { + context.addCallExpression(lvalue.identifier.id, value); + } + else if (value.kind === 'FunctionExpression' && + context.inUseEffectLambda()) { + visitFunctionExpressionAndPropagateFireDependencies(value, context, false); + } + else if (value.kind === 'FunctionExpression') { + context.addFunctionExpression(lvalue.identifier.id, value); + } + else if (value.kind === 'LoadLocal') { + context.addLoadLocalInstr(lvalue.identifier.id, value); + } + else if (value.kind === 'LoadGlobal' && + value.binding.kind === 'ImportSpecifier' && + value.binding.module === 'react' && + value.binding.imported === 'fire' && + context.inUseEffectLambda()) { + deleteInstrs.add(instr.id); + } + else if (value.kind === 'LoadGlobal') { + context.addLoadGlobalInstrId(lvalue.identifier.id, instr.id); + } + else if (value.kind === 'ArrayExpression') { + context.addArrayExpression(lvalue.identifier.id, value); + } + } + block.instructions = rewriteInstructions(rewriteInstrs, block.instructions); + block.instructions = deleteInstructions(deleteInstrs, block.instructions); + if (rewriteInstrs.size > 0 || deleteInstrs.size > 0) { + hasRewrite = true; + fn.env.hasFireRewrite = true; + } + } + if (hasRewrite) { + markInstructionIds(fn.body); + } +} +function visitFunctionExpressionAndPropagateFireDependencies(fnExpr, context, enteringUseEffect) { + let withScope = enteringUseEffect + ? context.withUseEffectLambdaScope.bind(context) + : context.withFunctionScope.bind(context); + const calleesCapturedByFnExpression = withScope(() => replaceFireFunctions(fnExpr.loweredFunc.func, context)); + for (let contextIdx = 0; contextIdx < fnExpr.loweredFunc.func.context.length; contextIdx++) { + const contextItem = fnExpr.loweredFunc.func.context[contextIdx]; + const replacedCallee = calleesCapturedByFnExpression.get(contextItem.identifier.id); + if (replacedCallee != null) { + fnExpr.loweredFunc.func.context[contextIdx] = Object.assign({}, replacedCallee.fireFunctionBinding); + } + } + context.mergeCalleesFromInnerScope(calleesCapturedByFnExpression); + return calleesCapturedByFnExpression; +} +function* eachReachablePlace(fn) { + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + if (instr.value.kind === 'FunctionExpression' || + instr.value.kind === 'ObjectMethod') { + yield* eachReachablePlace(instr.value.loweredFunc.func); + } + else { + yield* eachInstructionOperand(instr); + } + } + } +} +function ensureNoRemainingCalleeCaptures(fn, context, capturedCallees) { + var _a; + for (const place of eachReachablePlace(fn)) { + const calleeInfo = capturedCallees.get(place.identifier.id); + if (calleeInfo != null) { + const calleeName = ((_a = calleeInfo.capturedCalleeIdentifier.name) === null || _a === void 0 ? void 0 : _a.kind) === 'named' + ? calleeInfo.capturedCalleeIdentifier.name.value + : ''; + context.pushError({ + loc: place.loc, + description: `All uses of ${calleeName} must be either used with a fire() call in \ +this effect or not used with a fire() call at all. ${calleeName} was used with fire() on line \ +${printSourceLocationLine(calleeInfo.fireLoc)} in this effect`, + severity: ErrorSeverity.InvalidReact, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } +} +function ensureNoMoreFireUses(fn, context) { + for (const place of eachReachablePlace(fn)) { + if (place.identifier.type.kind === 'Function' && + place.identifier.type.shapeId === BuiltInFireId) { + context.pushError({ + loc: place.identifier.loc, + description: 'Cannot use `fire` outside of a useEffect function', + severity: ErrorSeverity.Invariant, + reason: CANNOT_COMPILE_FIRE, + suggestions: null, + }); + } + } +} +function makeLoadUseFireInstruction(env, importedLoadUseFire) { + const useFirePlace = createTemporaryPlace(env, GeneratedSource); + useFirePlace.effect = Effect.Read; + useFirePlace.identifier.type = DefaultNonmutatingHook; + const instrValue = { + kind: 'LoadGlobal', + binding: Object.assign({}, importedLoadUseFire), + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + value: instrValue, + lvalue: Object.assign({}, useFirePlace), + loc: GeneratedSource, + }; +} +function makeLoadFireCalleeInstruction(env, fireCalleeIdentifier) { + const loadedFireCallee = createTemporaryPlace(env, GeneratedSource); + const fireCallee = { + kind: 'Identifier', + identifier: fireCalleeIdentifier, + reactive: false, + effect: Effect.Unknown, + loc: fireCalleeIdentifier.loc, + }; + return { + id: makeInstructionId(0), + value: { + kind: 'LoadLocal', + loc: GeneratedSource, + place: Object.assign({}, fireCallee), + }, + lvalue: Object.assign({}, loadedFireCallee), + loc: GeneratedSource, + }; +} +function makeCallUseFireInstruction(env, useFirePlace, argPlace) { + const useFireCallResultPlace = createTemporaryPlace(env, GeneratedSource); + useFireCallResultPlace.effect = Effect.Read; + const useFireCall = { + kind: 'CallExpression', + callee: Object.assign({}, useFirePlace), + args: [argPlace], + loc: GeneratedSource, + }; + return { + id: makeInstructionId(0), + value: useFireCall, + lvalue: Object.assign({}, useFireCallResultPlace), + loc: GeneratedSource, + }; +} +function makeStoreUseFireInstruction(env, useFireCallResultPlace, fireFunctionBindingPlace) { + promoteTemporary(fireFunctionBindingPlace.identifier); + const fireFunctionBindingLValuePlace = createTemporaryPlace(env, GeneratedSource); + return { + id: makeInstructionId(0), + value: { + kind: 'StoreLocal', + lvalue: { + kind: InstructionKind.Const, + place: Object.assign({}, fireFunctionBindingPlace), + }, + value: Object.assign({}, useFireCallResultPlace), + type: null, + loc: GeneratedSource, + }, + lvalue: fireFunctionBindingLValuePlace, + loc: GeneratedSource, + }; +} +class Context { + constructor(env) { + _Context_env.set(this, void 0); + _Context_errors.set(this, new CompilerError()); + _Context_callExpressions.set(this, new Map()); + _Context_functionExpressions.set(this, new Map()); + _Context_loadLocals.set(this, new Map()); + _Context_fireCalleesToFireFunctions.set(this, new Map()); + _Context_calleesWithInsertedFire.set(this, new Set()); + _Context_capturedCalleeIdentifierIds.set(this, new Map()); + _Context_inUseEffectLambda.set(this, false); + _Context_loadGlobalInstructionIds.set(this, new Map()); + _Context_arrayExpressions.set(this, new Map()); + __classPrivateFieldSet(this, _Context_env, env, "f"); + } + pushError(error) { + __classPrivateFieldGet(this, _Context_errors, "f").push(error); + } + withFunctionScope(fn) { + fn(); + return __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f"); + } + withUseEffectLambdaScope(fn) { + const capturedCalleeIdentifierIds = __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f"); + const inUseEffectLambda = __classPrivateFieldGet(this, _Context_inUseEffectLambda, "f"); + __classPrivateFieldSet(this, _Context_capturedCalleeIdentifierIds, new Map(), "f"); + __classPrivateFieldSet(this, _Context_inUseEffectLambda, true, "f"); + const resultCapturedCalleeIdentifierIds = this.withFunctionScope(fn); + __classPrivateFieldSet(this, _Context_capturedCalleeIdentifierIds, capturedCalleeIdentifierIds, "f"); + __classPrivateFieldSet(this, _Context_inUseEffectLambda, inUseEffectLambda, "f"); + return resultCapturedCalleeIdentifierIds; + } + addCallExpression(id, callExpr) { + __classPrivateFieldGet(this, _Context_callExpressions, "f").set(id, callExpr); + } + getCallExpression(id) { + return __classPrivateFieldGet(this, _Context_callExpressions, "f").get(id); + } + addLoadLocalInstr(id, loadLocal) { + __classPrivateFieldGet(this, _Context_loadLocals, "f").set(id, loadLocal); + } + getLoadLocalInstr(id) { + return __classPrivateFieldGet(this, _Context_loadLocals, "f").get(id); + } + getOrGenerateFireFunctionBinding(callee, fireLoc) { + const fireFunctionBinding = getOrInsertWith(__classPrivateFieldGet(this, _Context_fireCalleesToFireFunctions, "f"), callee.identifier.id, () => createTemporaryPlace(__classPrivateFieldGet(this, _Context_env, "f"), GeneratedSource)); + fireFunctionBinding.identifier.type = { + kind: 'Function', + shapeId: BuiltInFireFunctionId, + return: { kind: 'Poly' }, + isConstructor: false, + }; + __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f").set(callee.identifier.id, { + fireFunctionBinding, + capturedCalleeIdentifier: callee.identifier, + fireLoc, + }); + return fireFunctionBinding; + } + mergeCalleesFromInnerScope(innerCallees) { + for (const [id, calleeInfo] of innerCallees.entries()) { + __classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, "f").set(id, calleeInfo); + } + } + addCalleeWithInsertedFire(id) { + __classPrivateFieldGet(this, _Context_calleesWithInsertedFire, "f").add(id); + } + hasCalleeWithInsertedFire(id) { + return __classPrivateFieldGet(this, _Context_calleesWithInsertedFire, "f").has(id); + } + inUseEffectLambda() { + return __classPrivateFieldGet(this, _Context_inUseEffectLambda, "f"); + } + addFunctionExpression(id, fn) { + __classPrivateFieldGet(this, _Context_functionExpressions, "f").set(id, fn); + } + getFunctionExpression(id) { + return __classPrivateFieldGet(this, _Context_functionExpressions, "f").get(id); + } + addLoadGlobalInstrId(id, instrId) { + __classPrivateFieldGet(this, _Context_loadGlobalInstructionIds, "f").set(id, instrId); + } + getLoadGlobalInstrId(id) { + return __classPrivateFieldGet(this, _Context_loadGlobalInstructionIds, "f").get(id); + } + addArrayExpression(id, array) { + __classPrivateFieldGet(this, _Context_arrayExpressions, "f").set(id, array); + } + getArrayExpression(id) { + return __classPrivateFieldGet(this, _Context_arrayExpressions, "f").get(id); + } + hasErrors() { + return __classPrivateFieldGet(this, _Context_errors, "f").hasErrors(); + } + throwIfErrorsFound() { + if (this.hasErrors()) + throw __classPrivateFieldGet(this, _Context_errors, "f"); + } +} +_Context_env = new WeakMap(), _Context_errors = new WeakMap(), _Context_callExpressions = new WeakMap(), _Context_functionExpressions = new WeakMap(), _Context_loadLocals = new WeakMap(), _Context_fireCalleesToFireFunctions = new WeakMap(), _Context_calleesWithInsertedFire = new WeakMap(), _Context_capturedCalleeIdentifierIds = new WeakMap(), _Context_inUseEffectLambda = new WeakMap(), _Context_loadGlobalInstructionIds = new WeakMap(), _Context_arrayExpressions = new WeakMap(); +function deleteInstructions(deleteInstrs, instructions) { + if (deleteInstrs.size > 0) { + const newInstrs = instructions.filter(instr => !deleteInstrs.has(instr.id)); + return newInstrs; + } + return instructions; +} +function rewriteInstructions(rewriteInstrs, instructions) { + if (rewriteInstrs.size > 0) { + const newInstrs = []; + for (const instr of instructions) { + const newInstrsAtId = rewriteInstrs.get(instr.id); + if (newInstrsAtId != null) { + newInstrs.push(...newInstrsAtId, instr); + } + else { + newInstrs.push(instr); + } + } + return newInstrs; + } + return instructions; +} + +function validateNoImpureFunctionsInRender(fn) { + const errors = new CompilerError(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + const value = instr.value; + if (value.kind === 'MethodCall' || value.kind == 'CallExpression') { + const callee = value.kind === 'MethodCall' ? value.property : value.callee; + const signature = getFunctionCallSignature(fn.env, callee.identifier.type); + if (signature != null && signature.impure === true) { + errors.push({ + reason: 'Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)', + description: signature.canonicalName != null + ? `\`${signature.canonicalName}\` is an impure function whose results may change on every call` + : null, + severity: ErrorSeverity.InvalidReact, + loc: callee.loc, + suggestions: null, + }); + } + } + } + } + return errors.asResult(); +} + +function validateStaticComponents(fn) { + const error = new CompilerError(); + const knownDynamicComponents = new Map(); + for (const block of fn.body.blocks.values()) { + phis: for (const phi of block.phis) { + for (const operand of phi.operands.values()) { + const loc = knownDynamicComponents.get(operand.identifier.id); + if (loc != null) { + knownDynamicComponents.set(phi.place.identifier.id, loc); + continue phis; + } + } + } + for (const instr of block.instructions) { + const { lvalue, value } = instr; + switch (value.kind) { + case 'FunctionExpression': + case 'NewExpression': + case 'MethodCall': + case 'CallExpression': { + knownDynamicComponents.set(lvalue.identifier.id, value.loc); + break; + } + case 'LoadLocal': { + const loc = knownDynamicComponents.get(value.place.identifier.id); + if (loc != null) { + knownDynamicComponents.set(lvalue.identifier.id, loc); + } + break; + } + case 'StoreLocal': { + const loc = knownDynamicComponents.get(value.value.identifier.id); + if (loc != null) { + knownDynamicComponents.set(lvalue.identifier.id, loc); + knownDynamicComponents.set(value.lvalue.place.identifier.id, loc); + } + break; + } + case 'JsxExpression': { + if (value.tag.kind === 'Identifier') { + const location = knownDynamicComponents.get(value.tag.identifier.id); + if (location != null) { + error.push({ + reason: `Components created during render will reset their state each time they are created. Declare components outside of render. `, + severity: ErrorSeverity.InvalidReact, + loc: value.tag.loc, + description: null, + suggestions: null, + }); + error.push({ + reason: `The component may be created during render`, + severity: ErrorSeverity.InvalidReact, + loc: location, + description: null, + suggestions: null, + }); + } + } + } + } + } + } + return error.asResult(); +} + +function run(func, config, fnType, mode, programContext, logger, filename, code) { + var _a, _b; + const contextIdentifiers = findContextIdentifiers(func); + const env = new Environment(func.scope, fnType, mode, config, contextIdentifiers, logger, filename, code, programContext); + (_b = (_a = env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, { + kind: 'debug', + name: 'EnvironmentConfig', + value: prettyFormat(env.config), + }); + return runWithEnvironment(func, env); +} +function runWithEnvironment(func, env) { + const log = (value) => { + var _a, _b; + (_b = (_a = env.logger) === null || _a === void 0 ? void 0 : _a.debugLogIRs) === null || _b === void 0 ? void 0 : _b.call(_a, value); + }; + const hir = lower$1(func, env).unwrap(); + log({ kind: 'hir', name: 'HIR', value: hir }); + pruneMaybeThrows(hir); + log({ kind: 'hir', name: 'PruneMaybeThrows', value: hir }); + validateContextVariableLValues(hir); + validateUseMemo(hir).unwrap(); + if (env.isInferredMemoEnabled && + !env.config.enablePreserveExistingManualUseMemo && + !env.config.disableMemoizationForDebugging && + !env.config.enableChangeDetectionForDebugging) { + dropManualMemoization(hir); + log({ kind: 'hir', name: 'DropManualMemoization', value: hir }); + } + inlineImmediatelyInvokedFunctionExpressions(hir); + log({ + kind: 'hir', + name: 'InlineImmediatelyInvokedFunctionExpressions', + value: hir, + }); + mergeConsecutiveBlocks(hir); + log({ kind: 'hir', name: 'MergeConsecutiveBlocks', value: hir }); + assertConsistentIdentifiers(hir); + assertTerminalSuccessorsExist(hir); + enterSSA(hir); + log({ kind: 'hir', name: 'SSA', value: hir }); + eliminateRedundantPhi(hir); + log({ kind: 'hir', name: 'EliminateRedundantPhi', value: hir }); + assertConsistentIdentifiers(hir); + constantPropagation(hir); + log({ kind: 'hir', name: 'ConstantPropagation', value: hir }); + inferTypes(hir); + log({ kind: 'hir', name: 'InferTypes', value: hir }); + if (env.isInferredMemoEnabled) { + if (env.config.validateHooksUsage) { + validateHooksUsage(hir).unwrap(); + } + if (env.config.validateNoCapitalizedCalls) { + validateNoCapitalizedCalls(hir).unwrap(); + } + } + if (env.config.enableFire) { + transformFire(hir); + log({ kind: 'hir', name: 'TransformFire', value: hir }); + } + if (env.config.lowerContextAccess) { + lowerContextAccess(hir, env.config.lowerContextAccess); + } + optimizePropsMethodCalls(hir); + log({ kind: 'hir', name: 'OptimizePropsMethodCalls', value: hir }); + analyseFunctions(hir); + log({ kind: 'hir', name: 'AnalyseFunctions', value: hir }); + const fnEffectErrors = inferReferenceEffects(hir); + if (env.isInferredMemoEnabled) { + if (fnEffectErrors.length > 0) { + CompilerError.throw(fnEffectErrors[0]); + } + } + log({ kind: 'hir', name: 'InferReferenceEffects', value: hir }); + validateLocalsNotReassignedAfterRender(hir); + deadCodeElimination(hir); + log({ kind: 'hir', name: 'DeadCodeElimination', value: hir }); + if (env.config.enableInstructionReordering) { + instructionReordering(hir); + log({ kind: 'hir', name: 'InstructionReordering', value: hir }); + } + pruneMaybeThrows(hir); + log({ kind: 'hir', name: 'PruneMaybeThrows', value: hir }); + inferMutableRanges(hir); + log({ kind: 'hir', name: 'InferMutableRanges', value: hir }); + if (env.isInferredMemoEnabled) { + if (env.config.assertValidMutableRanges) { + assertValidMutableRanges(hir); + } + if (env.config.validateRefAccessDuringRender) { + validateNoRefAccessInRender(hir).unwrap(); + } + if (env.config.validateNoSetStateInRender) { + validateNoSetStateInRender(hir).unwrap(); + } + if (env.config.validateNoSetStateInPassiveEffects) { + env.logErrors(validateNoSetStateInPassiveEffects(hir)); + } + if (env.config.validateNoJSXInTryStatements) { + env.logErrors(validateNoJSXInTryStatement(hir)); + } + if (env.config.validateNoImpureFunctionsInRender) { + validateNoImpureFunctionsInRender(hir).unwrap(); + } + } + inferReactivePlaces(hir); + log({ kind: 'hir', name: 'InferReactivePlaces', value: hir }); + rewriteInstructionKindsBasedOnReassignment(hir); + log({ + kind: 'hir', + name: 'RewriteInstructionKindsBasedOnReassignment', + value: hir, + }); + propagatePhiTypes(hir); + log({ + kind: 'hir', + name: 'PropagatePhiTypes', + value: hir, + }); + if (env.isInferredMemoEnabled) { + if (env.config.validateStaticComponents) { + env.logErrors(validateStaticComponents(hir)); + } + inferReactiveScopeVariables(hir); + log({ kind: 'hir', name: 'InferReactiveScopeVariables', value: hir }); + } + const fbtOperands = memoizeFbtAndMacroOperandsInSameScope(hir); + log({ + kind: 'hir', + name: 'MemoizeFbtAndMacroOperandsInSameScope', + value: hir, + }); + if (env.config.enableJsxOutlining) { + outlineJSX(hir); + } + if (env.config.enableFunctionOutlining) { + outlineFunctions(hir, fbtOperands); + log({ kind: 'hir', name: 'OutlineFunctions', value: hir }); + } + alignMethodCallScopes(hir); + log({ + kind: 'hir', + name: 'AlignMethodCallScopes', + value: hir, + }); + alignObjectMethodScopes(hir); + log({ + kind: 'hir', + name: 'AlignObjectMethodScopes', + value: hir, + }); + pruneUnusedLabelsHIR(hir); + log({ + kind: 'hir', + name: 'PruneUnusedLabelsHIR', + value: hir, + }); + alignReactiveScopesToBlockScopesHIR(hir); + log({ + kind: 'hir', + name: 'AlignReactiveScopesToBlockScopesHIR', + value: hir, + }); + mergeOverlappingReactiveScopesHIR(hir); + log({ + kind: 'hir', + name: 'MergeOverlappingReactiveScopesHIR', + value: hir, + }); + assertValidBlockNesting(hir); + buildReactiveScopeTerminalsHIR(hir); + log({ + kind: 'hir', + name: 'BuildReactiveScopeTerminalsHIR', + value: hir, + }); + assertValidBlockNesting(hir); + flattenReactiveLoopsHIR(hir); + log({ + kind: 'hir', + name: 'FlattenReactiveLoopsHIR', + value: hir, + }); + flattenScopesWithHooksOrUseHIR(hir); + log({ + kind: 'hir', + name: 'FlattenScopesWithHooksOrUseHIR', + value: hir, + }); + assertTerminalSuccessorsExist(hir); + assertTerminalPredsExist(hir); + propagateScopeDependenciesHIR(hir); + log({ + kind: 'hir', + name: 'PropagateScopeDependenciesHIR', + value: hir, + }); + if (env.config.inferEffectDependencies) { + inferEffectDependencies(hir); + log({ + kind: 'hir', + name: 'InferEffectDependencies', + value: hir, + }); + } + if (env.config.inlineJsxTransform) { + inlineJsxTransform(hir, env.config.inlineJsxTransform); + log({ + kind: 'hir', + name: 'inlineJsxTransform', + value: hir, + }); + } + const reactiveFunction = buildReactiveFunction(hir); + log({ + kind: 'reactive', + name: 'BuildReactiveFunction', + value: reactiveFunction, + }); + assertWellFormedBreakTargets(reactiveFunction); + pruneUnusedLabels(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedLabels', + value: reactiveFunction, + }); + assertScopeInstructionsWithinScopes(reactiveFunction); + pruneNonEscapingScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneNonEscapingScopes', + value: reactiveFunction, + }); + pruneNonReactiveDependencies(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneNonReactiveDependencies', + value: reactiveFunction, + }); + pruneUnusedScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedScopes', + value: reactiveFunction, + }); + mergeReactiveScopesThatInvalidateTogether(reactiveFunction); + log({ + kind: 'reactive', + name: 'MergeReactiveScopesThatInvalidateTogether', + value: reactiveFunction, + }); + pruneAlwaysInvalidatingScopes(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneAlwaysInvalidatingScopes', + value: reactiveFunction, + }); + if (env.config.enableChangeDetectionForDebugging != null) { + pruneInitializationDependencies(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneInitializationDependencies', + value: reactiveFunction, + }); + } + propagateEarlyReturns(reactiveFunction); + log({ + kind: 'reactive', + name: 'PropagateEarlyReturns', + value: reactiveFunction, + }); + pruneUnusedLValues(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneUnusedLValues', + value: reactiveFunction, + }); + promoteUsedTemporaries(reactiveFunction); + log({ + kind: 'reactive', + name: 'PromoteUsedTemporaries', + value: reactiveFunction, + }); + extractScopeDeclarationsFromDestructuring(reactiveFunction); + log({ + kind: 'reactive', + name: 'ExtractScopeDeclarationsFromDestructuring', + value: reactiveFunction, + }); + stabilizeBlockIds(reactiveFunction); + log({ + kind: 'reactive', + name: 'StabilizeBlockIds', + value: reactiveFunction, + }); + const uniqueIdentifiers = renameVariables(reactiveFunction); + log({ + kind: 'reactive', + name: 'RenameVariables', + value: reactiveFunction, + }); + pruneHoistedContexts(reactiveFunction); + log({ + kind: 'reactive', + name: 'PruneHoistedContexts', + value: reactiveFunction, + }); + if (env.config.validateMemoizedEffectDependencies) { + validateMemoizedEffectDependencies(reactiveFunction).unwrap(); + } + if (env.config.enablePreserveExistingMemoizationGuarantees || + env.config.validatePreserveExistingMemoizationGuarantees) { + validatePreservedManualMemoization(reactiveFunction).unwrap(); + } + const ast = codegenFunction(reactiveFunction, { + uniqueIdentifiers, + fbtOperands, + }).unwrap(); + log({ kind: 'ast', name: 'Codegen', value: ast }); + for (const outlined of ast.outlined) { + log({ kind: 'ast', name: 'Codegen (outlined)', value: outlined.fn }); + } + if (env.config.throwUnknownException__testonly) { + throw new Error('unexpected error'); + } + return ast; +} +function compileFn(func, config, fnType, mode, programContext, logger, filename, code) { + return run(func, config, fnType, mode, programContext, logger, filename, code); +} + +function filterSuppressionsThatAffectFunction(suppressionRanges, fn) { + const suppressionsInScope = []; + const fnNode = fn.node; + for (const suppressionRange of suppressionRanges) { + if (suppressionRange.disableComment.start == null || + fnNode.start == null || + fnNode.end == null) { + continue; + } + if (suppressionRange.disableComment.start > fnNode.start && + (suppressionRange.enableComment === null || + (suppressionRange.enableComment.end != null && + suppressionRange.enableComment.end < fnNode.end))) { + suppressionsInScope.push(suppressionRange); + } + if (suppressionRange.disableComment.start < fnNode.start && + (suppressionRange.enableComment === null || + (suppressionRange.enableComment.end != null && + suppressionRange.enableComment.end > fnNode.end))) { + suppressionsInScope.push(suppressionRange); + } + } + return suppressionsInScope; +} +function findProgramSuppressions(programComments, ruleNames, flowSuppressions) { + const suppressionRanges = []; + let disableComment = null; + let enableComment = null; + let source = null; + const rulePattern = `(${ruleNames.join('|')})`; + const disableNextLinePattern = new RegExp(`eslint-disable-next-line ${rulePattern}`); + const disablePattern = new RegExp(`eslint-disable ${rulePattern}`); + const enablePattern = new RegExp(`eslint-enable ${rulePattern}`); + const flowSuppressionPattern = new RegExp('\\$(FlowFixMe\\w*|FlowExpectedError|FlowIssue)\\[react\\-rule'); + for (const comment of programComments) { + if (comment.start == null || comment.end == null) { + continue; + } + if (disableComment == null && + disableNextLinePattern.test(comment.value)) { + disableComment = comment; + enableComment = comment; + source = 'Eslint'; + } + if (flowSuppressions && + disableComment == null && + flowSuppressionPattern.test(comment.value)) { + disableComment = comment; + enableComment = comment; + source = 'Flow'; + } + if (disablePattern.test(comment.value)) { + disableComment = comment; + source = 'Eslint'; + } + if (enablePattern.test(comment.value) && source === 'Eslint') { + enableComment = comment; + } + if (disableComment != null && source != null) { + suppressionRanges.push({ + disableComment: disableComment, + enableComment: enableComment, + source, + }); + disableComment = null; + enableComment = null; + source = null; + } + } + return suppressionRanges; +} +function suppressionsToCompilerError(suppressionRanges) { + var _a; + CompilerError.invariant(suppressionRanges.length !== 0, { + reason: `Expected at least suppression comment source range`, + loc: GeneratedSource, + }); + const error = new CompilerError(); + for (const suppressionRange of suppressionRanges) { + if (suppressionRange.disableComment.start == null || + suppressionRange.disableComment.end == null) { + continue; + } + let reason, suggestion; + switch (suppressionRange.source) { + case 'Eslint': + reason = + 'React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled'; + suggestion = + 'Remove the ESLint suppression and address the React error'; + break; + case 'Flow': + reason = + 'React Compiler has skipped optimizing this component because one or more React rule violations were reported by Flow'; + suggestion = 'Remove the Flow suppression and address the React error'; + break; + default: + assertExhaustive$1(suppressionRange.source, 'Unhandled suppression source'); + } + error.pushErrorDetail(new CompilerErrorDetail({ + reason: `${reason}. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior`, + description: suppressionRange.disableComment.value.trim(), + severity: ErrorSeverity.InvalidReact, + loc: (_a = suppressionRange.disableComment.loc) !== null && _a !== void 0 ? _a : null, + suggestions: [ + { + description: suggestion, + range: [ + suppressionRange.disableComment.start, + suppressionRange.disableComment.end, + ], + op: CompilerSuggestionOperation.Remove, + }, + ], + })); + } + return error; +} + +const OPT_IN_DIRECTIVES = new Set(['use forget', 'use memo']); +const OPT_OUT_DIRECTIVES = new Set(['use no forget', 'use no memo']); +function findDirectiveEnablingMemoization(directives) { + return directives.filter(directive => OPT_IN_DIRECTIVES.has(directive.value.value)); +} +function findDirectiveDisablingMemoization(directives) { + return directives.filter(directive => OPT_OUT_DIRECTIVES.has(directive.value.value)); +} +function isCriticalError(err) { + return !(err instanceof CompilerError) || err.isCritical(); +} +function isConfigError(err) { + if (err instanceof CompilerError) { + return err.details.some(detail => detail.severity === ErrorSeverity.InvalidConfig); + } + return false; +} +function logError(err, pass, fnLoc) { + var _a, _b; + if (pass.opts.logger) { + if (err instanceof CompilerError) { + for (const detail of err.details) { + pass.opts.logger.logEvent(pass.filename, { + kind: 'CompileError', + fnLoc, + detail: detail.options, + }); + } + } + else { + let stringifiedError; + if (err instanceof Error) { + stringifiedError = (_a = err.stack) !== null && _a !== void 0 ? _a : err.message; + } + else { + stringifiedError = (_b = err === null || err === void 0 ? void 0 : err.toString()) !== null && _b !== void 0 ? _b : '[ null ]'; + } + pass.opts.logger.logEvent(pass.filename, { + kind: 'PipelineError', + fnLoc, + data: stringifiedError, + }); + } + } +} +function handleError(err, pass, fnLoc) { + logError(err, pass, fnLoc); + if (pass.opts.panicThreshold === 'all_errors' || + (pass.opts.panicThreshold === 'critical_errors' && isCriticalError(err)) || + isConfigError(err)) { + throw err; + } +} +function createNewFunctionNode(originalFn, compiledFn) { + var _a, _b, _c; + let transformedFn; + switch (originalFn.node.type) { + case 'FunctionDeclaration': { + const fn = { + type: 'FunctionDeclaration', + id: compiledFn.id, + loc: (_a = originalFn.node.loc) !== null && _a !== void 0 ? _a : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + case 'ArrowFunctionExpression': { + const fn = { + type: 'ArrowFunctionExpression', + loc: (_b = originalFn.node.loc) !== null && _b !== void 0 ? _b : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + expression: originalFn.node.expression, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + case 'FunctionExpression': { + const fn = { + type: 'FunctionExpression', + id: compiledFn.id, + loc: (_c = originalFn.node.loc) !== null && _c !== void 0 ? _c : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + transformedFn = fn; + break; + } + default: { + assertExhaustive$1(originalFn.node, `Creating unhandled function: ${originalFn.node}`); + } + } + ALREADY_COMPILED.add(transformedFn); + return transformedFn; +} +function insertNewOutlinedFunctionNode(program, originalFn, compiledFn) { + var _a, _b, _c; + switch (originalFn.type) { + case 'FunctionDeclaration': { + return originalFn.insertAfter(createNewFunctionNode(originalFn, compiledFn))[0]; + } + case 'ArrowFunctionExpression': + case 'FunctionExpression': { + const fn = { + type: 'FunctionDeclaration', + id: compiledFn.id, + loc: (_a = originalFn.node.loc) !== null && _a !== void 0 ? _a : null, + async: compiledFn.async, + generator: compiledFn.generator, + params: compiledFn.params, + body: compiledFn.body, + }; + const insertedFuncDecl = program.pushContainer('body', [fn])[0]; + CompilerError.invariant(insertedFuncDecl.isFunctionDeclaration(), { + reason: 'Expected inserted function declaration', + description: `Got: ${insertedFuncDecl}`, + loc: (_c = (_b = insertedFuncDecl.node) === null || _b === void 0 ? void 0 : _b.loc) !== null && _c !== void 0 ? _c : null, + }); + return insertedFuncDecl; + } + default: { + assertExhaustive$1(originalFn, `Inserting unhandled function: ${originalFn}`); + } + } +} +const ALREADY_COMPILED = new (WeakSet !== null && WeakSet !== void 0 ? WeakSet : Set)(); +const DEFAULT_ESLINT_SUPPRESSIONS = [ + 'react-hooks/exhaustive-deps', + 'react-hooks/rules-of-hooks', +]; +function isFilePartOfSources(sources, filename) { + if (typeof sources === 'function') { + return sources(filename); + } + for (const prefix of sources) { + if (filename.indexOf(prefix) !== -1) { + return true; + } + } + return false; +} +function compileProgram(program, pass) { + var _a, _b; + if (shouldSkipCompilation(program, pass)) { + return null; + } + const environment = pass.opts.environment; + const restrictedImportsErr = validateRestrictedImports(program, environment); + if (restrictedImportsErr) { + handleError(restrictedImportsErr, pass, null); + return null; + } + const programContext = new ProgramContext(program, pass.opts.target, environment.hookPattern); + const suppressions = findProgramSuppressions(pass.comments, (_a = pass.opts.eslintSuppressionRules) !== null && _a !== void 0 ? _a : DEFAULT_ESLINT_SUPPRESSIONS, pass.opts.flowSuppressions); + const queue = []; + const compiledFns = []; + const traverseFunction = (fn, pass) => { + const fnType = getReactFunctionType(fn, pass, environment); + if (fnType === null || ALREADY_COMPILED.has(fn.node)) { + return; + } + ALREADY_COMPILED.add(fn.node); + fn.skip(); + queue.push({ kind: 'original', fn, fnType }); + }; + program.traverse({ + ClassDeclaration(node) { + node.skip(); + return; + }, + ClassExpression(node) { + node.skip(); + return; + }, + FunctionDeclaration: traverseFunction, + FunctionExpression: traverseFunction, + ArrowFunctionExpression: traverseFunction, + }, Object.assign(Object.assign({}, pass), { opts: Object.assign(Object.assign({}, pass.opts), pass.opts), filename: (_b = pass.filename) !== null && _b !== void 0 ? _b : null })); + const retryErrors = []; + const inferredEffectLocations = new Set(); + const processFn = (fn, fnType) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + let optInDirectives = []; + let optOutDirectives = []; + if (fn.node.body.type === 'BlockStatement') { + optInDirectives = findDirectiveEnablingMemoization(fn.node.body.directives); + optOutDirectives = findDirectiveDisablingMemoization(fn.node.body.directives); + } + const suppressionsInFunction = filterSuppressionsThatAffectFunction(suppressions, fn); + let compileResult; + if (suppressionsInFunction.length > 0) { + compileResult = { + kind: 'error', + error: suppressionsToCompilerError(suppressionsInFunction), + }; + } + else { + try { + compileResult = { + kind: 'compile', + compiledFn: compileFn(fn, environment, fnType, 'all_features', programContext, pass.opts.logger, pass.filename, pass.code), + }; + } + catch (err) { + compileResult = { kind: 'error', error: err }; + } + } + if (compileResult.kind === 'error') { + if (optOutDirectives.length > 0) { + logError(compileResult.error, pass, (_a = fn.node.loc) !== null && _a !== void 0 ? _a : null); + } + else { + handleError(compileResult.error, pass, (_b = fn.node.loc) !== null && _b !== void 0 ? _b : null); + } + if (!(environment.enableFire || environment.inferEffectDependencies != null)) { + return null; + } + try { + compileResult = { + kind: 'compile', + compiledFn: compileFn(fn, environment, fnType, 'no_inferred_memo', programContext, pass.opts.logger, pass.filename, pass.code), + }; + if (!compileResult.compiledFn.hasFireRewrite && + !compileResult.compiledFn.hasInferredEffect) { + return null; + } + } + catch (err) { + if (err instanceof CompilerError) { + retryErrors.push({ fn, error: err }); + } + return null; + } + } + if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) { + for (const directive of optOutDirectives) { + (_c = pass.opts.logger) === null || _c === void 0 ? void 0 : _c.logEvent(pass.filename, { + kind: 'CompileSkip', + fnLoc: (_d = fn.node.body.loc) !== null && _d !== void 0 ? _d : null, + reason: `Skipped due to '${directive.value.value}' directive.`, + loc: (_e = directive.loc) !== null && _e !== void 0 ? _e : null, + }); + } + return null; + } + (_f = pass.opts.logger) === null || _f === void 0 ? void 0 : _f.logEvent(pass.filename, { + kind: 'CompileSuccess', + fnLoc: (_g = fn.node.loc) !== null && _g !== void 0 ? _g : null, + fnName: (_j = (_h = compileResult.compiledFn.id) === null || _h === void 0 ? void 0 : _h.name) !== null && _j !== void 0 ? _j : null, + memoSlots: compileResult.compiledFn.memoSlotsUsed, + memoBlocks: compileResult.compiledFn.memoBlocks, + memoValues: compileResult.compiledFn.memoValues, + prunedMemoBlocks: compileResult.compiledFn.prunedMemoBlocks, + prunedMemoValues: compileResult.compiledFn.prunedMemoValues, + }); + if (optInDirectives.length > 0) { + return compileResult.compiledFn; + } + else if (pass.opts.compilationMode === 'annotation') { + return null; + } + if (!pass.opts.noEmit) { + return compileResult.compiledFn; + } + for (const loc of compileResult.compiledFn.inferredEffectLocations) { + if (loc !== GeneratedSource) + inferredEffectLocations.add(loc); + } + return null; + }; + while (queue.length !== 0) { + const current = queue.shift(); + const compiled = processFn(current.fn, current.fnType); + if (compiled === null) { + continue; + } + for (const outlined of compiled.outlined) { + CompilerError.invariant(outlined.fn.outlined.length === 0, { + reason: 'Unexpected nested outlined functions', + loc: outlined.fn.loc, + }); + const fn = insertNewOutlinedFunctionNode(program, current.fn, outlined.fn); + fn.skip(); + ALREADY_COMPILED.add(fn.node); + if (outlined.type !== null) { + queue.push({ + kind: 'outlined', + fn, + fnType: outlined.type, + }); + } + } + compiledFns.push({ + kind: current.kind, + compiledFn: compiled, + originalFn: current.fn, + }); + } + const moduleScopeOptOutDirectives = findDirectiveDisablingMemoization(program.node.directives); + if (moduleScopeOptOutDirectives.length > 0) { + return null; + } + const referencedBeforeDeclared = pass.opts.gating != null + ? getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns) + : null; + for (const result of compiledFns) { + const { kind, originalFn, compiledFn } = result; + const transformedFn = createNewFunctionNode(originalFn, compiledFn); + if (referencedBeforeDeclared != null && kind === 'original') { + CompilerError.invariant(pass.opts.gating != null, { + reason: "Expected 'gating' import to be present", + loc: null, + }); + insertGatedFunctionDeclaration(originalFn, transformedFn, programContext, pass.opts.gating, referencedBeforeDeclared.has(result)); + } + else { + originalFn.replaceWith(transformedFn); + } + } + if (compiledFns.length > 0) { + addImportsToProgram(program, programContext); + } + return { retryErrors, inferredEffectLocations }; +} +function shouldSkipCompilation(program, pass) { + if (pass.opts.sources) { + if (pass.filename === null) { + const error = new CompilerError(); + error.pushErrorDetail(new CompilerErrorDetail({ + reason: `Expected a filename but found none.`, + description: "When the 'sources' config options is specified, the React compiler will only compile files with a name", + severity: ErrorSeverity.InvalidConfig, + loc: null, + })); + handleError(error, pass, null); + return true; + } + if (!isFilePartOfSources(pass.opts.sources, pass.filename)) { + return true; + } + } + if (hasMemoCacheFunctionImport(program, getReactCompilerRuntimeModule(pass.opts.target))) { + return true; + } + return false; +} +function getReactFunctionType(fn, pass, environment) { + var _a, _b; + const hookPattern = environment.hookPattern; + if (fn.node.body.type === 'BlockStatement') { + if (findDirectiveEnablingMemoization(fn.node.body.directives).length > 0) + return (_a = getComponentOrHookLike(fn, hookPattern)) !== null && _a !== void 0 ? _a : 'Other'; + } + let componentSyntaxType = null; + if (fn.isFunctionDeclaration()) { + if (isComponentDeclaration(fn.node)) { + componentSyntaxType = 'Component'; + } + else if (isHookDeclaration(fn.node)) { + componentSyntaxType = 'Hook'; + } + } + switch (pass.opts.compilationMode) { + case 'annotation': { + return null; + } + case 'infer': { + return componentSyntaxType !== null && componentSyntaxType !== void 0 ? componentSyntaxType : getComponentOrHookLike(fn, hookPattern); + } + case 'syntax': { + return componentSyntaxType; + } + case 'all': { + if (fn.scope.getProgramParent() !== fn.scope.parent) { + return null; + } + return (_b = getComponentOrHookLike(fn, hookPattern)) !== null && _b !== void 0 ? _b : 'Other'; + } + default: { + assertExhaustive$1(pass.opts.compilationMode, `Unexpected compilationMode \`${pass.opts.compilationMode}\``); + } + } +} +function hasMemoCacheFunctionImport(program, moduleName) { + let hasUseMemoCache = false; + program.traverse({ + ImportSpecifier(path) { + const imported = path.get('imported'); + let importedName = null; + if (imported.isIdentifier()) { + importedName = imported.node.name; + } + else if (imported.isStringLiteral()) { + importedName = imported.node.value; + } + if (importedName === 'c' && + path.parentPath.isImportDeclaration() && + path.parentPath.get('source').node.value === moduleName) { + hasUseMemoCache = true; + } + }, + }); + return hasUseMemoCache; +} +function isHookName$1(s, hookPattern) { + if (hookPattern !== null) { + return new RegExp(hookPattern).test(s); + } + return /^use[A-Z0-9]/.test(s); +} +function isHook$1(path, hookPattern) { + if (path.isIdentifier()) { + return isHookName$1(path.node.name, hookPattern); + } + else if (path.isMemberExpression() && + !path.node.computed && + isHook$1(path.get('property'), hookPattern)) { + const obj = path.get('object').node; + const isPascalCaseNameSpace = /^[A-Z].*/; + return obj.type === 'Identifier' && isPascalCaseNameSpace.test(obj.name); + } + else { + return false; + } +} +function isComponentName$1(path) { + return path.isIdentifier() && /^[A-Z]/.test(path.node.name); +} +function isReactAPI(path, functionName) { + const node = path.node; + return ((node.type === 'Identifier' && node.name === functionName) || + (node.type === 'MemberExpression' && + node.object.type === 'Identifier' && + node.object.name === 'React' && + node.property.type === 'Identifier' && + node.property.name === functionName)); +} +function isForwardRefCallback$1(path) { + return !!(path.parentPath.isCallExpression() && + path.parentPath.get('callee').isExpression() && + isReactAPI(path.parentPath.get('callee'), 'forwardRef')); +} +function isMemoCallback$1(path) { + return (path.parentPath.isCallExpression() && + path.parentPath.get('callee').isExpression() && + isReactAPI(path.parentPath.get('callee'), 'memo')); +} +function isValidPropsAnnotation(annot) { + if (annot == null) { + return true; + } + else if (annot.type === 'TSTypeAnnotation') { + switch (annot.typeAnnotation.type) { + case 'TSArrayType': + case 'TSBigIntKeyword': + case 'TSBooleanKeyword': + case 'TSConstructorType': + case 'TSFunctionType': + case 'TSLiteralType': + case 'TSNeverKeyword': + case 'TSNumberKeyword': + case 'TSStringKeyword': + case 'TSSymbolKeyword': + case 'TSTupleType': + return false; + } + return true; + } + else if (annot.type === 'TypeAnnotation') { + switch (annot.typeAnnotation.type) { + case 'ArrayTypeAnnotation': + case 'BooleanLiteralTypeAnnotation': + case 'BooleanTypeAnnotation': + case 'EmptyTypeAnnotation': + case 'FunctionTypeAnnotation': + case 'NumberLiteralTypeAnnotation': + case 'NumberTypeAnnotation': + case 'StringLiteralTypeAnnotation': + case 'StringTypeAnnotation': + case 'SymbolTypeAnnotation': + case 'ThisTypeAnnotation': + case 'TupleTypeAnnotation': + return false; + } + return true; + } + else if (annot.type === 'Noop') { + return true; + } + else { + assertExhaustive$1(annot, `Unexpected annotation node \`${annot}\``); + } +} +function isValidComponentParams(params) { + if (params.length === 0) { + return true; + } + else if (params.length > 0 && params.length <= 2) { + if (!isValidPropsAnnotation(params[0].node.typeAnnotation)) { + return false; + } + if (params.length === 1) { + return !params[0].isRestElement(); + } + else if (params[1].isIdentifier()) { + const { name } = params[1].node; + return name.includes('ref') || name.includes('Ref'); + } + else { + return false; + } + } + return false; +} +function getComponentOrHookLike(node, hookPattern) { + const functionName = getFunctionName$1(node); + if (functionName !== null && isComponentName$1(functionName)) { + let isComponent = callsHooksOrCreatesJsx(node, hookPattern) && + isValidComponentParams(node.get('params')) && + !returnsNonNode(node); + return isComponent ? 'Component' : null; + } + else if (functionName !== null && isHook$1(functionName, hookPattern)) { + return callsHooksOrCreatesJsx(node, hookPattern) ? 'Hook' : null; + } + if (node.isFunctionExpression() || node.isArrowFunctionExpression()) { + if (isForwardRefCallback$1(node) || isMemoCallback$1(node)) { + return callsHooksOrCreatesJsx(node, hookPattern) ? 'Component' : null; + } + } + return null; +} +function skipNestedFunctions(node) { + return (fn) => { + if (fn.node !== node.node) { + fn.skip(); + } + }; +} +function callsHooksOrCreatesJsx(node, hookPattern) { + let invokesHooks = false; + let createsJsx = false; + node.traverse({ + JSX() { + createsJsx = true; + }, + CallExpression(call) { + const callee = call.get('callee'); + if (callee.isExpression() && isHook$1(callee, hookPattern)) { + invokesHooks = true; + } + }, + ArrowFunctionExpression: skipNestedFunctions(node), + FunctionExpression: skipNestedFunctions(node), + FunctionDeclaration: skipNestedFunctions(node), + }); + return invokesHooks || createsJsx; +} +function isNonNode(node) { + if (!node) { + return true; + } + switch (node.type) { + case 'ObjectExpression': + case 'ArrowFunctionExpression': + case 'FunctionExpression': + case 'BigIntLiteral': + case 'ClassExpression': + case 'NewExpression': + return true; + } + return false; +} +function returnsNonNode(node) { + let returnsNonNode = false; + if (node.type === 'ArrowFunctionExpression' && + node.node.body.type !== 'BlockStatement') { + returnsNonNode = isNonNode(node.node.body); + } + node.traverse({ + ReturnStatement(ret) { + returnsNonNode = isNonNode(ret.node.argument); + }, + ArrowFunctionExpression: skipNestedFunctions(node), + FunctionExpression: skipNestedFunctions(node), + FunctionDeclaration: skipNestedFunctions(node), + ObjectMethod: node => node.skip(), + }); + return returnsNonNode; +} +function getFunctionName$1(path) { + if (path.isFunctionDeclaration()) { + const id = path.get('id'); + if (id.isIdentifier()) { + return id; + } + return null; + } + let id = null; + const parent = path.parentPath; + if (parent.isVariableDeclarator() && parent.get('init').node === path.node) { + id = parent.get('id'); + } + else if (parent.isAssignmentExpression() && + parent.get('right').node === path.node && + parent.get('operator') === '=') { + id = parent.get('left'); + } + else if (parent.isProperty() && + parent.get('value').node === path.node && + !parent.get('computed') && + parent.get('key').isLVal()) { + id = parent.get('key'); + } + else if (parent.isAssignmentPattern() && + parent.get('right').node === path.node && + !parent.get('computed')) { + id = parent.get('left'); + } + if (id !== null && (id.isIdentifier() || id.isMemberExpression())) { + return id; + } + else { + return null; + } +} +function getFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) { + const fnNames = new Map(fns + .map(fn => [ + getFunctionName$1(fn.originalFn), + fn, + ]) + .filter((entry) => !!entry[0] && entry[0].isIdentifier()) + .map(entry => [entry[0].node.name, { id: entry[0].node, fn: entry[1] }])); + const referencedBeforeDeclaration = new Set(); + program.traverse({ + TypeAnnotation(path) { + path.skip(); + }, + TSTypeAnnotation(path) { + path.skip(); + }, + TypeAlias(path) { + path.skip(); + }, + TSTypeAliasDeclaration(path) { + path.skip(); + }, + Identifier(id) { + const fn = fnNames.get(id.node.name); + if (!fn) { + return; + } + if (id.node === fn.id) { + fnNames.delete(id.node.name); + return; + } + const scope = id.scope.getFunctionParent(); + if (scope === null && id.isReferencedIdentifier()) { + referencedBeforeDeclaration.add(fn.fn); + } + }, + }); + return referencedBeforeDeclaration; +} +function getReactCompilerRuntimeModule(target) { + if (target === '19') { + return 'react/compiler-runtime'; + } + else if (target === '17' || target === '18') { + return 'react-compiler-runtime'; + } + else { + CompilerError.invariant(target != null && + target.kind === 'donotuse_meta_internal' && + typeof target.runtimeModule === 'string', { + reason: 'Expected target to already be validated', + description: null, + loc: null, + suggestions: null, + }); + return target.runtimeModule; + } +} + +function validateRestrictedImports(path, { validateBlocklistedImports }) { + if (validateBlocklistedImports == null || + validateBlocklistedImports.length === 0) { + return null; + } + const error = new CompilerError(); + const restrictedImports = new Set(validateBlocklistedImports); + path.traverse({ + ImportDeclaration(importDeclPath) { + var _a; + if (restrictedImports.has(importDeclPath.node.source.value)) { + error.push({ + severity: ErrorSeverity.Todo, + reason: 'Bailing out due to blocklisted import', + description: `Import from module ${importDeclPath.node.source.value}`, + loc: (_a = importDeclPath.node.loc) !== null && _a !== void 0 ? _a : null, + }); + } + }, + }); + if (error.hasErrors()) { + return error; + } + else { + return null; + } +} +class ProgramContext { + constructor(program, reactRuntimeModule, hookPattern) { + this.knownReferencedNames = new Set(); + this.imports = new Map(); + this.hookPattern = hookPattern; + this.scope = program.scope; + this.reactRuntimeModule = getReactCompilerRuntimeModule(reactRuntimeModule); + } + isHookName(name) { + if (this.hookPattern == null) { + return isHookName$2(name); + } + else { + const match = new RegExp(this.hookPattern).exec(name); + return (match != null && typeof match[1] === 'string' && isHookName$2(match[1])); + } + } + hasReference(name) { + return (this.knownReferencedNames.has(name) || + this.scope.hasBinding(name) || + this.scope.hasGlobal(name) || + this.scope.hasReference(name)); + } + newUid(name) { + let uid; + if (this.isHookName(name)) { + uid = name; + let i = 0; + while (this.hasReference(uid)) { + this.knownReferencedNames.add(uid); + uid = `${name}_${i++}`; + } + } + else if (!this.hasReference(name)) { + uid = name; + } + else { + uid = this.scope.generateUid(name); + } + this.knownReferencedNames.add(uid); + return uid; + } + addMemoCacheImport() { + return this.addImportSpecifier({ + source: this.reactRuntimeModule, + importSpecifierName: 'c', + }, '_c'); + } + addImportSpecifier({ source: module, importSpecifierName: specifier }, nameHint) { + var _a; + const maybeBinding = (_a = this.imports.get(module)) === null || _a === void 0 ? void 0 : _a.get(specifier); + if (maybeBinding != null) { + return Object.assign({}, maybeBinding); + } + const binding = { + kind: 'ImportSpecifier', + name: this.newUid(nameHint !== null && nameHint !== void 0 ? nameHint : specifier), + module, + imported: specifier, + }; + getOrInsertWith(this.imports, module, () => new Map()).set(specifier, Object.assign({}, binding)); + return binding; + } + addNewReference(name) { + this.knownReferencedNames.add(name); + } + assertGlobalBinding(name, localScope) { + var _a, _b; + const scope = localScope !== null && localScope !== void 0 ? localScope : this.scope; + if (!scope.hasReference(name) && !scope.hasBinding(name)) { + return Ok(undefined); + } + const error = new CompilerError(); + error.push({ + severity: ErrorSeverity.Todo, + reason: 'Encountered conflicting global in generated program', + description: `Conflict from local binding ${name}`, + loc: (_b = (_a = scope.getBinding(name)) === null || _a === void 0 ? void 0 : _a.path.node.loc) !== null && _b !== void 0 ? _b : null, + suggestions: null, + }); + return Err(error); + } +} +function getExistingImports(program) { + const existingImports = new Map(); + program.traverse({ + ImportDeclaration(path) { + if (isNonNamespacedImport(path)) { + existingImports.set(path.node.source.value, path); + } + }, + }); + return existingImports; +} +function addImportsToProgram(path, programContext) { + const existingImports = getExistingImports(path); + const stmts = []; + const sortedModules = [...programContext.imports.entries()].sort(([a], [b]) => a.localeCompare(b)); + for (const [moduleName, importsMap] of sortedModules) { + for (const [specifierName, loweredImport] of importsMap) { + CompilerError.invariant(path.scope.getBinding(loweredImport.name) == null, { + reason: 'Encountered conflicting import specifiers in generated program', + description: `Conflict from import ${loweredImport.module}:(${loweredImport.imported} as ${loweredImport.name}).`, + loc: GeneratedSource, + suggestions: null, + }); + CompilerError.invariant(loweredImport.module === moduleName && + loweredImport.imported === specifierName, { + reason: 'Found inconsistent import specifier. This is an internal bug.', + description: `Expected import ${moduleName}:${specifierName} but found ${loweredImport.module}:${loweredImport.imported}`, + loc: GeneratedSource, + }); + } + const sortedImport = [ + ...importsMap.values(), + ].sort(({ imported: a }, { imported: b }) => a.localeCompare(b)); + const importSpecifiers = sortedImport.map(specifier => { + return libExports$1.importSpecifier(libExports$1.identifier(specifier.name), libExports$1.identifier(specifier.imported)); + }); + const maybeExistingImports = existingImports.get(moduleName); + if (maybeExistingImports != null) { + maybeExistingImports.pushContainer('specifiers', importSpecifiers); + } + else { + stmts.push(libExports$1.importDeclaration(importSpecifiers, libExports$1.stringLiteral(moduleName))); + } + } + path.unshiftContainer('body', stmts); +} +function isNonNamespacedImport(importDeclPath) { + return (importDeclPath + .get('specifiers') + .every(specifier => specifier.isImportSpecifier()) && + importDeclPath.node.importKind !== 'type' && + importDeclPath.node.importKind !== 'typeof'); +} + +zod.z.enum([ + 'all_errors', + 'critical_errors', + 'none', +]); +const CompilerReactTargetSchema = zod.z.union([ + zod.z.literal('17'), + zod.z.literal('18'), + zod.z.literal('19'), + zod.z.object({ + kind: zod.z.literal('donotuse_meta_internal'), + runtimeModule: zod.z.string().default('react'), + }), +]); +zod.z.enum([ + 'infer', + 'syntax', + 'annotation', + 'all', +]); +const defaultOptions = { + compilationMode: 'infer', + panicThreshold: 'none', + environment: parseEnvironmentConfig({}).unwrap(), + logger: null, + gating: null, + noEmit: false, + eslintSuppressionRules: null, + flowSuppressions: true, + ignoreUseNoForget: false, + sources: filename => { + return filename.indexOf('node_modules') === -1; + }, + enableReanimatedCheck: true, + target: '19', +}; +function parsePluginOptions(obj) { + if (obj == null || typeof obj !== 'object') { + return defaultOptions; + } + const parsedOptions = Object.create(null); + for (let [key, value] of Object.entries(obj)) { + if (typeof value === 'string') { + value = value.toLowerCase(); + } + if (isCompilerFlag(key)) { + switch (key) { + case 'environment': { + const environmentResult = parseEnvironmentConfig(value); + if (environmentResult.isErr()) { + CompilerError.throwInvalidConfig({ + reason: 'Error in validating environment config. This is an advanced setting and not meant to be used directly', + description: environmentResult.unwrapErr().toString(), + suggestions: null, + loc: null, + }); + } + parsedOptions[key] = environmentResult.unwrap(); + break; + } + case 'target': { + parsedOptions[key] = parseTargetConfig(value); + break; + } + case 'gating': { + if (value == null) { + parsedOptions[key] = null; + } + else { + parsedOptions[key] = tryParseExternalFunction(value); + } + break; + } + default: { + parsedOptions[key] = value; + } + } + } + } + return Object.assign(Object.assign({}, defaultOptions), parsedOptions); +} +function parseTargetConfig(value) { + const parsed = CompilerReactTargetSchema.safeParse(value); + if (parsed.success) { + return parsed.data; + } + else { + CompilerError.throwInvalidConfig({ + reason: 'Not a valid target', + description: `${zodValidationError.fromZodError(parsed.error)}`, + suggestions: null, + loc: null, + }); + } +} +function isCompilerFlag(s) { + return hasOwnProperty$1(defaultOptions, s); +} + +function hasModule(name) { + if (typeof require === 'undefined') { + return false; + } + try { + return !!require.resolve(name); + } + catch (error) { + if (error.code === 'MODULE_NOT_FOUND' && + error.message.indexOf(name) !== -1) { + return false; + } + throw error; + } +} +function pipelineUsesReanimatedPlugin(plugins) { + if (Array.isArray(plugins)) { + for (const plugin of plugins) { + if (hasOwnProperty$1(plugin, 'key')) { + const key = plugin.key; + if (typeof key === 'string' && + key.indexOf('react-native-reanimated') !== -1) { + return true; + } + } + } + } + return hasModule('react-native-reanimated'); +} +function injectReanimatedFlag(options) { + return Object.assign(Object.assign({}, options), { environment: Object.assign(Object.assign({}, options.environment), { enableCustomTypeDefinitionForReanimated: true }) }); +} + +function throwInvalidReact(options, { logger, filename }) { + const detail = Object.assign(Object.assign({}, options), { severity: ErrorSeverity.InvalidReact }); + logger === null || logger === void 0 ? void 0 : logger.logEvent(filename, { + kind: 'CompileError', + fnLoc: null, + detail, + }); + CompilerError.throw(detail); +} +function assertValidEffectImportReference(numArgs, paths, context) { + var _a; + for (const path of paths) { + const parent = path.parentPath; + if (parent != null && parent.isCallExpression()) { + const args = parent.get('arguments'); + const maybeCalleeLoc = path.node.loc; + const hasInferredEffect = maybeCalleeLoc != null && + context.inferredEffectLocations.has(maybeCalleeLoc); + if (args.length === numArgs && !hasInferredEffect) { + const maybeErrorDiagnostic = matchCompilerDiagnostic(path, context.transformErrors); + throwInvalidReact({ + reason: '[InferEffectDependencies] React Compiler is unable to infer dependencies of this effect. ' + + 'This will break your build! ' + + 'To resolve, either pass your own dependency array or fix reported compiler bailout diagnostics.', + description: maybeErrorDiagnostic + ? `(Bailout reason: ${maybeErrorDiagnostic})` + : null, + loc: (_a = parent.node.loc) !== null && _a !== void 0 ? _a : null, + }, context); + } + } + } +} +function assertValidFireImportReference(paths, context) { + var _a; + if (paths.length > 0) { + const maybeErrorDiagnostic = matchCompilerDiagnostic(paths[0], context.transformErrors); + throwInvalidReact({ + reason: '[Fire] Untransformed reference to compiler-required feature. ' + + 'Either remove this `fire` call or ensure it is successfully transformed by the compiler', + description: maybeErrorDiagnostic + ? `(Bailout reason: ${maybeErrorDiagnostic})` + : null, + loc: (_a = paths[0].node.loc) !== null && _a !== void 0 ? _a : null, + }, context); + } +} +function validateNoUntransformedReferences(path, filename, logger, env, compileResult) { + const moduleLoadChecks = new Map(); + if (env.enableFire) { + for (const module of Environment.knownReactModules) { + const react = getOrInsertWith(moduleLoadChecks, module, () => new Map()); + react.set('fire', assertValidFireImportReference); + } + } + if (env.inferEffectDependencies) { + for (const { function: { source, importSpecifierName }, numRequiredArgs, } of env.inferEffectDependencies) { + const module = getOrInsertWith(moduleLoadChecks, source, () => new Map()); + module.set(importSpecifierName, assertValidEffectImportReference.bind(null, numRequiredArgs)); + } + } + if (moduleLoadChecks.size > 0) { + transformProgram(path, moduleLoadChecks, filename, logger, compileResult); + } +} +function validateImportSpecifier(specifier, importSpecifierChecks, state) { + var _a; + const imported = specifier.get('imported'); + const specifierName = imported.node.type === 'Identifier' + ? imported.node.name + : imported.node.value; + const checkFn = importSpecifierChecks.get(specifierName); + if (checkFn == null) { + return; + } + if (state.shouldInvalidateScopes) { + state.shouldInvalidateScopes = false; + state.program.scope.crawl(); + } + const local = specifier.get('local'); + const binding = local.scope.getBinding(local.node.name); + CompilerError.invariant(binding != null, { + reason: 'Expected binding to be found for import specifier', + loc: (_a = local.node.loc) !== null && _a !== void 0 ? _a : null, + }); + checkFn(binding.referencePaths, state); +} +function validateNamespacedImport(specifier, importSpecifierChecks, state) { + var _a; + if (state.shouldInvalidateScopes) { + state.shouldInvalidateScopes = false; + state.program.scope.crawl(); + } + const local = specifier.get('local'); + const binding = local.scope.getBinding(local.node.name); + const defaultCheckFn = importSpecifierChecks.get(DEFAULT_EXPORT); + CompilerError.invariant(binding != null, { + reason: 'Expected binding to be found for import specifier', + loc: (_a = local.node.loc) !== null && _a !== void 0 ? _a : null, + }); + const filteredReferences = new Map(); + for (const reference of binding.referencePaths) { + if (defaultCheckFn != null) { + getOrInsertWith(filteredReferences, defaultCheckFn, () => []).push(reference); + } + const parent = reference.parentPath; + if (parent != null && + parent.isMemberExpression() && + parent.get('object') === reference) { + if (parent.node.computed || parent.node.property.type !== 'Identifier') { + continue; + } + const checkFn = importSpecifierChecks.get(parent.node.property.name); + if (checkFn != null) { + getOrInsertWith(filteredReferences, checkFn, () => []).push(parent); + } + } + } + for (const [checkFn, references] of filteredReferences) { + checkFn(references, state); + } +} +function transformProgram(path, moduleLoadChecks, filename, logger, compileResult) { + var _a, _b; + const traversalState = { + shouldInvalidateScopes: true, + program: path, + filename, + logger, + transformErrors: (_a = compileResult === null || compileResult === void 0 ? void 0 : compileResult.retryErrors) !== null && _a !== void 0 ? _a : [], + inferredEffectLocations: (_b = compileResult === null || compileResult === void 0 ? void 0 : compileResult.inferredEffectLocations) !== null && _b !== void 0 ? _b : new Set(), + }; + path.traverse({ + ImportDeclaration(path) { + const importSpecifierChecks = moduleLoadChecks.get(path.node.source.value); + if (importSpecifierChecks == null) { + return; + } + const specifiers = path.get('specifiers'); + for (const specifier of specifiers) { + if (specifier.isImportSpecifier()) { + validateImportSpecifier(specifier, importSpecifierChecks, traversalState); + } + else { + validateNamespacedImport(specifier, importSpecifierChecks, traversalState); + } + } + }, + }); +} +function matchCompilerDiagnostic(badReference, transformErrors) { + for (const { fn, error } of transformErrors) { + if (fn.isAncestor(badReference)) { + return error.toString(); + } + } + return null; +} + +const ENABLE_REACT_COMPILER_TIMINGS = process.env['ENABLE_REACT_COMPILER_TIMINGS'] === '1'; +function BabelPluginReactCompiler(_babel) { + return { + name: 'react-forget', + visitor: { + Program: { + enter(prog, pass) { + var _a, _b, _c, _d; + const filename = (_a = pass.filename) !== null && _a !== void 0 ? _a : 'unknown'; + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + performance.mark(`${filename}:start`, { + detail: 'BabelPlugin:Program:start', + }); + } + let opts = parsePluginOptions(pass.opts); + const isDev = process.env['NODE_ENV'] === 'development'; + if (opts.enableReanimatedCheck === true && + pipelineUsesReanimatedPlugin(pass.file.opts.plugins)) { + opts = injectReanimatedFlag(opts); + } + if (opts.environment.enableResetCacheOnSourceFileChanges !== false && + isDev) { + opts = Object.assign(Object.assign({}, opts), { environment: Object.assign(Object.assign({}, opts.environment), { enableResetCacheOnSourceFileChanges: true }) }); + } + const result = compileProgram(prog, { + opts, + filename: (_b = pass.filename) !== null && _b !== void 0 ? _b : null, + comments: (_c = pass.file.ast.comments) !== null && _c !== void 0 ? _c : [], + code: pass.file.code, + }); + validateNoUntransformedReferences(prog, (_d = pass.filename) !== null && _d !== void 0 ? _d : null, opts.logger, opts.environment, result); + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + performance.mark(`${filename}:end`, { + detail: 'BabelPlugin:Program:end', + }); + } + }, + exit(_, pass) { + var _a; + if (ENABLE_REACT_COMPILER_TIMINGS === true) { + const filename = (_a = pass.filename) !== null && _a !== void 0 ? _a : 'unknown'; + const measurement = performance.measure(filename, { + start: `${filename}:start`, + end: `${filename}:end`, + detail: 'BabelPlugin:Program', + }); + if ('logger' in pass.opts && pass.opts.logger != null) { + const logger = pass.opts.logger; + logger.logEvent(filename, { + kind: 'Timing', + measurement, + }); + } + } + }, + }, + }, + }; +} + +function assertExhaustive(_, errorMsg) { + throw new Error(errorMsg); +} +const DEFAULT_REPORTABLE_LEVELS = new Set([ + ErrorSeverity.InvalidReact, + ErrorSeverity.InvalidJS, +]); +let reportableLevels = DEFAULT_REPORTABLE_LEVELS; +function isReportableDiagnostic(detail) { + return (reportableLevels.has(detail.severity) && + detail.loc != null && + typeof detail.loc !== 'symbol'); +} +function makeSuggestions(detail) { + const suggest = []; + if (Array.isArray(detail.suggestions)) { + for (const suggestion of detail.suggestions) { + switch (suggestion.op) { + case CompilerSuggestionOperation.InsertBefore: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.insertTextBeforeRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.InsertAfter: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.insertTextAfterRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.Replace: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.replaceTextRange(suggestion.range, suggestion.text); + }, + }); + break; + case CompilerSuggestionOperation.Remove: + suggest.push({ + desc: suggestion.description, + fix(fixer) { + return fixer.removeRange(suggestion.range); + }, + }); + break; + default: + assertExhaustive(suggestion, 'Unhandled suggestion operation'); + } + } + } + return suggest; +} +const COMPILER_OPTIONS = { + noEmit: true, + panicThreshold: 'none', + flowSuppressions: false, + environment: validateEnvironmentConfig({ + validateRefAccessDuringRender: false, + }), +}; +const rule$1 = { + meta: { + type: 'problem', + docs: { + description: 'Surfaces diagnostics from React Forget', + recommended: true, + }, + fixable: 'code', + hasSuggestions: true, + schema: [{ type: 'object', additionalProperties: true }], + }, + create(context) { + var _a, _b, _c, _d, _e; + const sourceCode = (_a = context.sourceCode) !== null && _a !== void 0 ? _a : context.getSourceCode(); + const filename = (_b = context.filename) !== null && _b !== void 0 ? _b : context.getFilename(); + const userOpts = (_c = context.options[0]) !== null && _c !== void 0 ? _c : {}; + if (userOpts.reportableLevels != null && + userOpts.reportableLevels instanceof Set) { + reportableLevels = userOpts.reportableLevels; + } + else { + reportableLevels = DEFAULT_REPORTABLE_LEVELS; + } + let __unstable_donotuse_reportAllBailouts = false; + if (userOpts.__unstable_donotuse_reportAllBailouts != null && + typeof userOpts.__unstable_donotuse_reportAllBailouts === 'boolean') { + __unstable_donotuse_reportAllBailouts = + userOpts.__unstable_donotuse_reportAllBailouts; + } + let shouldReportUnusedOptOutDirective = true; + const options = parsePluginOptions(Object.assign(Object.assign(Object.assign({}, COMPILER_OPTIONS), userOpts), { environment: Object.assign(Object.assign({}, COMPILER_OPTIONS.environment), userOpts.environment) })); + const userLogger = options.logger; + options.logger = { + logEvent: (eventFilename, event) => { + var _a, _b; + userLogger === null || userLogger === void 0 ? void 0 : userLogger.logEvent(eventFilename, event); + if (event.kind === 'CompileError') { + shouldReportUnusedOptOutDirective = false; + const detail = event.detail; + const suggest = makeSuggestions(detail); + if (__unstable_donotuse_reportAllBailouts && event.fnLoc != null) { + const locStr = detail.loc != null && typeof detail.loc !== 'symbol' + ? ` (@:${detail.loc.start.line}:${detail.loc.start.column})` + : ''; + let endLoc; + if (event.fnLoc.end.line === event.fnLoc.start.line) { + endLoc = event.fnLoc.end; + } + else { + endLoc = { + line: event.fnLoc.start.line, + column: (_b = (_a = sourceCode.text.split(/\r?\n|\r|\n/g)[event.fnLoc.start.line - 1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0, + }; + } + const firstLineLoc = { + start: event.fnLoc.start, + end: endLoc, + }; + context.report({ + message: `[ReactCompilerBailout] ${detail.reason}${locStr}`, + loc: firstLineLoc, + suggest, + }); + } + if (!isReportableDiagnostic(detail)) { + return; + } + if (hasFlowSuppression(detail.loc, 'react-rule-hook') || + hasFlowSuppression(detail.loc, 'react-rule-unsafe-ref')) { + return; + } + const loc = detail.loc == null || typeof detail.loc === 'symbol' + ? event.fnLoc + : detail.loc; + if (loc != null) { + context.report({ + message: detail.reason, + loc, + suggest, + }); + } + } + }, + }; + try { + options.environment = validateEnvironmentConfig((_d = options.environment) !== null && _d !== void 0 ? _d : {}); + } + catch (err) { + (_e = options.logger) === null || _e === void 0 ? void 0 : _e.logEvent('', err); + } + function hasFlowSuppression(nodeLoc, suppression) { + const comments = sourceCode.getAllComments(); + const flowSuppressionRegex = new RegExp('\\$FlowFixMe\\[' + suppression + '\\]'); + for (const commentNode of comments) { + if (flowSuppressionRegex.test(commentNode.value) && + commentNode.loc.end.line === nodeLoc.start.line - 1) { + return true; + } + } + return false; + } + let babelAST; + if (filename.endsWith('.tsx') || filename.endsWith('.ts')) { + try { + const { parse: babelParse } = require('@babel/parser'); + babelAST = babelParse(sourceCode.text, { + filename, + sourceType: 'unambiguous', + plugins: ['typescript', 'jsx'], + }); + } + catch (_f) { + } + } + else { + try { + babelAST = HermesParser.parse(sourceCode.text, { + babel: true, + enableExperimentalComponentSyntax: true, + sourceFilename: filename, + sourceType: 'module', + }); + } + catch (_g) { + } + } + if (babelAST != null) { + try { + core$1.transformFromAstSync(babelAST, sourceCode.text, { + filename, + highlightCode: false, + retainLines: true, + plugins: [ + [PluginProposalPrivateMethods.default, { loose: true }], + [BabelPluginReactCompiler, options], + ], + sourceType: 'module', + configFile: false, + babelrc: false, + }); + } + catch (err) { + } + } + function reportUnusedOptOutDirective(stmt) { + if (stmt.type === 'ExpressionStatement' && + stmt.expression.type === 'Literal' && + typeof stmt.expression.value === 'string' && + OPT_OUT_DIRECTIVES.has(stmt.expression.value) && + stmt.loc != null) { + context.report({ + message: `Unused '${stmt.expression.value}' directive`, + loc: stmt.loc, + suggest: [ + { + desc: 'Remove the directive', + fix(fixer) { + return fixer.remove(stmt); + }, + }, + ], + }); + } + } + if (shouldReportUnusedOptOutDirective) { + return { + FunctionDeclaration(fnDecl) { + for (const stmt of fnDecl.body.body) { + reportUnusedOptOutDirective(stmt); + } + }, + ArrowFunctionExpression(fnExpr) { + if (fnExpr.body.type === 'BlockStatement') { + for (const stmt of fnExpr.body.body) { + reportUnusedOptOutDirective(stmt); + } + } + }, + FunctionExpression(fnExpr) { + for (const stmt of fnExpr.body.body) { + reportUnusedOptOutDirective(stmt); + } + }, + }; + } + else { + return {}; + } + }, +}; + +var assert_1; +var hasRequiredAssert; +function requireAssert() { + if (hasRequiredAssert) return assert_1; + hasRequiredAssert = 1; + function assert(cond) { + if (!cond) { + throw new Error('Assertion violated.'); + } + } + assert_1 = assert; + return assert_1; +} + +var codePathSegment; +var hasRequiredCodePathSegment; +function requireCodePathSegment() { + if (hasRequiredCodePathSegment) return codePathSegment; + hasRequiredCodePathSegment = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Checks whether or not a given segment is reachable. + * @param {CodePathSegment} segment A segment to check. + * @returns {boolean} `true` if the segment is reachable. + */ + function isReachable(segment) { + return segment.reachable; + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A code path segment. + */ + class CodePathSegment { + /** + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * This array includes unreachable segments. + * @param {boolean} reachable A flag which shows this is reachable. + */ + constructor(id, allPrevSegments, reachable) { + /** + * The identifier of this code path. + * Rules use it to store additional information of each rule. + * @type {string} + */ + this.id = id; + + /** + * An array of the next segments. + * @type {CodePathSegment[]} + */ + this.nextSegments = []; + + /** + * An array of the previous segments. + * @type {CodePathSegment[]} + */ + this.prevSegments = allPrevSegments.filter(isReachable); + + /** + * An array of the next segments. + * This array includes unreachable segments. + * @type {CodePathSegment[]} + */ + this.allNextSegments = []; + + /** + * An array of the previous segments. + * This array includes unreachable segments. + * @type {CodePathSegment[]} + */ + this.allPrevSegments = allPrevSegments; + + /** + * A flag which shows this is reachable. + * @type {boolean} + */ + this.reachable = reachable; + + // Internal data. + Object.defineProperty(this, 'internal', { + value: { + used: false, + loopedPrevSegments: [] + } + }); + } + + /** + * Checks a given previous segment is coming from the end of a loop. + * @param {CodePathSegment} segment A previous segment to check. + * @returns {boolean} `true` if the segment is coming from the end of a loop. + */ + isLoopedPrevSegment(segment) { + return this.internal.loopedPrevSegments.includes(segment); + } + + /** + * Creates the root segment. + * @param {string} id An identifier. + * @returns {CodePathSegment} The created segment. + */ + static newRoot(id) { + return new CodePathSegment(id, [], true); + } + + /** + * Creates a segment that follows given segments. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newNext(id, allPrevSegments) { + return new CodePathSegment(id, CodePathSegment.flattenUnusedSegments(allPrevSegments), allPrevSegments.some(isReachable)); + } + + /** + * Creates an unreachable segment that follows given segments. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newUnreachable(id, allPrevSegments) { + const segment = new CodePathSegment(id, CodePathSegment.flattenUnusedSegments(allPrevSegments), false); + + /* + * In `if (a) return a; foo();` case, the unreachable segment preceded by + * the return statement is not used but must not be remove. + */ + CodePathSegment.markUsed(segment); + return segment; + } + + /** + * Creates a segment that follows given segments. + * This factory method does not connect with `allPrevSegments`. + * But this inherits `reachable` flag. + * @param {string} id An identifier. + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. + * @returns {CodePathSegment} The created segment. + */ + static newDisconnected(id, allPrevSegments) { + return new CodePathSegment(id, [], allPrevSegments.some(isReachable)); + } + + /** + * Makes a given segment being used. + * + * And this function registers the segment into the previous segments as a next. + * @param {CodePathSegment} segment A segment to mark. + * @returns {void} + */ + static markUsed(segment) { + if (segment.internal.used) { + return; + } + segment.internal.used = true; + let i; + if (segment.reachable) { + for (i = 0; i < segment.allPrevSegments.length; ++i) { + const prevSegment = segment.allPrevSegments[i]; + prevSegment.allNextSegments.push(segment); + prevSegment.nextSegments.push(segment); + } + } else { + for (i = 0; i < segment.allPrevSegments.length; ++i) { + segment.allPrevSegments[i].allNextSegments.push(segment); + } + } + } + + /** + * Marks a previous segment as looped. + * @param {CodePathSegment} segment A segment. + * @param {CodePathSegment} prevSegment A previous segment to mark. + * @returns {void} + */ + static markPrevSegmentAsLooped(segment, prevSegment) { + segment.internal.loopedPrevSegments.push(prevSegment); + } + + /** + * Replaces unused segments with the previous segments of each unused segment. + * @param {CodePathSegment[]} segments An array of segments to replace. + * @returns {CodePathSegment[]} The replaced array. + */ + static flattenUnusedSegments(segments) { + const done = Object.create(null); + const retv = []; + for (let i = 0; i < segments.length; ++i) { + const segment = segments[i]; + + // Ignores duplicated. + if (done[segment.id]) { + continue; + } + + // Use previous segments if unused. + if (!segment.internal.used) { + for (let j = 0; j < segment.allPrevSegments.length; ++j) { + const prevSegment = segment.allPrevSegments[j]; + if (!done[prevSegment.id]) { + done[prevSegment.id] = true; + retv.push(prevSegment); + } + } + } else { + done[segment.id] = true; + retv.push(segment); + } + } + return retv; + } + } + codePathSegment = CodePathSegment; + return codePathSegment; +} + +var forkContext; +var hasRequiredForkContext; +function requireForkContext() { + if (hasRequiredForkContext) return forkContext; + hasRequiredForkContext = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + const assert = requireAssert(); + // eslint-disable-next-line + const CodePathSegment = requireCodePathSegment(); + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Gets whether or not a given segment is reachable. + * @param {CodePathSegment} segment A segment to get. + * @returns {boolean} `true` if the segment is reachable. + */ + function isReachable(segment) { + return segment.reachable; + } + + /** + * Creates new segments from the specific range of `context.segmentsList`. + * + * When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and + * `end` is `-1`, this creates `[g, h]`. This `g` is from `a`, `c`, and `e`. + * This `h` is from `b`, `d`, and `f`. + * @param {ForkContext} context An instance. + * @param {number} begin The first index of the previous segments. + * @param {number} end The last index of the previous segments. + * @param {Function} create A factory function of new segments. + * @returns {CodePathSegment[]} New segments. + */ + function makeSegments(context, begin, end, create) { + const list = context.segmentsList; + const normalizedBegin = begin >= 0 ? begin : list.length + begin; + const normalizedEnd = end >= 0 ? end : list.length + end; + const segments = []; + for (let i = 0; i < context.count; ++i) { + const allPrevSegments = []; + for (let j = normalizedBegin; j <= normalizedEnd; ++j) { + allPrevSegments.push(list[j][i]); + } + segments.push(create(context.idGenerator.next(), allPrevSegments)); + } + return segments; + } + + /** + * `segments` becomes doubly in a `finally` block. Then if a code path exits by a + * control statement (such as `break`, `continue`) from the `finally` block, the + * destination's segments may be half of the source segments. In that case, this + * merges segments. + * @param {ForkContext} context An instance. + * @param {CodePathSegment[]} segments Segments to merge. + * @returns {CodePathSegment[]} The merged segments. + */ + function mergeExtraSegments(context, segments) { + let currentSegments = segments; + while (currentSegments.length > context.count) { + const merged = []; + for (let i = 0, length = currentSegments.length / 2 | 0; i < length; ++i) { + merged.push(CodePathSegment.newNext(context.idGenerator.next(), [currentSegments[i], currentSegments[i + length]])); + } + currentSegments = merged; + } + return currentSegments; + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A class to manage forking. + */ + class ForkContext { + /** + * @param {IdGenerator} idGenerator An identifier generator for segments. + * @param {ForkContext|null} upper An upper fork context. + * @param {number} count A number of parallel segments. + */ + constructor(idGenerator, upper, count) { + this.idGenerator = idGenerator; + this.upper = upper; + this.count = count; + this.segmentsList = []; + } + + /** + * The head segments. + * @type {CodePathSegment[]} + */ + get head() { + const list = this.segmentsList; + return list.length === 0 ? [] : list[list.length - 1]; + } + + /** + * A flag which shows empty. + * @type {boolean} + */ + get empty() { + return this.segmentsList.length === 0; + } + + /** + * A flag which shows reachable. + * @type {boolean} + */ + get reachable() { + const segments = this.head; + return segments.length > 0 && segments.some(isReachable); + } + + /** + * Creates new segments from this context. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeNext(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newNext); + } + + /** + * Creates new segments from this context. + * The new segments is always unreachable. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeUnreachable(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newUnreachable); + } + + /** + * Creates new segments from this context. + * The new segments don't have connections for previous segments. + * But these inherit the reachable flag from this context. + * @param {number} begin The first index of previous segments. + * @param {number} end The last index of previous segments. + * @returns {CodePathSegment[]} New segments. + */ + makeDisconnected(begin, end) { + return makeSegments(this, begin, end, CodePathSegment.newDisconnected); + } + + /** + * Adds segments into this context. + * The added segments become the head. + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + add(segments) { + assert(segments.length >= this.count, segments.length + " >= " + this.count); + this.segmentsList.push(mergeExtraSegments(this, segments)); + } + + /** + * Replaces the head segments with given segments. + * The current head segments are removed. + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + replaceHead(segments) { + assert(segments.length >= this.count, segments.length + " >= " + this.count); + this.segmentsList.splice(-1, 1, mergeExtraSegments(this, segments)); + } + + /** + * Adds all segments of a given fork context into this context. + * @param {ForkContext} context A fork context to add. + * @returns {void} + */ + addAll(context) { + assert(context.count === this.count); + const source = context.segmentsList; + for (let i = 0; i < source.length; ++i) { + this.segmentsList.push(source[i]); + } + } + + /** + * Clears all segments in this context. + * @returns {void} + */ + clear() { + this.segmentsList = []; + } + + /** + * Creates the root fork context. + * @param {IdGenerator} idGenerator An identifier generator for segments. + * @returns {ForkContext} New fork context. + */ + static newRoot(idGenerator) { + const context = new ForkContext(idGenerator, null, 1); + context.add([CodePathSegment.newRoot(idGenerator.next())]); + return context; + } + + /** + * Creates an empty fork context preceded by a given context. + * @param {ForkContext} parentContext The parent fork context. + * @param {boolean} forkLeavingPath A flag which shows inside of `finally` block. + * @returns {ForkContext} New fork context. + */ + static newEmpty(parentContext, forkLeavingPath) { + return new ForkContext(parentContext.idGenerator, parentContext, (forkLeavingPath ? 2 : 1) * parentContext.count); + } + } + forkContext = ForkContext; + return forkContext; +} + +var codePathState; +var hasRequiredCodePathState; +function requireCodePathState() { + if (hasRequiredCodePathState) return codePathState; + hasRequiredCodePathState = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + const CodePathSegment = requireCodePathSegment(); + // eslint-disable-next-line + const ForkContext = requireForkContext(); + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Adds given segments into the `dest` array. + * If the `others` array does not includes the given segments, adds to the `all` + * array as well. + * + * This adds only reachable and used segments. + * @param {CodePathSegment[]} dest A destination array (`returnedSegments` or `thrownSegments`). + * @param {CodePathSegment[]} others Another destination array (`returnedSegments` or `thrownSegments`). + * @param {CodePathSegment[]} all The unified destination array (`finalSegments`). + * @param {CodePathSegment[]} segments Segments to add. + * @returns {void} + */ + function addToReturnedOrThrown(dest, others, all, segments) { + for (let i = 0; i < segments.length; ++i) { + const segment = segments[i]; + dest.push(segment); + if (!others.includes(segment)) { + all.push(segment); + } + } + } + + /** + * Gets a loop-context for a `continue` statement. + * @param {CodePathState} state A state to get. + * @param {string} label The label of a `continue` statement. + * @returns {LoopContext} A loop-context for a `continue` statement. + */ + function getContinueContext(state, label) { + if (!label) { + return state.loopContext; + } + let context = state.loopContext; + while (context) { + if (context.label === label) { + return context; + } + context = context.upper; + } + + /* c8 ignore next */ + return null; + } + + /** + * Gets a context for a `break` statement. + * @param {CodePathState} state A state to get. + * @param {string} label The label of a `break` statement. + * @returns {LoopContext|SwitchContext} A context for a `break` statement. + */ + function getBreakContext(state, label) { + let context = state.breakContext; + while (context) { + if (label ? context.label === label : context.breakable) { + return context; + } + context = context.upper; + } + + /* c8 ignore next */ + return null; + } + + /** + * Gets a context for a `return` statement. + * @param {CodePathState} state A state to get. + * @returns {TryContext|CodePathState} A context for a `return` statement. + */ + function getReturnContext(state) { + let context = state.tryContext; + while (context) { + if (context.hasFinalizer && context.position !== 'finally') { + return context; + } + context = context.upper; + } + return state; + } + + /** + * Gets a context for a `throw` statement. + * @param {CodePathState} state A state to get. + * @returns {TryContext|CodePathState} A context for a `throw` statement. + */ + function getThrowContext(state) { + let context = state.tryContext; + while (context) { + if (context.position === 'try' || context.hasFinalizer && context.position === 'catch') { + return context; + } + context = context.upper; + } + return state; + } + + /** + * Removes a given element from a given array. + * @param {any[]} xs An array to remove the specific element. + * @param {any} x An element to be removed. + * @returns {void} + */ + function remove(xs, x) { + xs.splice(xs.indexOf(x), 1); + } + + /** + * Disconnect given segments. + * + * This is used in a process for switch statements. + * If there is the "default" chunk before other cases, the order is different + * between node's and running's. + * @param {CodePathSegment[]} prevSegments Forward segments to disconnect. + * @param {CodePathSegment[]} nextSegments Backward segments to disconnect. + * @returns {void} + */ + function removeConnection(prevSegments, nextSegments) { + for (let i = 0; i < prevSegments.length; ++i) { + const prevSegment = prevSegments[i]; + const nextSegment = nextSegments[i]; + remove(prevSegment.nextSegments, nextSegment); + remove(prevSegment.allNextSegments, nextSegment); + remove(nextSegment.prevSegments, prevSegment); + remove(nextSegment.allPrevSegments, prevSegment); + } + } + + /** + * Creates looping path. + * @param {CodePathState} state The instance. + * @param {CodePathSegment[]} unflattenedFromSegments Segments which are source. + * @param {CodePathSegment[]} unflattenedToSegments Segments which are destination. + * @returns {void} + */ + function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) { + const fromSegments = CodePathSegment.flattenUnusedSegments(unflattenedFromSegments); + const toSegments = CodePathSegment.flattenUnusedSegments(unflattenedToSegments); + const end = Math.min(fromSegments.length, toSegments.length); + for (let i = 0; i < end; ++i) { + const fromSegment = fromSegments[i]; + const toSegment = toSegments[i]; + if (toSegment.reachable) { + fromSegment.nextSegments.push(toSegment); + } + if (fromSegment.reachable) { + toSegment.prevSegments.push(fromSegment); + } + fromSegment.allNextSegments.push(toSegment); + toSegment.allPrevSegments.push(fromSegment); + if (toSegment.allPrevSegments.length >= 2) { + CodePathSegment.markPrevSegmentAsLooped(toSegment, fromSegment); + } + state.notifyLooped(fromSegment, toSegment); + } + } + + /** + * Finalizes segments of `test` chunk of a ForStatement. + * + * - Adds `false` paths to paths which are leaving from the loop. + * - Sets `true` paths to paths which go to the body. + * @param {LoopContext} context A loop context to modify. + * @param {ChoiceContext} choiceContext A choice context of this loop. + * @param {CodePathSegment[]} head The current head paths. + * @returns {void} + */ + function finalizeTestSegmentsOfFor(context, choiceContext, head) { + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(head); + choiceContext.falseForkContext.add(head); + choiceContext.qqForkContext.add(head); + } + if (context.test !== true) { + context.brokenForkContext.addAll(choiceContext.falseForkContext); + } + context.endOfTestSegments = choiceContext.trueForkContext.makeNext(0, -1); + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A class which manages state to analyze code paths. + */ + class CodePathState { + /** + * @param {IdGenerator} idGenerator An id generator to generate id for code + * path segments. + * @param {Function} onLooped A callback function to notify looping. + */ + constructor(idGenerator, onLooped) { + this.idGenerator = idGenerator; + this.notifyLooped = onLooped; + this.forkContext = ForkContext.newRoot(idGenerator); + this.choiceContext = null; + this.switchContext = null; + this.tryContext = null; + this.loopContext = null; + this.breakContext = null; + this.chainContext = null; + this.currentSegments = []; + this.initialSegment = this.forkContext.head[0]; + + // returnedSegments and thrownSegments push elements into finalSegments also. + const final = this.finalSegments = []; + const returned = this.returnedForkContext = []; + const thrown = this.thrownForkContext = []; + returned.add = addToReturnedOrThrown.bind(null, returned, thrown, final); + thrown.add = addToReturnedOrThrown.bind(null, thrown, returned, final); + } + + /** + * The head segments. + * @type {CodePathSegment[]} + */ + get headSegments() { + return this.forkContext.head; + } + + /** + * The parent forking context. + * This is used for the root of new forks. + * @type {ForkContext} + */ + get parentForkContext() { + const current = this.forkContext; + return current && current.upper; + } + + /** + * Creates and stacks new forking context. + * @param {boolean} forkLeavingPath A flag which shows being in a + * "finally" block. + * @returns {ForkContext} The created context. + */ + pushForkContext(forkLeavingPath) { + this.forkContext = ForkContext.newEmpty(this.forkContext, forkLeavingPath); + return this.forkContext; + } + + /** + * Pops and merges the last forking context. + * @returns {ForkContext} The last context. + */ + popForkContext() { + const lastContext = this.forkContext; + this.forkContext = lastContext.upper; + this.forkContext.replaceHead(lastContext.makeNext(0, -1)); + return lastContext; + } + + /** + * Creates a new path. + * @returns {void} + */ + forkPath() { + this.forkContext.add(this.parentForkContext.makeNext(-1, -1)); + } + + /** + * Creates a bypass path. + * This is used for such as IfStatement which does not have "else" chunk. + * @returns {void} + */ + forkBypassPath() { + this.forkContext.add(this.parentForkContext.head); + } + + //-------------------------------------------------------------------------- + // ConditionalExpression, LogicalExpression, IfStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context for ConditionalExpression, LogicalExpression, AssignmentExpression (logical assignments only), + * IfStatement, WhileStatement, DoWhileStatement, or ForStatement. + * + * LogicalExpressions have cases that it goes different paths between the + * `true` case and the `false` case. + * + * For Example: + * + * if (a || b) { + * foo(); + * } else { + * bar(); + * } + * + * In this case, `b` is evaluated always in the code path of the `else` + * block, but it's not so in the code path of the `if` block. + * So there are 3 paths. + * + * a -> foo(); + * a -> b -> foo(); + * a -> b -> bar(); + * @param {string} kind A kind string. + * If the new context is LogicalExpression's or AssignmentExpression's, this is `"&&"` or `"||"` or `"??"`. + * If it's IfStatement's or ConditionalExpression's, this is `"test"`. + * Otherwise, this is `"loop"`. + * @param {boolean} isForkingAsResult A flag that shows that goes different + * paths between `true` and `false`. + * @returns {void} + */ + pushChoiceContext(kind, isForkingAsResult) { + this.choiceContext = { + upper: this.choiceContext, + kind, + isForkingAsResult, + trueForkContext: ForkContext.newEmpty(this.forkContext), + falseForkContext: ForkContext.newEmpty(this.forkContext), + qqForkContext: ForkContext.newEmpty(this.forkContext), + processed: false + }; + } + + /** + * Pops the last choice context and finalizes it. + * @throws {Error} (Unreachable.) + * @returns {ChoiceContext} The popped context. + */ + popChoiceContext() { + const context = this.choiceContext; + this.choiceContext = context.upper; + const forkContext = this.forkContext; + const headSegments = forkContext.head; + switch (context.kind) { + case '&&': + case '||': + case '??': + /* + * If any result were not transferred from child contexts, + * this sets the head segments to both cases. + * The head segments are the path of the right-hand operand. + */ + if (!context.processed) { + context.trueForkContext.add(headSegments); + context.falseForkContext.add(headSegments); + context.qqForkContext.add(headSegments); + } + + /* + * Transfers results to upper context if this context is in + * test chunk. + */ + if (context.isForkingAsResult) { + const parentContext = this.choiceContext; + parentContext.trueForkContext.addAll(context.trueForkContext); + parentContext.falseForkContext.addAll(context.falseForkContext); + parentContext.qqForkContext.addAll(context.qqForkContext); + parentContext.processed = true; + return context; + } + break; + case 'test': + if (!context.processed) { + /* + * The head segments are the path of the `if` block here. + * Updates the `true` path with the end of the `if` block. + */ + context.trueForkContext.clear(); + context.trueForkContext.add(headSegments); + } else { + /* + * The head segments are the path of the `else` block here. + * Updates the `false` path with the end of the `else` + * block. + */ + context.falseForkContext.clear(); + context.falseForkContext.add(headSegments); + } + break; + case 'loop': + /* + * Loops are addressed in popLoopContext(). + * This is called from popLoopContext(). + */ + return context; + + /* c8 ignore next */ + default: + throw new Error('unreachable'); + } + + // Merges all paths. + const prevForkContext = context.trueForkContext; + prevForkContext.addAll(context.falseForkContext); + forkContext.replaceHead(prevForkContext.makeNext(0, -1)); + return context; + } + + /** + * Makes a code path segment of the right-hand operand of a logical + * expression. + * @throws {Error} (Unreachable.) + * @returns {void} + */ + makeLogicalRight() { + const context = this.choiceContext; + const forkContext = this.forkContext; + if (context.processed) { + /* + * This got segments already from the child choice context. + * Creates the next path from own true/false fork context. + */ + let prevForkContext; + switch (context.kind) { + case '&&': + // if true then go to the right-hand side. + prevForkContext = context.trueForkContext; + break; + case '||': + // if false then go to the right-hand side. + prevForkContext = context.falseForkContext; + break; + case '??': + // Both true/false can short-circuit, so needs the third path to go to the right-hand side. That's qqForkContext. + prevForkContext = context.qqForkContext; + break; + default: + throw new Error('unreachable'); + } + forkContext.replaceHead(prevForkContext.makeNext(0, -1)); + prevForkContext.clear(); + context.processed = false; + } else { + /* + * This did not get segments from the child choice context. + * So addresses the head segments. + * The head segments are the path of the left-hand operand. + */ + switch (context.kind) { + case '&&': + // the false path can short-circuit. + context.falseForkContext.add(forkContext.head); + break; + case '||': + // the true path can short-circuit. + context.trueForkContext.add(forkContext.head); + break; + case '??': + // both can short-circuit. + context.trueForkContext.add(forkContext.head); + context.falseForkContext.add(forkContext.head); + break; + default: + throw new Error('unreachable'); + } + forkContext.replaceHead(forkContext.makeNext(-1, -1)); + } + } + + /** + * Makes a code path segment of the `if` block. + * @returns {void} + */ + makeIfConsequent() { + const context = this.choiceContext; + const forkContext = this.forkContext; + + /* + * If any result were not transferred from child contexts, + * this sets the head segments to both cases. + * The head segments are the path of the test expression. + */ + if (!context.processed) { + context.trueForkContext.add(forkContext.head); + context.falseForkContext.add(forkContext.head); + context.qqForkContext.add(forkContext.head); + } + context.processed = false; + + // Creates new path from the `true` case. + forkContext.replaceHead(context.trueForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment of the `else` block. + * @returns {void} + */ + makeIfAlternate() { + const context = this.choiceContext; + const forkContext = this.forkContext; + + /* + * The head segments are the path of the `if` block. + * Updates the `true` path with the end of the `if` block. + */ + context.trueForkContext.clear(); + context.trueForkContext.add(forkContext.head); + context.processed = true; + + // Creates new path from the `false` case. + forkContext.replaceHead(context.falseForkContext.makeNext(0, -1)); + } + + //-------------------------------------------------------------------------- + // ChainExpression + //-------------------------------------------------------------------------- + + /** + * Push a new `ChainExpression` context to the stack. + * This method is called on entering to each `ChainExpression` node. + * This context is used to count forking in the optional chain then merge them on the exiting from the `ChainExpression` node. + * @returns {void} + */ + pushChainContext() { + this.chainContext = { + upper: this.chainContext, + countChoiceContexts: 0 + }; + } + + /** + * Pop a `ChainExpression` context from the stack. + * This method is called on exiting from each `ChainExpression` node. + * This merges all forks of the last optional chaining. + * @returns {void} + */ + popChainContext() { + const context = this.chainContext; + this.chainContext = context.upper; + + // pop all choice contexts of this. + for (let i = context.countChoiceContexts; i > 0; --i) { + this.popChoiceContext(); + } + } + + /** + * Create a choice context for optional access. + * This method is called on entering to each `(Call|Member)Expression[optional=true]` node. + * This creates a choice context as similar to `LogicalExpression[operator="??"]` node. + * @returns {void} + */ + makeOptionalNode() { + if (this.chainContext) { + this.chainContext.countChoiceContexts += 1; + this.pushChoiceContext('??', false); + } + } + + /** + * Create a fork. + * This method is called on entering to the `arguments|property` property of each `(Call|Member)Expression` node. + * @returns {void} + */ + makeOptionalRight() { + if (this.chainContext) { + this.makeLogicalRight(); + } + } + + //-------------------------------------------------------------------------- + // SwitchStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context object of SwitchStatement and stacks it. + * @param {boolean} hasCase `true` if the switch statement has one or more + * case parts. + * @param {string|null} label The label text. + * @returns {void} + */ + pushSwitchContext(hasCase, label) { + this.switchContext = { + upper: this.switchContext, + hasCase, + defaultSegments: null, + defaultBodySegments: null, + foundDefault: false, + lastIsDefault: false, + countForks: 0 + }; + this.pushBreakContext(true, label); + } + + /** + * Pops the last context of SwitchStatement and finalizes it. + * + * - Disposes all forking stack for `case` and `default`. + * - Creates the next code path segment from `context.brokenForkContext`. + * - If the last `SwitchCase` node is not a `default` part, creates a path + * to the `default` body. + * @returns {void} + */ + popSwitchContext() { + const context = this.switchContext; + this.switchContext = context.upper; + const forkContext = this.forkContext; + const brokenForkContext = this.popBreakContext().brokenForkContext; + if (context.countForks === 0) { + /* + * When there is only one `default` chunk and there is one or more + * `break` statements, even if forks are nothing, it needs to merge + * those. + */ + if (!brokenForkContext.empty) { + brokenForkContext.add(forkContext.makeNext(-1, -1)); + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + return; + } + const lastSegments = forkContext.head; + this.forkBypassPath(); + const lastCaseSegments = forkContext.head; + + /* + * `brokenForkContext` is used to make the next segment. + * It must add the last segment into `brokenForkContext`. + */ + brokenForkContext.add(lastSegments); + + /* + * A path which is failed in all case test should be connected to path + * of `default` chunk. + */ + if (!context.lastIsDefault) { + if (context.defaultBodySegments) { + /* + * Remove a link from `default` label to its chunk. + * It's false route. + */ + removeConnection(context.defaultSegments, context.defaultBodySegments); + makeLooped(this, lastCaseSegments, context.defaultBodySegments); + } else { + /* + * It handles the last case body as broken if `default` chunk + * does not exist. + */ + brokenForkContext.add(lastCaseSegments); + } + } + + // Pops the segment context stack until the entry segment. + for (let i = 0; i < context.countForks; ++i) { + this.forkContext = this.forkContext.upper; + } + + /* + * Creates a path from all brokenForkContext paths. + * This is a path after switch statement. + */ + this.forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment for a `SwitchCase` node. + * @param {boolean} isEmpty `true` if the body is empty. + * @param {boolean} isDefault `true` if the body is the default case. + * @returns {void} + */ + makeSwitchCaseBody(isEmpty, isDefault) { + const context = this.switchContext; + if (!context.hasCase) { + return; + } + + /* + * Merge forks. + * The parent fork context has two segments. + * Those are from the current case and the body of the previous case. + */ + const parentForkContext = this.forkContext; + const forkContext = this.pushForkContext(); + forkContext.add(parentForkContext.makeNext(0, -1)); + + /* + * Save `default` chunk info. + * If the `default` label is not at the last, we must make a path from + * the last `case` to the `default` chunk. + */ + if (isDefault) { + context.defaultSegments = parentForkContext.head; + if (isEmpty) { + context.foundDefault = true; + } else { + context.defaultBodySegments = forkContext.head; + } + } else { + if (!isEmpty && context.foundDefault) { + context.foundDefault = false; + context.defaultBodySegments = forkContext.head; + } + } + context.lastIsDefault = isDefault; + context.countForks += 1; + } + + //-------------------------------------------------------------------------- + // TryStatement + //-------------------------------------------------------------------------- + + /** + * Creates a context object of TryStatement and stacks it. + * @param {boolean} hasFinalizer `true` if the try statement has a + * `finally` block. + * @returns {void} + */ + pushTryContext(hasFinalizer) { + this.tryContext = { + upper: this.tryContext, + position: 'try', + hasFinalizer, + returnedForkContext: hasFinalizer ? ForkContext.newEmpty(this.forkContext) : null, + thrownForkContext: ForkContext.newEmpty(this.forkContext), + lastOfTryIsReachable: false, + lastOfCatchIsReachable: false + }; + } + + /** + * Pops the last context of TryStatement and finalizes it. + * @returns {void} + */ + popTryContext() { + const context = this.tryContext; + this.tryContext = context.upper; + if (context.position === 'catch') { + // Merges two paths from the `try` block and `catch` block merely. + this.popForkContext(); + return; + } + + /* + * The following process is executed only when there is the `finally` + * block. + */ + + const returned = context.returnedForkContext; + const thrown = context.thrownForkContext; + if (returned.empty && thrown.empty) { + return; + } + + // Separate head to normal paths and leaving paths. + const headSegments = this.forkContext.head; + this.forkContext = this.forkContext.upper; + const normalSegments = headSegments.slice(0, headSegments.length / 2 | 0); + const leavingSegments = headSegments.slice(headSegments.length / 2 | 0); + + // Forwards the leaving path to upper contexts. + if (!returned.empty) { + getReturnContext(this).returnedForkContext.add(leavingSegments); + } + if (!thrown.empty) { + getThrowContext(this).thrownForkContext.add(leavingSegments); + } + + // Sets the normal path as the next. + this.forkContext.replaceHead(normalSegments); + + /* + * If both paths of the `try` block and the `catch` block are + * unreachable, the next path becomes unreachable as well. + */ + if (!context.lastOfTryIsReachable && !context.lastOfCatchIsReachable) { + this.forkContext.makeUnreachable(); + } + } + + /** + * Makes a code path segment for a `catch` block. + * @returns {void} + */ + makeCatchBlock() { + const context = this.tryContext; + const forkContext = this.forkContext; + const thrown = context.thrownForkContext; + + // Update state. + context.position = 'catch'; + context.thrownForkContext = ForkContext.newEmpty(forkContext); + context.lastOfTryIsReachable = forkContext.reachable; + + // Merge thrown paths. + thrown.add(forkContext.head); + const thrownSegments = thrown.makeNext(0, -1); + + // Fork to a bypass and the merged thrown path. + this.pushForkContext(); + this.forkBypassPath(); + this.forkContext.add(thrownSegments); + } + + /** + * Makes a code path segment for a `finally` block. + * + * In the `finally` block, parallel paths are created. The parallel paths + * are used as leaving-paths. The leaving-paths are paths from `return` + * statements and `throw` statements in a `try` block or a `catch` block. + * @returns {void} + */ + makeFinallyBlock() { + const context = this.tryContext; + let forkContext = this.forkContext; + const returned = context.returnedForkContext; + const thrown = context.thrownForkContext; + const headOfLeavingSegments = forkContext.head; + + // Update state. + if (context.position === 'catch') { + // Merges two paths from the `try` block and `catch` block. + this.popForkContext(); + forkContext = this.forkContext; + context.lastOfCatchIsReachable = forkContext.reachable; + } else { + context.lastOfTryIsReachable = forkContext.reachable; + } + context.position = 'finally'; + if (returned.empty && thrown.empty) { + // This path does not leave. + return; + } + + /* + * Create a parallel segment from merging returned and thrown. + * This segment will leave at the end of this finally block. + */ + const segments = forkContext.makeNext(-1, -1); + for (let i = 0; i < forkContext.count; ++i) { + const prevSegsOfLeavingSegment = [headOfLeavingSegments[i]]; + for (let j = 0; j < returned.segmentsList.length; ++j) { + prevSegsOfLeavingSegment.push(returned.segmentsList[j][i]); + } + for (let j = 0; j < thrown.segmentsList.length; ++j) { + prevSegsOfLeavingSegment.push(thrown.segmentsList[j][i]); + } + segments.push(CodePathSegment.newNext(this.idGenerator.next(), prevSegsOfLeavingSegment)); + } + this.pushForkContext(true); + this.forkContext.add(segments); + } + + /** + * Makes a code path segment from the first throwable node to the `catch` + * block or the `finally` block. + * @returns {void} + */ + makeFirstThrowablePathInTryBlock() { + const forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + const context = getThrowContext(this); + if (context === this || context.position !== 'try' || !context.thrownForkContext.empty) { + return; + } + context.thrownForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeNext(-1, -1)); + } + + //-------------------------------------------------------------------------- + // Loop Statements + //-------------------------------------------------------------------------- + + /** + * Creates a context object of a loop statement and stacks it. + * @param {string} type The type of the node which was triggered. One of + * `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`, + * and `ForStatement`. + * @param {string|null} label A label of the node which was triggered. + * @throws {Error} (Unreachable - unknown type.) + * @returns {void} + */ + pushLoopContext(type, label) { + const forkContext = this.forkContext; + const breakContext = this.pushBreakContext(true, label); + switch (type) { + case 'WhileStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type, + label, + test: void 0, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'DoWhileStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type, + label, + test: void 0, + entrySegments: null, + continueForkContext: ForkContext.newEmpty(forkContext), + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'ForStatement': + this.pushChoiceContext('loop', false); + this.loopContext = { + upper: this.loopContext, + type, + label, + test: void 0, + endOfInitSegments: null, + testSegments: null, + endOfTestSegments: null, + updateSegments: null, + endOfUpdateSegments: null, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + case 'ForInStatement': + case 'ForOfStatement': + this.loopContext = { + upper: this.loopContext, + type, + label, + prevSegments: null, + leftSegments: null, + endOfLeftSegments: null, + continueDestSegments: null, + brokenForkContext: breakContext.brokenForkContext + }; + break; + + /* c8 ignore next */ + default: + throw new Error("unknown type: \"" + type + "\""); + } + } + + /** + * Pops the last context of a loop statement and finalizes it. + * @throws {Error} (Unreachable - unknown type.) + * @returns {void} + */ + popLoopContext() { + const context = this.loopContext; + this.loopContext = context.upper; + const forkContext = this.forkContext; + const brokenForkContext = this.popBreakContext().brokenForkContext; + + // Creates a looped path. + switch (context.type) { + case 'WhileStatement': + case 'ForStatement': + this.popChoiceContext(); + makeLooped(this, forkContext.head, context.continueDestSegments); + break; + case 'DoWhileStatement': + { + const choiceContext = this.popChoiceContext(); + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(forkContext.head); + choiceContext.falseForkContext.add(forkContext.head); + } + if (context.test !== true) { + brokenForkContext.addAll(choiceContext.falseForkContext); + } + + // `true` paths go to looping. + const segmentsList = choiceContext.trueForkContext.segmentsList; + for (let i = 0; i < segmentsList.length; ++i) { + makeLooped(this, segmentsList[i], context.entrySegments); + } + break; + } + case 'ForInStatement': + case 'ForOfStatement': + brokenForkContext.add(forkContext.head); + makeLooped(this, forkContext.head, context.leftSegments); + break; + + /* c8 ignore next */ + default: + throw new Error('unreachable'); + } + + // Go next. + if (brokenForkContext.empty) { + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } else { + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + } + + /** + * Makes a code path segment for the test part of a WhileStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeWhileTest(test) { + const context = this.loopContext; + const forkContext = this.forkContext; + const testSegments = forkContext.makeNext(0, -1); + + // Update state. + context.test = test; + context.continueDestSegments = testSegments; + forkContext.replaceHead(testSegments); + } + + /** + * Makes a code path segment for the body part of a WhileStatement. + * @returns {void} + */ + makeWhileBody() { + const context = this.loopContext; + const choiceContext = this.choiceContext; + const forkContext = this.forkContext; + if (!choiceContext.processed) { + choiceContext.trueForkContext.add(forkContext.head); + choiceContext.falseForkContext.add(forkContext.head); + } + + // Update state. + if (context.test !== true) { + context.brokenForkContext.addAll(choiceContext.falseForkContext); + } + forkContext.replaceHead(choiceContext.trueForkContext.makeNext(0, -1)); + } + + /** + * Makes a code path segment for the body part of a DoWhileStatement. + * @returns {void} + */ + makeDoWhileBody() { + const context = this.loopContext; + const forkContext = this.forkContext; + const bodySegments = forkContext.makeNext(-1, -1); + + // Update state. + context.entrySegments = bodySegments; + forkContext.replaceHead(bodySegments); + } + + /** + * Makes a code path segment for the test part of a DoWhileStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeDoWhileTest(test) { + const context = this.loopContext; + const forkContext = this.forkContext; + context.test = test; + + // Creates paths of `continue` statements. + if (!context.continueForkContext.empty) { + context.continueForkContext.add(forkContext.head); + const testSegments = context.continueForkContext.makeNext(0, -1); + forkContext.replaceHead(testSegments); + } + } + + /** + * Makes a code path segment for the test part of a ForStatement. + * @param {boolean|undefined} test The test value (only when constant). + * @returns {void} + */ + makeForTest(test) { + const context = this.loopContext; + const forkContext = this.forkContext; + const endOfInitSegments = forkContext.head; + const testSegments = forkContext.makeNext(-1, -1); + + // Update state. + context.test = test; + context.endOfInitSegments = endOfInitSegments; + context.continueDestSegments = context.testSegments = testSegments; + forkContext.replaceHead(testSegments); + } + + /** + * Makes a code path segment for the update part of a ForStatement. + * @returns {void} + */ + makeForUpdate() { + const context = this.loopContext; + const choiceContext = this.choiceContext; + const forkContext = this.forkContext; + + // Make the next paths of the test. + if (context.testSegments) { + finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head); + } else { + context.endOfInitSegments = forkContext.head; + } + + // Update state. + const updateSegments = forkContext.makeDisconnected(-1, -1); + context.continueDestSegments = context.updateSegments = updateSegments; + forkContext.replaceHead(updateSegments); + } + + /** + * Makes a code path segment for the body part of a ForStatement. + * @returns {void} + */ + makeForBody() { + const context = this.loopContext; + const choiceContext = this.choiceContext; + const forkContext = this.forkContext; + + // Update state. + if (context.updateSegments) { + context.endOfUpdateSegments = forkContext.head; + + // `update` -> `test` + if (context.testSegments) { + makeLooped(this, context.endOfUpdateSegments, context.testSegments); + } + } else if (context.testSegments) { + finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head); + } else { + context.endOfInitSegments = forkContext.head; + } + let bodySegments = context.endOfTestSegments; + if (!bodySegments) { + /* + * If there is not the `test` part, the `body` path comes from the + * `init` part and the `update` part. + */ + const prevForkContext = ForkContext.newEmpty(forkContext); + prevForkContext.add(context.endOfInitSegments); + if (context.endOfUpdateSegments) { + prevForkContext.add(context.endOfUpdateSegments); + } + bodySegments = prevForkContext.makeNext(0, -1); + } + context.continueDestSegments = context.continueDestSegments || bodySegments; + forkContext.replaceHead(bodySegments); + } + + /** + * Makes a code path segment for the left part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfLeft() { + const context = this.loopContext; + const forkContext = this.forkContext; + const leftSegments = forkContext.makeDisconnected(-1, -1); + + // Update state. + context.prevSegments = forkContext.head; + context.leftSegments = context.continueDestSegments = leftSegments; + forkContext.replaceHead(leftSegments); + } + + /** + * Makes a code path segment for the right part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfRight() { + const context = this.loopContext; + const forkContext = this.forkContext; + const temp = ForkContext.newEmpty(forkContext); + temp.add(context.prevSegments); + const rightSegments = temp.makeNext(-1, -1); + + // Update state. + context.endOfLeftSegments = forkContext.head; + forkContext.replaceHead(rightSegments); + } + + /** + * Makes a code path segment for the body part of a ForInStatement and a + * ForOfStatement. + * @returns {void} + */ + makeForInOfBody() { + const context = this.loopContext; + const forkContext = this.forkContext; + const temp = ForkContext.newEmpty(forkContext); + temp.add(context.endOfLeftSegments); + const bodySegments = temp.makeNext(-1, -1); + + // Make a path: `right` -> `left`. + makeLooped(this, forkContext.head, context.leftSegments); + + // Update state. + context.brokenForkContext.add(forkContext.head); + forkContext.replaceHead(bodySegments); + } + + //-------------------------------------------------------------------------- + // Control Statements + //-------------------------------------------------------------------------- + + /** + * Creates new context for BreakStatement. + * @param {boolean} breakable The flag to indicate it can break by + * an unlabeled BreakStatement. + * @param {string|null} label The label of this context. + * @returns {Object} The new context. + */ + pushBreakContext(breakable, label) { + this.breakContext = { + upper: this.breakContext, + breakable, + label, + brokenForkContext: ForkContext.newEmpty(this.forkContext) + }; + return this.breakContext; + } + + /** + * Removes the top item of the break context stack. + * @returns {Object} The removed context. + */ + popBreakContext() { + const context = this.breakContext; + const forkContext = this.forkContext; + this.breakContext = context.upper; + + // Process this context here for other than switches and loops. + if (!context.breakable) { + const brokenForkContext = context.brokenForkContext; + if (!brokenForkContext.empty) { + brokenForkContext.add(forkContext.head); + forkContext.replaceHead(brokenForkContext.makeNext(0, -1)); + } + } + return context; + } + + /** + * Makes a path for a `break` statement. + * + * It registers the head segment to a context of `break`. + * It makes new unreachable segment, then it set the head with the segment. + * @param {string} label A label of the break statement. + * @returns {void} + */ + makeBreak(label) { + const forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + const context = getBreakContext(this, label); + if (context) { + context.brokenForkContext.add(forkContext.head); + } + + /* c8 ignore next */ + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + + /** + * Makes a path for a `continue` statement. + * + * It makes a looping path. + * It makes new unreachable segment, then it set the head with the segment. + * @param {string} label A label of the continue statement. + * @returns {void} + */ + makeContinue(label) { + const forkContext = this.forkContext; + if (!forkContext.reachable) { + return; + } + const context = getContinueContext(this, label); + if (context) { + if (context.continueDestSegments) { + makeLooped(this, forkContext.head, context.continueDestSegments); + + // If the context is a for-in/of loop, this effects a break also. + if (context.type === 'ForInStatement' || context.type === 'ForOfStatement') { + context.brokenForkContext.add(forkContext.head); + } + } else { + context.continueForkContext.add(forkContext.head); + } + } + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + + /** + * Makes a path for a `return` statement. + * + * It registers the head segment to a context of `return`. + * It makes new unreachable segment, then it set the head with the segment. + * @returns {void} + */ + makeReturn() { + const forkContext = this.forkContext; + if (forkContext.reachable) { + getReturnContext(this).returnedForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + } + + /** + * Makes a path for a `throw` statement. + * + * It registers the head segment to a context of `throw`. + * It makes new unreachable segment, then it set the head with the segment. + * @returns {void} + */ + makeThrow() { + const forkContext = this.forkContext; + if (forkContext.reachable) { + getThrowContext(this).thrownForkContext.add(forkContext.head); + forkContext.replaceHead(forkContext.makeUnreachable(-1, -1)); + } + } + + /** + * Makes the final path. + * @returns {void} + */ + makeFinal() { + const segments = this.currentSegments; + if (segments.length > 0 && segments[0].reachable) { + this.returnedForkContext.add(segments); + } + } + } + codePathState = CodePathState; + return codePathState; +} + +var idGenerator; +var hasRequiredIdGenerator; +function requireIdGenerator() { + if (hasRequiredIdGenerator) return idGenerator; + hasRequiredIdGenerator = 1; + + /* eslint-disable react-internal/safe-string-coercion */ + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A generator for unique ids. + */ + class IdGenerator { + /** + * @param {string} prefix Optional. A prefix of generated ids. + */ + constructor(prefix) { + this.prefix = String(prefix); + this.n = 0; + } + + /** + * Generates id. + * @returns {string} A generated id. + */ + next() { + this.n = 1 + this.n | 0; + + /* c8 ignore start */ + if (this.n < 0) { + this.n = 1; + } /* c8 ignore stop */ + + return this.prefix + this.n; + } + } + idGenerator = IdGenerator; + return idGenerator; +} + +var codePath; +var hasRequiredCodePath; +function requireCodePath() { + if (hasRequiredCodePath) return codePath; + hasRequiredCodePath = 1; + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + const CodePathState = requireCodePathState(); + // eslint-disable-next-line + const IdGenerator = requireIdGenerator(); + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * A code path. + */ + class CodePath { + /** + * Creates a new instance. + * @param {Object} options Options for the function (see below). + * @param {string} options.id An identifier. + * @param {string} options.origin The type of code path origin. + * @param {CodePath|null} options.upper The code path of the upper function scope. + * @param {Function} options.onLooped A callback function to notify looping. + */ + constructor(_ref) { + let id = _ref.id, + origin = _ref.origin, + upper = _ref.upper, + onLooped = _ref.onLooped; + /** + * The identifier of this code path. + * Rules use it to store additional information of each rule. + * @type {string} + */ + this.id = id; + + /** + * The reason that this code path was started. May be "program", + * "function", "class-field-initializer", or "class-static-block". + * @type {string} + */ + this.origin = origin; + + /** + * The code path of the upper function scope. + * @type {CodePath|null} + */ + this.upper = upper; + + /** + * The code paths of nested function scopes. + * @type {CodePath[]} + */ + this.childCodePaths = []; + + // Initializes internal state. + Object.defineProperty(this, 'internal', { + value: new CodePathState(new IdGenerator(id + "_"), onLooped) + }); + + // Adds this into `childCodePaths` of `upper`. + if (upper) { + upper.childCodePaths.push(this); + } + } + + /** + * Gets the state of a given code path. + * @param {CodePath} codePath A code path to get. + * @returns {CodePathState} The state of the code path. + */ + static getState(codePath) { + return codePath.internal; + } + + /** + * The initial code path segment. + * @type {CodePathSegment} + */ + get initialSegment() { + return this.internal.initialSegment; + } + + /** + * Final code path segments. + * This array is a mix of `returnedSegments` and `thrownSegments`. + * @type {CodePathSegment[]} + */ + get finalSegments() { + return this.internal.finalSegments; + } + + /** + * Final code path segments which is with `return` statements. + * This array contains the last path segment if it's reachable. + * Since the reachable last path returns `undefined`. + * @type {CodePathSegment[]} + */ + get returnedSegments() { + return this.internal.returnedForkContext; + } + + /** + * Final code path segments which is with `throw` statements. + * @type {CodePathSegment[]} + */ + get thrownSegments() { + return this.internal.thrownForkContext; + } + + /** + * Current code path segments. + * @type {CodePathSegment[]} + */ + get currentSegments() { + return this.internal.currentSegments; + } + + /** + * Traverses all segments in this code path. + * + * codePath.traverseSegments(function(segment, controller) { + * // do something. + * }); + * + * This method enumerates segments in order from the head. + * + * The `controller` object has two methods. + * + * - `controller.skip()` - Skip the following segments in this branch. + * - `controller.break()` - Skip all following segments. + * @param {Object} [options] Omittable. + * @param {CodePathSegment} [options.first] The first segment to traverse. + * @param {CodePathSegment} [options.last] The last segment to traverse. + * @param {Function} callback A callback function. + * @returns {void} + */ + traverseSegments(options, callback) { + let resolvedOptions; + let resolvedCallback; + if (typeof options === 'function') { + resolvedCallback = options; + resolvedOptions = {}; + } else { + resolvedOptions = options || {}; + resolvedCallback = callback; + } + const startSegment = resolvedOptions.first || this.internal.initialSegment; + const lastSegment = resolvedOptions.last; + let item = null; + let index = 0; + let end = 0; + let segment = null; + const visited = Object.create(null); + const stack = [[startSegment, 0]]; + let skippedSegment = null; + let broken = false; + const controller = { + skip() { + if (stack.length <= 1) { + broken = true; + } else { + skippedSegment = stack[stack.length - 2][0]; + } + }, + break() { + broken = true; + } + }; + + /** + * Checks a given previous segment has been visited. + * @param {CodePathSegment} prevSegment A previous segment to check. + * @returns {boolean} `true` if the segment has been visited. + */ + function isVisited(prevSegment) { + return visited[prevSegment.id] || segment.isLoopedPrevSegment(prevSegment); + } + while (stack.length > 0) { + item = stack[stack.length - 1]; + segment = item[0]; + index = item[1]; + if (index === 0) { + // Skip if this segment has been visited already. + if (visited[segment.id]) { + stack.pop(); + continue; + } + + // Skip if all previous segments have not been visited. + if (segment !== startSegment && segment.prevSegments.length > 0 && !segment.prevSegments.every(isVisited)) { + stack.pop(); + continue; + } + + // Reset the flag of skipping if all branches have been skipped. + if (skippedSegment && segment.prevSegments.includes(skippedSegment)) { + skippedSegment = null; + } + visited[segment.id] = true; + + // Call the callback when the first time. + if (!skippedSegment) { + resolvedCallback.call(this, segment, controller); + if (segment === lastSegment) { + controller.skip(); + } + if (broken) { + break; + } + } + } + + // Update the stack. + end = segment.nextSegments.length - 1; + if (index < end) { + item[1] += 1; + stack.push([segment.nextSegments[index], 0]); + } else if (index === end) { + item[0] = segment.nextSegments[index]; + item[1] = 0; + } else { + stack.pop(); + } + } + } + } + codePath = CodePath; + return codePath; +} + +var codePathAnalyzer; +var hasRequiredCodePathAnalyzer; +function requireCodePathAnalyzer() { + if (hasRequiredCodePathAnalyzer) return codePathAnalyzer; + hasRequiredCodePathAnalyzer = 1; + + /* eslint-disable react-internal/no-primitive-constructors */ + + //------------------------------------------------------------------------------ + // Requirements + //------------------------------------------------------------------------------ + + // eslint-disable-next-line + const assert = requireAssert(); + // eslint-disable-next-line + const CodePath = requireCodePath(); + // eslint-disable-next-line + const CodePathSegment = requireCodePathSegment(); + // eslint-disable-next-line + const IdGenerator = requireIdGenerator(); + const breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u; + + //------------------------------------------------------------------------------ + // Helpers + //------------------------------------------------------------------------------ + + /** + * Checks whether or not a given node is a `case` node (not `default` node). + * @param {ASTNode} node A `SwitchCase` node to check. + * @returns {boolean} `true` if the node is a `case` node (not `default` node). + */ + function isCaseNode(node) { + return Boolean(node.test); + } + + /** + * Checks if a given node appears as the value of a PropertyDefinition node. + * @param {ASTNode} node THe node to check. + * @returns {boolean} `true` if the node is a PropertyDefinition value, + * false if not. + */ + function isPropertyDefinitionValue(node) { + const parent = node.parent; + return parent && parent.type === 'PropertyDefinition' && parent.value === node; + } + + /** + * Checks whether the given logical operator is taken into account for the code + * path analysis. + * @param {string} operator The operator found in the LogicalExpression node + * @returns {boolean} `true` if the operator is "&&" or "||" or "??" + */ + function isHandledLogicalOperator(operator) { + return operator === '&&' || operator === '||' || operator === '??'; + } + + /** + * Checks whether the given assignment operator is a logical assignment operator. + * Logical assignments are taken into account for the code path analysis + * because of their short-circuiting semantics. + * @param {string} operator The operator found in the AssignmentExpression node + * @returns {boolean} `true` if the operator is "&&=" or "||=" or "??=" + */ + function isLogicalAssignmentOperator(operator) { + return operator === '&&=' || operator === '||=' || operator === '??='; + } + + /** + * Gets the label if the parent node of a given node is a LabeledStatement. + * @param {ASTNode} node A node to get. + * @returns {string|null} The label or `null`. + */ + function getLabel(node) { + if (node.parent.type === 'LabeledStatement') { + return node.parent.label.name; + } + return null; + } + + /** + * Checks whether or not a given logical expression node goes different path + * between the `true` case and the `false` case. + * @param {ASTNode} node A node to check. + * @returns {boolean} `true` if the node is a test of a choice statement. + */ + function isForkingByTrueOrFalse(node) { + const parent = node.parent; + switch (parent.type) { + case 'ConditionalExpression': + case 'IfStatement': + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + return parent.test === node; + case 'LogicalExpression': + return isHandledLogicalOperator(parent.operator); + case 'AssignmentExpression': + return isLogicalAssignmentOperator(parent.operator); + default: + return false; + } + } + + /** + * Gets the boolean value of a given literal node. + * + * This is used to detect infinity loops (e.g. `while (true) {}`). + * Statements preceded by an infinity loop are unreachable if the loop didn't + * have any `break` statement. + * @param {ASTNode} node A node to get. + * @returns {boolean|undefined} a boolean value if the node is a Literal node, + * otherwise `undefined`. + */ + function getBooleanValueIfSimpleConstant(node) { + if (node.type === 'Literal') { + return Boolean(node.value); + } + return void 0; + } + + /** + * Checks that a given identifier node is a reference or not. + * + * This is used to detect the first throwable node in a `try` block. + * @param {ASTNode} node An Identifier node to check. + * @returns {boolean} `true` if the node is a reference. + */ + function isIdentifierReference(node) { + const parent = node.parent; + switch (parent.type) { + case 'LabeledStatement': + case 'BreakStatement': + case 'ContinueStatement': + case 'ArrayPattern': + case 'RestElement': + case 'ImportSpecifier': + case 'ImportDefaultSpecifier': + case 'ImportNamespaceSpecifier': + case 'CatchClause': + return false; + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + case 'ClassDeclaration': + case 'ClassExpression': + case 'VariableDeclarator': + return parent.id !== node; + case 'Property': + case 'PropertyDefinition': + case 'MethodDefinition': + return parent.key !== node || parent.computed || parent.shorthand; + case 'AssignmentPattern': + return parent.key !== node; + default: + return true; + } + } + + /** + * Updates the current segment with the head segment. + * This is similar to local branches and tracking branches of git. + * + * To separate the current and the head is in order to not make useless segments. + * + * In this process, both "onCodePathSegmentStart" and "onCodePathSegmentEnd" + * events are fired. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function forwardCurrentToHead(analyzer, node) { + const codePath = analyzer.codePath; + const state = CodePath.getState(codePath); + const currentSegments = state.currentSegments; + const headSegments = state.headSegments; + const end = Math.max(currentSegments.length, headSegments.length); + let i, currentSegment, headSegment; + + // Fires leaving events. + for (i = 0; i < end; ++i) { + currentSegment = currentSegments[i]; + headSegment = headSegments[i]; + if (currentSegment !== headSegment && currentSegment) { + if (currentSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentEnd', currentSegment, node); + } + } + } + + // Update state. + state.currentSegments = headSegments; + + // Fires entering events. + for (i = 0; i < end; ++i) { + currentSegment = currentSegments[i]; + headSegment = headSegments[i]; + if (currentSegment !== headSegment && headSegment) { + CodePathSegment.markUsed(headSegment); + if (headSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentStart', headSegment, node); + } + } + } + } + + /** + * Updates the current segment with empty. + * This is called at the last of functions or the program. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function leaveFromCurrentSegment(analyzer, node) { + const state = CodePath.getState(analyzer.codePath); + const currentSegments = state.currentSegments; + for (let i = 0; i < currentSegments.length; ++i) { + const currentSegment = currentSegments[i]; + if (currentSegment.reachable) { + analyzer.emitter.emit('onCodePathSegmentEnd', currentSegment, node); + } + } + state.currentSegments = []; + } + + /** + * Updates the code path due to the position of a given node in the parent node + * thereof. + * + * For example, if the node is `parent.consequent`, this creates a fork from the + * current path. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function preprocess(analyzer, node) { + const codePath = analyzer.codePath; + const state = CodePath.getState(codePath); + const parent = node.parent; + switch (parent.type) { + // The `arguments.length == 0` case is in `postprocess` function. + case 'CallExpression': + if (parent.optional === true && parent.arguments.length >= 1 && parent.arguments[0] === node) { + state.makeOptionalRight(); + } + break; + case 'MemberExpression': + if (parent.optional === true && parent.property === node) { + state.makeOptionalRight(); + } + break; + case 'LogicalExpression': + if (parent.right === node && isHandledLogicalOperator(parent.operator)) { + state.makeLogicalRight(); + } + break; + case 'AssignmentExpression': + if (parent.right === node && isLogicalAssignmentOperator(parent.operator)) { + state.makeLogicalRight(); + } + break; + case 'ConditionalExpression': + case 'IfStatement': + /* + * Fork if this node is at `consequent`/`alternate`. + * `popForkContext()` exists at `IfStatement:exit` and + * `ConditionalExpression:exit`. + */ + if (parent.consequent === node) { + state.makeIfConsequent(); + } else if (parent.alternate === node) { + state.makeIfAlternate(); + } + break; + case 'SwitchCase': + if (parent.consequent[0] === node) { + state.makeSwitchCaseBody(false, !parent.test); + } + break; + case 'TryStatement': + if (parent.handler === node) { + state.makeCatchBlock(); + } else if (parent.finalizer === node) { + state.makeFinallyBlock(); + } + break; + case 'WhileStatement': + if (parent.test === node) { + state.makeWhileTest(getBooleanValueIfSimpleConstant(node)); + } else { + assert(parent.body === node); + state.makeWhileBody(); + } + break; + case 'DoWhileStatement': + if (parent.body === node) { + state.makeDoWhileBody(); + } else { + assert(parent.test === node); + state.makeDoWhileTest(getBooleanValueIfSimpleConstant(node)); + } + break; + case 'ForStatement': + if (parent.test === node) { + state.makeForTest(getBooleanValueIfSimpleConstant(node)); + } else if (parent.update === node) { + state.makeForUpdate(); + } else if (parent.body === node) { + state.makeForBody(); + } + break; + case 'ForInStatement': + case 'ForOfStatement': + if (parent.left === node) { + state.makeForInOfLeft(); + } else if (parent.right === node) { + state.makeForInOfRight(); + } else { + assert(parent.body === node); + state.makeForInOfBody(); + } + break; + case 'AssignmentPattern': + /* + * Fork if this node is at `right`. + * `left` is executed always, so it uses the current path. + * `popForkContext()` exists at `AssignmentPattern:exit`. + */ + if (parent.right === node) { + state.pushForkContext(); + state.forkBypassPath(); + state.forkPath(); + } + break; + } + } + + /** + * Updates the code path due to the type of a given node in entering. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function processCodePathToEnter(analyzer, node) { + let codePath = analyzer.codePath; + let state = codePath && CodePath.getState(codePath); + const parent = node.parent; + + /** + * Creates a new code path and trigger the onCodePathStart event + * based on the currently selected node. + * @param {string} origin The reason the code path was started. + * @returns {void} + */ + function startCodePath(origin) { + if (codePath) { + // Emits onCodePathSegmentStart events if updated. + forwardCurrentToHead(analyzer, node); + } + + // Create the code path of this scope. + codePath = analyzer.codePath = new CodePath({ + id: analyzer.idGenerator.next(), + origin, + upper: codePath, + onLooped: analyzer.onLooped + }); + state = CodePath.getState(codePath); + + // Emits onCodePathStart events. + analyzer.emitter.emit('onCodePathStart', codePath, node); + } + + /* + * Special case: The right side of class field initializer is considered + * to be its own function, so we need to start a new code path in this + * case. + */ + if (isPropertyDefinitionValue(node)) { + startCodePath('class-field-initializer'); + + /* + * Intentional fall through because `node` needs to also be + * processed by the code below. For example, if we have: + * + * class Foo { + * a = () => {} + * } + * + * In this case, we also need start a second code path. + */ + } + switch (node.type) { + case 'Program': + startCodePath('program'); + break; + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + startCodePath('function'); + break; + case 'StaticBlock': + startCodePath('class-static-block'); + break; + case 'ChainExpression': + state.pushChainContext(); + break; + case 'CallExpression': + if (node.optional === true) { + state.makeOptionalNode(); + } + break; + case 'MemberExpression': + if (node.optional === true) { + state.makeOptionalNode(); + } + break; + case 'LogicalExpression': + if (isHandledLogicalOperator(node.operator)) { + state.pushChoiceContext(node.operator, isForkingByTrueOrFalse(node)); + } + break; + case 'AssignmentExpression': + if (isLogicalAssignmentOperator(node.operator)) { + state.pushChoiceContext(node.operator.slice(0, -1), + // removes `=` from the end + isForkingByTrueOrFalse(node)); + } + break; + case 'ConditionalExpression': + case 'IfStatement': + state.pushChoiceContext('test', false); + break; + case 'SwitchStatement': + state.pushSwitchContext(node.cases.some(isCaseNode), getLabel(node)); + break; + case 'TryStatement': + state.pushTryContext(Boolean(node.finalizer)); + break; + case 'SwitchCase': + /* + * Fork if this node is after the 2st node in `cases`. + * It's similar to `else` blocks. + * The next `test` node is processed in this path. + */ + if (parent.discriminant !== node && parent.cases[0] !== node) { + state.forkPath(); + } + break; + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + case 'ForInStatement': + case 'ForOfStatement': + state.pushLoopContext(node.type, getLabel(node)); + break; + case 'LabeledStatement': + if (!breakableTypePattern.test(node.body.type)) { + state.pushBreakContext(false, node.label.name); + } + break; + } + + // Emits onCodePathSegmentStart events if updated. + forwardCurrentToHead(analyzer, node); + } + + /** + * Updates the code path due to the type of a given node in leaving. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function processCodePathToExit(analyzer, node) { + const codePath = analyzer.codePath; + const state = CodePath.getState(codePath); + let dontForward = false; + switch (node.type) { + case 'ChainExpression': + state.popChainContext(); + break; + case 'IfStatement': + case 'ConditionalExpression': + state.popChoiceContext(); + break; + case 'LogicalExpression': + if (isHandledLogicalOperator(node.operator)) { + state.popChoiceContext(); + } + break; + case 'AssignmentExpression': + if (isLogicalAssignmentOperator(node.operator)) { + state.popChoiceContext(); + } + break; + case 'SwitchStatement': + state.popSwitchContext(); + break; + case 'SwitchCase': + /* + * This is the same as the process at the 1st `consequent` node in + * `preprocess` function. + * Must do if this `consequent` is empty. + */ + if (node.consequent.length === 0) { + state.makeSwitchCaseBody(true, !node.test); + } + if (state.forkContext.reachable) { + dontForward = true; + } + break; + case 'TryStatement': + state.popTryContext(); + break; + case 'BreakStatement': + forwardCurrentToHead(analyzer, node); + state.makeBreak(node.label && node.label.name); + dontForward = true; + break; + case 'ContinueStatement': + forwardCurrentToHead(analyzer, node); + state.makeContinue(node.label && node.label.name); + dontForward = true; + break; + case 'ReturnStatement': + forwardCurrentToHead(analyzer, node); + state.makeReturn(); + dontForward = true; + break; + case 'ThrowStatement': + forwardCurrentToHead(analyzer, node); + state.makeThrow(); + dontForward = true; + break; + case 'Identifier': + if (isIdentifierReference(node)) { + state.makeFirstThrowablePathInTryBlock(); + dontForward = true; + } + break; + case 'CallExpression': + case 'ImportExpression': + case 'MemberExpression': + case 'NewExpression': + case 'YieldExpression': + state.makeFirstThrowablePathInTryBlock(); + break; + case 'WhileStatement': + case 'DoWhileStatement': + case 'ForStatement': + case 'ForInStatement': + case 'ForOfStatement': + state.popLoopContext(); + break; + case 'AssignmentPattern': + state.popForkContext(); + break; + case 'LabeledStatement': + if (!breakableTypePattern.test(node.body.type)) { + state.popBreakContext(); + } + break; + } + + // Emits onCodePathSegmentStart events if updated. + if (!dontForward) { + forwardCurrentToHead(analyzer, node); + } + } + + /** + * Updates the code path to finalize the current code path. + * @param {CodePathAnalyzer} analyzer The instance. + * @param {ASTNode} node The current AST node. + * @returns {void} + */ + function postprocess(analyzer, node) { + /** + * Ends the code path for the current node. + * @returns {void} + */ + function endCodePath() { + let codePath = analyzer.codePath; + + // Mark the current path as the final node. + CodePath.getState(codePath).makeFinal(); + + // Emits onCodePathSegmentEnd event of the current segments. + leaveFromCurrentSegment(analyzer, node); + + // Emits onCodePathEnd event of this code path. + analyzer.emitter.emit('onCodePathEnd', codePath, node); + codePath = analyzer.codePath = analyzer.codePath.upper; + } + switch (node.type) { + case 'Program': + case 'FunctionDeclaration': + case 'ComponentDeclaration': + case 'HookDeclaration': + case 'FunctionExpression': + case 'ArrowFunctionExpression': + case 'StaticBlock': + { + endCodePath(); + break; + } + + // The `arguments.length >= 1` case is in `preprocess` function. + case 'CallExpression': + if (node.optional === true && node.arguments.length === 0) { + CodePath.getState(analyzer.codePath).makeOptionalRight(); + } + break; + } + + /* + * Special case: The right side of class field initializer is considered + * to be its own function, so we need to end a code path in this + * case. + * + * We need to check after the other checks in order to close the + * code paths in the correct order for code like this: + * + * + * class Foo { + * a = () => {} + * } + * + * In this case, The ArrowFunctionExpression code path is closed first + * and then we need to close the code path for the PropertyDefinition + * value. + */ + if (isPropertyDefinitionValue(node)) { + endCodePath(); + } + } + + //------------------------------------------------------------------------------ + // Public Interface + //------------------------------------------------------------------------------ + + /** + * The class to analyze code paths. + * This class implements the EventGenerator interface. + */ + class CodePathAnalyzer { + /** + * @param {EventGenerator} eventGenerator An event generator to wrap. + */ + constructor(emitters) { + this.emitter = { + emit(event) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + emitters[event]?.(...args); + } + }; + this.codePath = null; + this.idGenerator = new IdGenerator('s'); + this.currentNode = null; + this.onLooped = this.onLooped.bind(this); + } + + /** + * Does the process to enter a given AST node. + * This updates state of analysis and calls `enterNode` of the wrapped. + * @param {ASTNode} node A node which is entering. + * @returns {void} + */ + enterNode(node) { + this.currentNode = node; + + // Updates the code path due to node's position in its parent node. + if (node.parent) { + preprocess(this, node); + } + + /* + * Updates the code path. + * And emits onCodePathStart/onCodePathSegmentStart events. + */ + processCodePathToEnter(this, node); + this.currentNode = null; + } + + /** + * Does the process to leave a given AST node. + * This updates state of analysis and calls `leaveNode` of the wrapped. + * @param {ASTNode} node A node which is leaving. + * @returns {void} + */ + leaveNode(node) { + this.currentNode = node; + + /* + * Updates the code path. + * And emits onCodePathStart/onCodePathSegmentStart events. + */ + processCodePathToExit(this, node); + + // Emits the last onCodePathStart/onCodePathSegmentStart events. + postprocess(this, node); + this.currentNode = null; + } + + /** + * This is called on a code path looped. + * Then this raises a looped event. + * @param {CodePathSegment} fromSegment A segment of prev. + * @param {CodePathSegment} toSegment A segment of next. + * @returns {void} + */ + onLooped(fromSegment, toSegment) { + if (fromSegment.reachable && toSegment.reachable) { + this.emitter.emit('onCodePathSegmentLoop', fromSegment, toSegment, this.currentNode); + } + } + } + codePathAnalyzer = CodePathAnalyzer; + return codePathAnalyzer; +} + +var codePathAnalyzerExports = requireCodePathAnalyzer(); +var CodePathAnalyzer = /*@__PURE__*/getDefaultExportFromCjs(codePathAnalyzerExports); + +function isHookName(s) { + return s === 'use' || /^use[A-Z0-9]/.test(s); +} +function isHook(node) { + if (node.type === 'Identifier') { + return isHookName(node.name); + } + else if (node.type === 'MemberExpression' && + !node.computed && + isHook(node.property)) { + const obj = node.object; + const isPascalCaseNameSpace = /^[A-Z].*/; + return obj.type === 'Identifier' && isPascalCaseNameSpace.test(obj.name); + } + else { + return false; + } +} +function isComponentName(node) { + return node.type === 'Identifier' && /^[A-Z]/.test(node.name); +} +function isReactFunction(node, functionName) { + return (('name' in node && node.name === functionName) || + (node.type === 'MemberExpression' && + 'name' in node.object && + node.object.name === 'React' && + 'name' in node.property && + node.property.name === functionName)); +} +function isForwardRefCallback(node) { + return !!(node.parent && + 'callee' in node.parent && + node.parent.callee && + isReactFunction(node.parent.callee, 'forwardRef')); +} +function isMemoCallback(node) { + return !!(node.parent && + 'callee' in node.parent && + node.parent.callee && + isReactFunction(node.parent.callee, 'memo')); +} +function isInsideComponentOrHook(node) { + while (node) { + const functionName = getFunctionName(node); + if (functionName) { + if (isComponentName(functionName) || isHook(functionName)) { + return true; + } + } + if (isForwardRefCallback(node) || isMemoCallback(node)) { + return true; + } + node = node.parent; + } + return false; +} +function isInsideDoWhileLoop(node) { + while (node) { + if (node.type === 'DoWhileStatement') { + return true; + } + node = node.parent; + } + return false; +} +function isUseEffectEventIdentifier(node) { + { + return node.type === 'Identifier' && node.name === 'useEffectEvent'; + } +} +function isUseIdentifier(node) { + return isReactFunction(node, 'use'); +} +const rule = { + meta: { + type: 'problem', + docs: { + description: 'enforces the Rules of Hooks', + recommended: true, + url: 'https://reactjs.org/docs/hooks-rules.html', + }, + }, + create(context) { + let lastEffect = null; + const codePathReactHooksMapStack = []; + const codePathSegmentStack = []; + const useEffectEventFunctions = new WeakSet(); + function recordAllUseEffectEventFunctions(scope) { + for (const reference of scope.references) { + const parent = reference.identifier.parent; + if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'VariableDeclarator' && + parent.init && + parent.init.type === 'CallExpression' && + parent.init.callee && + isUseEffectEventIdentifier(parent.init.callee)) { + if (reference.resolved === null) { + throw new Error('Unexpected null reference.resolved'); + } + for (const ref of reference.resolved.references) { + if (ref !== reference) { + useEffectEventFunctions.add(ref.identifier); + } + } + } + } + } + const getSourceCode = typeof context.getSourceCode === 'function' + ? () => { + return context.getSourceCode(); + } + : () => { + return context.sourceCode; + }; + const getScope = typeof context.getScope === 'function' + ? () => { + return context.getScope(); + } + : (node) => { + return getSourceCode().getScope(node); + }; + function hasFlowSuppression(node, suppression) { + const sourceCode = getSourceCode(); + const comments = sourceCode.getAllComments(); + const flowSuppressionRegex = new RegExp('\\$FlowFixMe\\[' + suppression + '\\]'); + return comments.some(commentNode => flowSuppressionRegex.test(commentNode.value) && + commentNode.loc != null && + node.loc != null && + commentNode.loc.end.line === node.loc.start.line - 1); + } + const analyzer = new CodePathAnalyzer({ + onCodePathSegmentStart: (segment) => codePathSegmentStack.push(segment), + onCodePathSegmentEnd: () => codePathSegmentStack.pop(), + onCodePathStart: () => codePathReactHooksMapStack.push(new Map()), + onCodePathEnd(codePath, codePathNode) { + const reactHooksMap = codePathReactHooksMapStack.pop(); + if ((reactHooksMap === null || reactHooksMap === void 0 ? void 0 : reactHooksMap.size) === 0) { + return; + } + else if (typeof reactHooksMap === 'undefined') { + throw new Error('Unexpected undefined reactHooksMap'); + } + const cyclic = new Set(); + function countPathsFromStart(segment, pathHistory) { + const { cache } = countPathsFromStart; + let paths = cache.get(segment.id); + const pathList = new Set(pathHistory); + if (pathList.has(segment.id)) { + const pathArray = [...pathList]; + const cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1); + for (const cyclicSegment of cyclicSegments) { + cyclic.add(cyclicSegment); + } + return BigInt('0'); + } + pathList.add(segment.id); + if (paths !== undefined) { + return paths; + } + if (codePath.thrownSegments.includes(segment)) { + paths = BigInt('0'); + } + else if (segment.prevSegments.length === 0) { + paths = BigInt('1'); + } + else { + paths = BigInt('0'); + for (const prevSegment of segment.prevSegments) { + paths += countPathsFromStart(prevSegment, pathList); + } + } + if (segment.reachable && paths === BigInt('0')) { + cache.delete(segment.id); + } + else { + cache.set(segment.id, paths); + } + return paths; + } + function countPathsToEnd(segment, pathHistory) { + const { cache } = countPathsToEnd; + let paths = cache.get(segment.id); + const pathList = new Set(pathHistory); + if (pathList.has(segment.id)) { + const pathArray = Array.from(pathList); + const cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1); + for (const cyclicSegment of cyclicSegments) { + cyclic.add(cyclicSegment); + } + return BigInt('0'); + } + pathList.add(segment.id); + if (paths !== undefined) { + return paths; + } + if (codePath.thrownSegments.includes(segment)) { + paths = BigInt('0'); + } + else if (segment.nextSegments.length === 0) { + paths = BigInt('1'); + } + else { + paths = BigInt('0'); + for (const nextSegment of segment.nextSegments) { + paths += countPathsToEnd(nextSegment, pathList); + } + } + cache.set(segment.id, paths); + return paths; + } + function shortestPathLengthToStart(segment) { + const { cache } = shortestPathLengthToStart; + let length = cache.get(segment.id); + if (length === null) { + return Infinity; + } + if (length !== undefined) { + return length; + } + cache.set(segment.id, null); + if (segment.prevSegments.length === 0) { + length = 1; + } + else { + length = Infinity; + for (const prevSegment of segment.prevSegments) { + const prevLength = shortestPathLengthToStart(prevSegment); + if (prevLength < length) { + length = prevLength; + } + } + length += 1; + } + cache.set(segment.id, length); + return length; + } + countPathsFromStart.cache = new Map(); + countPathsToEnd.cache = new Map(); + shortestPathLengthToStart.cache = new Map(); + const allPathsFromStartToEnd = countPathsToEnd(codePath.initialSegment); + const codePathFunctionName = getFunctionName(codePathNode); + const isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode); + const isDirectlyInsideComponentOrHook = codePathFunctionName + ? isComponentName(codePathFunctionName) || + isHook(codePathFunctionName) + : isForwardRefCallback(codePathNode) || isMemoCallback(codePathNode); + let shortestFinalPathLength = Infinity; + for (const finalSegment of codePath.finalSegments) { + if (!finalSegment.reachable) { + continue; + } + const length = shortestPathLengthToStart(finalSegment); + if (length < shortestFinalPathLength) { + shortestFinalPathLength = length; + } + } + for (const [segment, reactHooks] of reactHooksMap) { + if (!segment.reachable) { + continue; + } + const possiblyHasEarlyReturn = segment.nextSegments.length === 0 + ? shortestFinalPathLength <= shortestPathLengthToStart(segment) + : shortestFinalPathLength < shortestPathLengthToStart(segment); + const pathsFromStartToEnd = countPathsFromStart(segment) * countPathsToEnd(segment); + const cycled = cyclic.has(segment.id); + for (const hook of reactHooks) { + if (hasFlowSuppression(hook, 'react-rule-hook')) { + continue; + } + if ((cycled || isInsideDoWhileLoop(hook)) && + !isUseIdentifier(hook)) { + context.report({ + node: hook, + message: `React Hook "${getSourceCode().getText(hook)}" may be executed ` + + 'more than once. Possibly because it is called in a loop. ' + + 'React Hooks must be called in the exact same order in ' + + 'every component render.', + }); + } + if (isDirectlyInsideComponentOrHook) { + const isAsyncFunction = codePathNode.async; + if (isAsyncFunction) { + context.report({ + node: hook, + message: `React Hook "${getSourceCode().getText(hook)}" cannot be ` + + 'called in an async function.', + }); + } + if (!cycled && + pathsFromStartToEnd !== allPathsFromStartToEnd && + !isUseIdentifier(hook) && + !isInsideDoWhileLoop(hook)) { + const message = `React Hook "${getSourceCode().getText(hook)}" is called ` + + 'conditionally. React Hooks must be called in the exact ' + + 'same order in every component render.' + + (possiblyHasEarlyReturn + ? ' Did you accidentally call a React Hook after an' + + ' early return?' + : ''); + context.report({ node: hook, message }); + } + } + else if (codePathNode.parent != null && + (codePathNode.parent.type === 'MethodDefinition' || + codePathNode.parent.type === 'ClassProperty' || + codePathNode.parent.type === 'PropertyDefinition') && + codePathNode.parent.value === codePathNode) { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'in a class component. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + else if (codePathFunctionName) { + const message = `React Hook "${getSourceCode().getText(hook)}" is called in ` + + `function "${getSourceCode().getText(codePathFunctionName)}" ` + + 'that is neither a React function component nor a custom ' + + 'React Hook function.' + + ' React component names must start with an uppercase letter.' + + ' React Hook names must start with the word "use".'; + context.report({ node: hook, message }); + } + else if (codePathNode.type === 'Program') { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'at the top level. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + else { + if (isSomewhereInsideComponentOrHook && !isUseIdentifier(hook)) { + const message = `React Hook "${getSourceCode().getText(hook)}" cannot be called ` + + 'inside a callback. React Hooks must be called in a ' + + 'React function component or a custom React Hook function.'; + context.report({ node: hook, message }); + } + } + } + } + }, + }); + return { + '*'(node) { + analyzer.enterNode(node); + }, + '*:exit'(node) { + analyzer.leaveNode(node); + }, + CallExpression(node) { + if (isHook(node.callee)) { + const reactHooksMap = last(codePathReactHooksMapStack); + const codePathSegment = last(codePathSegmentStack); + let reactHooks = reactHooksMap.get(codePathSegment); + if (!reactHooks) { + reactHooks = []; + reactHooksMap.set(codePathSegment, reactHooks); + } + reactHooks.push(node.callee); + } + if (node.callee.type === 'Identifier' && + (node.callee.name === 'useEffect' || + isUseEffectEventIdentifier(node.callee)) && + node.arguments.length > 0) { + lastEffect = node; + } + }, + Identifier(node) { + if (lastEffect == null && + useEffectEventFunctions.has(node) && + node.parent.type !== 'CallExpression') { + context.report({ + node, + message: `\`${getSourceCode().getText(node)}\` is a function created with React Hook "useEffectEvent", and can only be called from ` + + 'the same component. They cannot be assigned to variables or passed down.', + }); + } + }, + 'CallExpression:exit'(node) { + if (node === lastEffect) { + lastEffect = null; + } + }, + FunctionDeclaration(node) { + if (isInsideComponentOrHook(node)) { + recordAllUseEffectEventFunctions(getScope(node)); + } + }, + ArrowFunctionExpression(node) { + if (isInsideComponentOrHook(node)) { + recordAllUseEffectEventFunctions(getScope(node)); + } + }, + }; + }, +}; +function getFunctionName(node) { + var _a, _b, _c, _d; + if (node.type === 'ComponentDeclaration' || + node.type === 'HookDeclaration' || + node.type === 'FunctionDeclaration' || + (node.type === 'FunctionExpression' && node.id)) { + return node.id; + } + else if (node.type === 'FunctionExpression' || + node.type === 'ArrowFunctionExpression') { + if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'VariableDeclarator' && + node.parent.init === node) { + return node.parent.id; + } + else if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === 'AssignmentExpression' && + node.parent.right === node && + node.parent.operator === '=') { + return node.parent.left; + } + else if (((_c = node.parent) === null || _c === void 0 ? void 0 : _c.type) === 'Property' && + node.parent.value === node && + !node.parent.computed) { + return node.parent.key; + } + else if (((_d = node.parent) === null || _d === void 0 ? void 0 : _d.type) === 'AssignmentPattern' && + node.parent.right === node && + !node.parent.computed) { + return node.parent.left; + } + else { + return undefined; + } + } + else { + return undefined; + } +} +function last(array) { + return array[array.length - 1]; +} + +const rules = { + 'exhaustive-deps': rule$2, + 'react-compiler': rule$1, + 'rules-of-hooks': rule, +}; +const configRules = { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', +}; +const recommendedConfig = { + name: 'react-hooks/recommended', + plugins: { + get 'react-hooks'() { + return plugin; + }, + }, + rules: configRules, +}; +const plugin = { + meta: { name: 'eslint-plugin-react-hooks' }, + rules, + configs: { + 'recommended-legacy': { + plugins: ['react-hooks'], + rules: configRules, + }, + recommended: recommendedConfig, + 'recommended-latest': recommendedConfig, + }, +}; +const configs = plugin.configs; +const meta = plugin.meta; + +exports.configs = configs; +exports.meta = meta; +exports.rules = rules; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.d.ts b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.d.ts new file mode 100644 index 0000000000..17bdf95c51 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.d.ts @@ -0,0 +1,8 @@ +/** + * 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. + */ + +export * from './cjs/eslint-plugin-react-hooks'; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.js new file mode 100644 index 0000000000..b8d16f4dca --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/index.js @@ -0,0 +1,17 @@ +/** + * 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. + * @generated SignedSource<<829a703f74325e3ef8d64eef69524fd5>> + */ + +'use strict'; + +// TODO: this doesn't make sense for an ESLint rule. +// We need to fix our build process to not create bundles for "raw" packages like this. +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/eslint-plugin-react-hooks.production.js'); +} else { + module.exports = require('./cjs/eslint-plugin-react-hooks.development.js'); +} diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/package.json b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/package.json new file mode 100644 index 0000000000..8a99731af1 --- /dev/null +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/eslint-plugin-react-hooks/eslint-plugin-react-hooks/package.json @@ -0,0 +1,69 @@ +{ + "name": "eslint-plugin-react-hooks", + "description": "ESLint rules for React Hooks", + "version": "0.0.0-experimental-9de0304a-20250502", + "repository": { + "type": "git", + "url": "https://github.com/facebook/react.git", + "directory": "packages/eslint-plugin-react-hooks" + }, + "files": [ + "LICENSE", + "README.md", + "cjs", + "index.js", + "index.d.ts" + ], + "keywords": [ + "eslint", + "eslint-plugin", + "eslintplugin", + "react" + ], + "scripts": { + "build:compiler": "cd ../../compiler && yarn workspace babel-plugin-react-compiler build", + "test": "yarn build:compiler && jest", + "typecheck": "tsc --noEmit" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/facebook/react/issues" + }, + "main": "./index.js", + "types": "./index.d.ts", + "engines": { + "node": ">=18" + }, + "homepage": "https://react.dev/", + "peerDependencies": { + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0" + }, + "dependencies": { + "@babel/core": "^7.24.4", + "@babel/parser": "^7.24.4", + "@babel/plugin-transform-private-methods": "^7.24.4", + "hermes-parser": "^0.25.1", + "zod": "^3.22.4", + "zod-validation-error": "^3.0.3" + }, + "devDependencies": { + "@babel/eslint-parser": "^7.11.4", + "@babel/preset-typescript": "^7.26.0", + "@babel/types": "^7.19.0", + "@tsconfig/strictest": "^2.0.5", + "@typescript-eslint/parser-v2": "npm:@typescript-eslint/parser@^2.26.0", + "@typescript-eslint/parser-v3": "npm:@typescript-eslint/parser@^3.10.0", + "@typescript-eslint/parser-v4": "npm:@typescript-eslint/parser@^4.1.0", + "@typescript-eslint/parser-v5": "npm:@typescript-eslint/parser@^5.62.0", + "@types/eslint": "^8.56.12", + "@types/estree": "^1.0.6", + "@types/estree-jsx": "^1.0.5", + "@types/node": "^20.2.5", + "babel-eslint": "^10.0.3", + "eslint-v7": "npm:eslint@^7.7.0", + "eslint-v8": "npm:eslint@^8.57.1", + "eslint-v9": "npm:eslint@^9.0.0", + "jest": "^29.5.0", + "typescript": "^5.4.3" + } +} \ No newline at end of file diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js index 38f88d9cd0..d7813e6746 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<1eb08f6a09bf7c59a67b2c313eee5a7f>> + * @generated SignedSource<<94418d6210d98f9818b820d855be067b>> */ "use strict"; @@ -404,5 +404,5 @@ __DEV__ && exports.useFormStatus = function () { return resolveDispatcher().useHostTransitionStatus(); }; - exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; + exports.version = "19.2.0-native-fb-9de0304a-20250502"; })(); diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js index 16912130bf..df97e92455 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<> */ "use strict"; @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) { exports.useFormStatus = function () { return ReactSharedInternals.H.useHostTransitionStatus(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js index 16912130bf..df97e92455 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<> */ "use strict"; @@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) { exports.useFormStatus = function () { return ReactSharedInternals.H.useHostTransitionStatus(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js index 1fca4db33c..11d8863bf2 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<7c1e0cf917b85f5c89bb7c829d2fefae>> + * @generated SignedSource<<731574b70709fc6bdfd9890e3a84358d>> */ /* @@ -26650,11 +26650,11 @@ __DEV__ && }; (function () { var isomorphicReactPackageVersion = React.version; - if ("19.2.0-native-fb-0ed6ceb9-20250501" !== isomorphicReactPackageVersion) + if ("19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion) throw Error( 'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' + (isomorphicReactPackageVersion + - "\n - react-dom: 19.2.0-native-fb-0ed6ceb9-20250501\nLearn more: https://react.dev/warnings/version-mismatch") + "\n - react-dom: 19.2.0-native-fb-9de0304a-20250502\nLearn more: https://react.dev/warnings/version-mismatch") ); })(); ("function" === typeof Map && @@ -26691,10 +26691,10 @@ __DEV__ && !(function () { var internals = { bundleType: 1, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; internals.overrideHookState = overrideHookState; internals.overrideHookStateDeletePath = overrideHookStateDeletePath; @@ -26838,5 +26838,5 @@ __DEV__ && listenToAllSupportedEvents(container); return new ReactDOMHydrationRoot(initialChildren); }; - exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; + exports.version = "19.2.0-native-fb-9de0304a-20250502"; })(); diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js index 5f9f0d469e..5622665a77 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<4d808718671119eeb92d5fca2e8ffff2>> + * @generated SignedSource<<271c338ffe2768b505ffedff1fd57c13>> */ /* @@ -16748,14 +16748,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) { }; var isomorphicReactPackageVersion$jscomp$inline_1904 = React.version; if ( - "19.2.0-native-fb-0ed6ceb9-20250501" !== + "19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion$jscomp$inline_1904 ) throw Error( formatProdErrorMessage( 527, isomorphicReactPackageVersion$jscomp$inline_1904, - "19.2.0-native-fb-0ed6ceb9-20250501" + "19.2.0-native-fb-9de0304a-20250502" ) ); ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { @@ -16777,10 +16777,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { }; var internals$jscomp$inline_2388 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_2389 = __REACT_DEVTOOLS_GLOBAL_HOOK__; @@ -16884,4 +16884,4 @@ exports.hydrateRoot = function (container, initialChildren, options) { listenToAllSupportedEvents(container); return new ReactDOMHydrationRoot(initialChildren); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js index a99dfa6880..085ff10f56 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<89f9e826ae16098a3381f903164292b7>> + * @generated SignedSource<<3379d7be92d89e37652992f051429130>> */ /* @@ -17457,14 +17457,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) { }; var isomorphicReactPackageVersion$jscomp$inline_2007 = React.version; if ( - "19.2.0-native-fb-0ed6ceb9-20250501" !== + "19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion$jscomp$inline_2007 ) throw Error( formatProdErrorMessage( 527, isomorphicReactPackageVersion$jscomp$inline_2007, - "19.2.0-native-fb-0ed6ceb9-20250501" + "19.2.0-native-fb-9de0304a-20250502" ) ); ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { @@ -17486,10 +17486,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { }; var internals$jscomp$inline_2014 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501", + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502", getLaneLabelMap: function () { for ( var map = new Map(), lane = 1, index$305 = 0; @@ -17608,4 +17608,4 @@ exports.hydrateRoot = function (container, initialChildren, options) { listenToAllSupportedEvents(container); return new ReactDOMHydrationRoot(initialChildren); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js index 6873b17ee1..159be97111 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<<7617947fd85698c498bf3434a36d6e40>> */ /* @@ -26711,11 +26711,11 @@ __DEV__ && }; (function () { var isomorphicReactPackageVersion = React.version; - if ("19.2.0-native-fb-0ed6ceb9-20250501" !== isomorphicReactPackageVersion) + if ("19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion) throw Error( 'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' + (isomorphicReactPackageVersion + - "\n - react-dom: 19.2.0-native-fb-0ed6ceb9-20250501\nLearn more: https://react.dev/warnings/version-mismatch") + "\n - react-dom: 19.2.0-native-fb-9de0304a-20250502\nLearn more: https://react.dev/warnings/version-mismatch") ); })(); ("function" === typeof Map && @@ -26752,10 +26752,10 @@ __DEV__ && !(function () { var internals = { bundleType: 1, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; internals.overrideHookState = overrideHookState; internals.overrideHookStateDeletePath = overrideHookStateDeletePath; @@ -27215,7 +27215,7 @@ __DEV__ && exports.useFormStatus = function () { return resolveDispatcher().useHostTransitionStatus(); }; - exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; + exports.version = "19.2.0-native-fb-9de0304a-20250502"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js index d6433ea9d5..9f837f2de5 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<> */ /* @@ -16759,14 +16759,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) { }; var isomorphicReactPackageVersion$jscomp$inline_1905 = React.version; if ( - "19.2.0-native-fb-0ed6ceb9-20250501" !== + "19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion$jscomp$inline_1905 ) throw Error( formatProdErrorMessage( 527, isomorphicReactPackageVersion$jscomp$inline_1905, - "19.2.0-native-fb-0ed6ceb9-20250501" + "19.2.0-native-fb-9de0304a-20250502" ) ); ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { @@ -16788,10 +16788,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { }; var internals$jscomp$inline_2391 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_2392 = __REACT_DEVTOOLS_GLOBAL_HOOK__; @@ -17049,4 +17049,4 @@ exports.useFormState = function (action, initialState, permalink) { exports.useFormStatus = function () { return ReactSharedInternals.H.useHostTransitionStatus(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js index 65b5c5e57a..50ce10ccd5 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<> */ /* @@ -17472,14 +17472,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) { }; var isomorphicReactPackageVersion$jscomp$inline_2008 = React.version; if ( - "19.2.0-native-fb-0ed6ceb9-20250501" !== + "19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion$jscomp$inline_2008 ) throw Error( formatProdErrorMessage( 527, isomorphicReactPackageVersion$jscomp$inline_2008, - "19.2.0-native-fb-0ed6ceb9-20250501" + "19.2.0-native-fb-9de0304a-20250502" ) ); ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { @@ -17501,10 +17501,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) { }; var internals$jscomp$inline_2015 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-dom", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501", + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502", getLaneLabelMap: function () { for ( var map = new Map(), lane = 1, index$305 = 0; @@ -17777,7 +17777,7 @@ exports.useFormState = function (action, initialState, permalink) { exports.useFormStatus = function () { return ReactSharedInternals.H.useHostTransitionStatus(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js index 44f62dc574..742bdca0e4 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<01e19d9368d624d31c81161ec91aa4c5>> + * @generated SignedSource<<3180708964486dfe2f683b09dd529c25>> */ "use strict"; @@ -15630,10 +15630,10 @@ __DEV__ && (function () { var internals = { bundleType: 1, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-test-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; internals.overrideHookState = overrideHookState; internals.overrideHookStateDeletePath = overrideHookStateDeletePath; @@ -15778,5 +15778,5 @@ __DEV__ && flushSyncWorkAcrossRoots_impl(0, !0)); } }; - exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; + exports.version = "19.2.0-native-fb-9de0304a-20250502"; })(); diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-prod.js index a505339c83..72c97e1d45 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<170c832af1ef56139d84b9583fc9e6fd>> + * @generated SignedSource<> */ "use strict"; @@ -9885,10 +9885,10 @@ function wrapFiber(fiber) { } var internals$jscomp$inline_1439 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-test-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) { var hook$jscomp$inline_1440 = __REACT_DEVTOOLS_GLOBAL_HOOK__; @@ -10024,4 +10024,4 @@ exports.unstable_batchedUpdates = function (fn, a) { flushSyncWorkAcrossRoots_impl(0, !0)); } }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-profiling.js index 1596a39c4e..3a4b11a14b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<1ddec52ec0745a726c45d3233f99fb2a>> + * @generated SignedSource<<04a618789b7da79ae41ed09e0cb4cfb6>> */ "use strict"; @@ -10502,10 +10502,10 @@ function wrapFiber(fiber) { } var internals$jscomp$inline_1247 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-test-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501", + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502", getLaneLabelMap: function () { for ( var map = new Map(), lane = 1, index$155 = 0; @@ -10656,4 +10656,4 @@ exports.unstable_batchedUpdates = function (fn, a) { flushSyncWorkAcrossRoots_impl(0, !0)); } }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-dev.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-dev.js index 0a6ccb39ef..4d6f8fba3e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-dev.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-dev.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<6b8da4e84e37ef171caed06c55d3dd2d>> + * @generated SignedSource<> */ "use strict"; @@ -1412,7 +1412,7 @@ __DEV__ && exports.useTransition = function () { return resolveDispatcher().useTransition(); }; - exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; + exports.version = "19.2.0-native-fb-9de0304a-20250502"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-prod.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-prod.js index 66b562a6b6..d0abf9578f 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-prod.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-prod.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<09120e326736c5eca767081f61aaa504>> + * @generated SignedSource<> */ "use strict"; @@ -587,4 +587,4 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactSharedInternals.H.useTransition(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; diff --git a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-profiling.js b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-profiling.js index 524a905a61..7038844a82 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-profiling.js +++ b/compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-profiling.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<2407780bbfe7ed8fabddae3ec42d4978>> + * @generated SignedSource<<26b89a0b74047672074df141d79c79ec>> */ "use strict"; @@ -591,7 +591,7 @@ exports.useSyncExternalStore = function ( exports.useTransition = function () { return ReactSharedInternals.H.useTransition(); }; -exports.version = "19.2.0-native-fb-0ed6ceb9-20250501"; +exports.version = "19.2.0-native-fb-9de0304a-20250502"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION index 701056f1d6..cea3bbada4 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION @@ -1 +1 @@ -0ed6ceb9f6c19f28c504cf46193cef40166a61f6 +9de0304ad72bc3f8a77d2d84efa530b8051d1c15 diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js index 5a729ae430..f5f0272d67 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<2d9ccae50774dce0a433ee4503ae9b83>> + * @generated SignedSource<<96afa3cc7d41677e277a5828272f203a>> */ "use strict"; @@ -17469,10 +17469,10 @@ __DEV__ && (function () { var internals = { bundleType: 1, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals.rendererConfig = extraDevToolsConfig); diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js index ccbe8465a7..054e2ca04b 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<> + * @generated SignedSource<<0f7f496b9c54aca42108799399bb466e>> */ "use strict"; @@ -11210,10 +11210,10 @@ batchedUpdatesImpl = function (fn, a) { var roots = new Map(), internals$jscomp$inline_1251 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals$jscomp$inline_1251.rendererConfig = extraDevToolsConfig); diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js index 22b62256fb..55da37174e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<7959d567f6347b3a7ce45d838b3526d3>> + * @generated SignedSource<<4982b4d22c36fcef01af3f4e4070a9dd>> */ "use strict"; @@ -11911,10 +11911,10 @@ batchedUpdatesImpl = function (fn, a) { var roots = new Map(), internals$jscomp$inline_1352 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals$jscomp$inline_1352.rendererConfig = extraDevToolsConfig); diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js index 6b118fe3e0..2fc0326cb1 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<67faeb8c2a8f26549d4b4e302b2069e2>> + * @generated SignedSource<> */ "use strict"; @@ -17622,11 +17622,11 @@ __DEV__ && shouldSuspendImpl = newShouldSuspendImpl; }; var isomorphicReactPackageVersion = React.version; - if ("19.2.0-native-fb-0ed6ceb9-20250501" !== isomorphicReactPackageVersion) + if ("19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion) throw Error( 'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' + (isomorphicReactPackageVersion + - "\n - react-native-renderer: 19.2.0-native-fb-0ed6ceb9-20250501\nLearn more: https://react.dev/warnings/version-mismatch") + "\n - react-native-renderer: 19.2.0-native-fb-9de0304a-20250502\nLearn more: https://react.dev/warnings/version-mismatch") ); if ( "function" !== @@ -17652,10 +17652,10 @@ __DEV__ && (function () { var internals = { bundleType: 1, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals.rendererConfig = extraDevToolsConfig); diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js index 02b6021446..bc1243aee8 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-prod.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<592cef100153b912cdab60cb2e078efc>> + * @generated SignedSource<<9fa913670d20217656ae3c695faf63ae>> */ "use strict"; @@ -11243,11 +11243,11 @@ function updateContainer(element, container, parentComponent, callback) { return lane; } var isomorphicReactPackageVersion = React.version; -if ("19.2.0-native-fb-0ed6ceb9-20250501" !== isomorphicReactPackageVersion) +if ("19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion) throw Error( 'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' + (isomorphicReactPackageVersion + - "\n - react-native-renderer: 19.2.0-native-fb-0ed6ceb9-20250501\nLearn more: https://react.dev/warnings/version-mismatch") + "\n - react-native-renderer: 19.2.0-native-fb-9de0304a-20250502\nLearn more: https://react.dev/warnings/version-mismatch") ); if ( "function" !== @@ -11296,10 +11296,10 @@ batchedUpdatesImpl = function (fn, a) { var roots = new Map(), internals$jscomp$inline_1299 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals$jscomp$inline_1299.rendererConfig = extraDevToolsConfig); diff --git a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js index 158096876e..7e46a8042e 100644 --- a/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js +++ b/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.fb.js @@ -7,7 +7,7 @@ * @noflow * @nolint * @preventMunge - * @generated SignedSource<<4c4885ef41508d8e05a68f6a2a9d1d0f>> + * @generated SignedSource<> */ "use strict"; @@ -11942,11 +11942,11 @@ function updateContainer(element, container, parentComponent, callback) { return lane; } var isomorphicReactPackageVersion = React.version; -if ("19.2.0-native-fb-0ed6ceb9-20250501" !== isomorphicReactPackageVersion) +if ("19.2.0-native-fb-9de0304a-20250502" !== isomorphicReactPackageVersion) throw Error( 'Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:\n - react: ' + (isomorphicReactPackageVersion + - "\n - react-native-renderer: 19.2.0-native-fb-0ed6ceb9-20250501\nLearn more: https://react.dev/warnings/version-mismatch") + "\n - react-native-renderer: 19.2.0-native-fb-9de0304a-20250502\nLearn more: https://react.dev/warnings/version-mismatch") ); if ( "function" !== @@ -11995,10 +11995,10 @@ batchedUpdatesImpl = function (fn, a) { var roots = new Map(), internals$jscomp$inline_1400 = { bundleType: 0, - version: "19.2.0-native-fb-0ed6ceb9-20250501", + version: "19.2.0-native-fb-9de0304a-20250502", rendererPackageName: "react-native-renderer", currentDispatcherRef: ReactSharedInternals, - reconcilerVersion: "19.2.0-native-fb-0ed6ceb9-20250501" + reconcilerVersion: "19.2.0-native-fb-9de0304a-20250502" }; null !== extraDevToolsConfig && (internals$jscomp$inline_1400.rendererConfig = extraDevToolsConfig);