UNPKG

@mastra/schema-compat

Version:

Tool schema compatibility layer for Mastra.ai

1 lines • 444 kB
{"version":3,"file":"json-schema-pcL1TeZs.cjs","names":["#schema","#options","#validate","#toJsonSchema","#getAjvValidator","#ajvPathToStandardPath","#ajvValidateCache","Ajv2020","Ajv","#ajvInstance"],"sources":["../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/codegen/code.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/codegen/scope.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/codegen/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/util.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/names.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/errors.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/boolSchema.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/rules.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/applicability.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/dataType.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/defaults.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/code.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/keyword.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/subschema.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fast-deep-equal/3.1.3/57fbe5fd6f7d3bd61519466ad102884cc9e5511fabd9777317b6582805433878/node_modules/fast-deep-equal/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/resolve.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/validate/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/runtime/validation_error.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/ref_error.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/compile/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/data.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fast-uri/3.1.5/fd960d70645639d9369f70462ee9b95ab368f1696f14cfc9efbb9e9a4bd25318/node_modules/fast-uri/lib/utils.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fast-uri/3.1.5/fd960d70645639d9369f70462ee9b95ab368f1696f14cfc9efbb9e9a4bd25318/node_modules/fast-uri/lib/schemes.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/fast-uri/3.1.5/fd960d70645639d9369f70462ee9b95ab368f1696f14cfc9efbb9e9a4bd25318/node_modules/fast-uri/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/runtime/uri.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/core.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/core/id.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/core/ref.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/core/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/limitNumber.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/multipleOf.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/runtime/ucs2length.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/limitLength.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/pattern.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/limitProperties.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/required.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/limitItems.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/runtime/equal.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/const.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/enum.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/items.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/items2020.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/contains.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/dependencies.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/properties.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/not.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/anyOf.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/oneOf.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/allOf.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/if.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/thenElse.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/format/format.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/format/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/metadata.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/draft7.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/discriminator/types.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/discriminator/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-draft-07.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/ajv.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/dynamic/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/validation/limitContains.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/next.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/unevaluated/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/vocabularies/draft2020.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/schema.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.json","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/refs/json-schema-2020-12/index.js","../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/ajv/8.20.0/45a7731a7f226afbb54bce5941cf72055c748f37aa24c1b293e6625f57e4ce6e/node_modules/ajv/dist/2020.js","../src/standard-schema/adapters/json-schema.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.regexpCode = exports.getEsmExportName = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nclass _CodeOrName {\n}\nexports._CodeOrName = _CodeOrName;\nexports.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;\nclass Name extends _CodeOrName {\n constructor(s) {\n super();\n if (!exports.IDENTIFIER.test(s))\n throw new Error(\"CodeGen: name must be a valid identifier\");\n this.str = s;\n }\n toString() {\n return this.str;\n }\n emptyStr() {\n return false;\n }\n get names() {\n return { [this.str]: 1 };\n }\n}\nexports.Name = Name;\nclass _Code extends _CodeOrName {\n constructor(code) {\n super();\n this._items = typeof code === \"string\" ? [code] : code;\n }\n toString() {\n return this.str;\n }\n emptyStr() {\n if (this._items.length > 1)\n return false;\n const item = this._items[0];\n return item === \"\" || item === '\"\"';\n }\n get str() {\n var _a;\n return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, \"\")));\n }\n get names() {\n var _a;\n return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {\n if (c instanceof Name)\n names[c.str] = (names[c.str] || 0) + 1;\n return names;\n }, {})));\n }\n}\nexports._Code = _Code;\nexports.nil = new _Code(\"\");\nfunction _(strs, ...args) {\n const code = [strs[0]];\n let i = 0;\n while (i < args.length) {\n addCodeArg(code, args[i]);\n code.push(strs[++i]);\n }\n return new _Code(code);\n}\nexports._ = _;\nconst plus = new _Code(\"+\");\nfunction str(strs, ...args) {\n const expr = [safeStringify(strs[0])];\n let i = 0;\n while (i < args.length) {\n expr.push(plus);\n addCodeArg(expr, args[i]);\n expr.push(plus, safeStringify(strs[++i]));\n }\n optimize(expr);\n return new _Code(expr);\n}\nexports.str = str;\nfunction addCodeArg(code, arg) {\n if (arg instanceof _Code)\n code.push(...arg._items);\n else if (arg instanceof Name)\n code.push(arg);\n else\n code.push(interpolate(arg));\n}\nexports.addCodeArg = addCodeArg;\nfunction optimize(expr) {\n let i = 1;\n while (i < expr.length - 1) {\n if (expr[i] === plus) {\n const res = mergeExprItems(expr[i - 1], expr[i + 1]);\n if (res !== undefined) {\n expr.splice(i - 1, 3, res);\n continue;\n }\n expr[i++] = \"+\";\n }\n i++;\n }\n}\nfunction mergeExprItems(a, b) {\n if (b === '\"\"')\n return a;\n if (a === '\"\"')\n return b;\n if (typeof a == \"string\") {\n if (b instanceof Name || a[a.length - 1] !== '\"')\n return;\n if (typeof b != \"string\")\n return `${a.slice(0, -1)}${b}\"`;\n if (b[0] === '\"')\n return a.slice(0, -1) + b.slice(1);\n return;\n }\n if (typeof b == \"string\" && b[0] === '\"' && !(a instanceof Name))\n return `\"${a}${b.slice(1)}`;\n return;\n}\nfunction strConcat(c1, c2) {\n return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;\n}\nexports.strConcat = strConcat;\n// TODO do not allow arrays here\nfunction interpolate(x) {\n return typeof x == \"number\" || typeof x == \"boolean\" || x === null\n ? x\n : safeStringify(Array.isArray(x) ? x.join(\",\") : x);\n}\nfunction stringify(x) {\n return new _Code(safeStringify(x));\n}\nexports.stringify = stringify;\nfunction safeStringify(x) {\n return JSON.stringify(x)\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\nexports.safeStringify = safeStringify;\nfunction getProperty(key) {\n return typeof key == \"string\" && exports.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;\n}\nexports.getProperty = getProperty;\n//Does best effort to format the name properly\nfunction getEsmExportName(key) {\n if (typeof key == \"string\" && exports.IDENTIFIER.test(key)) {\n return new _Code(`${key}`);\n }\n throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);\n}\nexports.getEsmExportName = getEsmExportName;\nfunction regexpCode(rx) {\n return new _Code(rx.toString());\n}\nexports.regexpCode = regexpCode;\n//# sourceMappingURL=code.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = exports.UsedValueState = void 0;\nconst code_1 = require(\"./code\");\nclass ValueError extends Error {\n constructor(name) {\n super(`CodeGen: \"code\" for ${name} not defined`);\n this.value = name.value;\n }\n}\nvar UsedValueState;\n(function (UsedValueState) {\n UsedValueState[UsedValueState[\"Started\"] = 0] = \"Started\";\n UsedValueState[UsedValueState[\"Completed\"] = 1] = \"Completed\";\n})(UsedValueState || (exports.UsedValueState = UsedValueState = {}));\nexports.varKinds = {\n const: new code_1.Name(\"const\"),\n let: new code_1.Name(\"let\"),\n var: new code_1.Name(\"var\"),\n};\nclass Scope {\n constructor({ prefixes, parent } = {}) {\n this._names = {};\n this._prefixes = prefixes;\n this._parent = parent;\n }\n toName(nameOrPrefix) {\n return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);\n }\n name(prefix) {\n return new code_1.Name(this._newName(prefix));\n }\n _newName(prefix) {\n const ng = this._names[prefix] || this._nameGroup(prefix);\n return `${prefix}${ng.index++}`;\n }\n _nameGroup(prefix) {\n var _a, _b;\n if (((_b = (_a = this._parent) === null || _a === void 0 ? void 0 : _a._prefixes) === null || _b === void 0 ? void 0 : _b.has(prefix)) || (this._prefixes && !this._prefixes.has(prefix))) {\n throw new Error(`CodeGen: prefix \"${prefix}\" is not allowed in this scope`);\n }\n return (this._names[prefix] = { prefix, index: 0 });\n }\n}\nexports.Scope = Scope;\nclass ValueScopeName extends code_1.Name {\n constructor(prefix, nameStr) {\n super(nameStr);\n this.prefix = prefix;\n }\n setValue(value, { property, itemIndex }) {\n this.value = value;\n this.scopePath = (0, code_1._) `.${new code_1.Name(property)}[${itemIndex}]`;\n }\n}\nexports.ValueScopeName = ValueScopeName;\nconst line = (0, code_1._) `\\n`;\nclass ValueScope extends Scope {\n constructor(opts) {\n super(opts);\n this._values = {};\n this._scope = opts.scope;\n this.opts = { ...opts, _n: opts.lines ? line : code_1.nil };\n }\n get() {\n return this._scope;\n }\n name(prefix) {\n return new ValueScopeName(prefix, this._newName(prefix));\n }\n value(nameOrPrefix, value) {\n var _a;\n if (value.ref === undefined)\n throw new Error(\"CodeGen: ref must be passed in value\");\n const name = this.toName(nameOrPrefix);\n const { prefix } = name;\n const valueKey = (_a = value.key) !== null && _a !== void 0 ? _a : value.ref;\n let vs = this._values[prefix];\n if (vs) {\n const _name = vs.get(valueKey);\n if (_name)\n return _name;\n }\n else {\n vs = this._values[prefix] = new Map();\n }\n vs.set(valueKey, name);\n const s = this._scope[prefix] || (this._scope[prefix] = []);\n const itemIndex = s.length;\n s[itemIndex] = value.ref;\n name.setValue(value, { property: prefix, itemIndex });\n return name;\n }\n getValue(prefix, keyOrRef) {\n const vs = this._values[prefix];\n if (!vs)\n return;\n return vs.get(keyOrRef);\n }\n scopeRefs(scopeName, values = this._values) {\n return this._reduceValues(values, (name) => {\n if (name.scopePath === undefined)\n throw new Error(`CodeGen: name \"${name}\" has no value`);\n return (0, code_1._) `${scopeName}${name.scopePath}`;\n });\n }\n scopeCode(values = this._values, usedValues, getCode) {\n return this._reduceValues(values, (name) => {\n if (name.value === undefined)\n throw new Error(`CodeGen: name \"${name}\" has no value`);\n return name.value.code;\n }, usedValues, getCode);\n }\n _reduceValues(values, valueCode, usedValues = {}, getCode) {\n let code = code_1.nil;\n for (const prefix in values) {\n const vs = values[prefix];\n if (!vs)\n continue;\n const nameSet = (usedValues[prefix] = usedValues[prefix] || new Map());\n vs.forEach((name) => {\n if (nameSet.has(name))\n return;\n nameSet.set(name, UsedValueState.Started);\n let c = valueCode(name);\n if (c) {\n const def = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;\n code = (0, code_1._) `${code}${def} ${name} = ${c};${this.opts._n}`;\n }\n else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {\n code = (0, code_1._) `${code}${c}${this.opts._n}`;\n }\n else {\n throw new ValueError(name);\n }\n nameSet.set(name, UsedValueState.Completed);\n });\n }\n return code;\n }\n}\nexports.ValueScope = ValueScope;\n//# sourceMappingURL=scope.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScopeName = exports.ValueScope = exports.Scope = exports.Name = exports.regexpCode = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;\nconst code_1 = require(\"./code\");\nconst scope_1 = require(\"./scope\");\nvar code_2 = require(\"./code\");\nObject.defineProperty(exports, \"_\", { enumerable: true, get: function () { return code_2._; } });\nObject.defineProperty(exports, \"str\", { enumerable: true, get: function () { return code_2.str; } });\nObject.defineProperty(exports, \"strConcat\", { enumerable: true, get: function () { return code_2.strConcat; } });\nObject.defineProperty(exports, \"nil\", { enumerable: true, get: function () { return code_2.nil; } });\nObject.defineProperty(exports, \"getProperty\", { enumerable: true, get: function () { return code_2.getProperty; } });\nObject.defineProperty(exports, \"stringify\", { enumerable: true, get: function () { return code_2.stringify; } });\nObject.defineProperty(exports, \"regexpCode\", { enumerable: true, get: function () { return code_2.regexpCode; } });\nObject.defineProperty(exports, \"Name\", { enumerable: true, get: function () { return code_2.Name; } });\nvar scope_2 = require(\"./scope\");\nObject.defineProperty(exports, \"Scope\", { enumerable: true, get: function () { return scope_2.Scope; } });\nObject.defineProperty(exports, \"ValueScope\", { enumerable: true, get: function () { return scope_2.ValueScope; } });\nObject.defineProperty(exports, \"ValueScopeName\", { enumerable: true, get: function () { return scope_2.ValueScopeName; } });\nObject.defineProperty(exports, \"varKinds\", { enumerable: true, get: function () { return scope_2.varKinds; } });\nexports.operators = {\n GT: new code_1._Code(\">\"),\n GTE: new code_1._Code(\">=\"),\n LT: new code_1._Code(\"<\"),\n LTE: new code_1._Code(\"<=\"),\n EQ: new code_1._Code(\"===\"),\n NEQ: new code_1._Code(\"!==\"),\n NOT: new code_1._Code(\"!\"),\n OR: new code_1._Code(\"||\"),\n AND: new code_1._Code(\"&&\"),\n ADD: new code_1._Code(\"+\"),\n};\nclass Node {\n optimizeNodes() {\n return this;\n }\n optimizeNames(_names, _constants) {\n return this;\n }\n}\nclass Def extends Node {\n constructor(varKind, name, rhs) {\n super();\n this.varKind = varKind;\n this.name = name;\n this.rhs = rhs;\n }\n render({ es5, _n }) {\n const varKind = es5 ? scope_1.varKinds.var : this.varKind;\n const rhs = this.rhs === undefined ? \"\" : ` = ${this.rhs}`;\n return `${varKind} ${this.name}${rhs};` + _n;\n }\n optimizeNames(names, constants) {\n if (!names[this.name.str])\n return;\n if (this.rhs)\n this.rhs = optimizeExpr(this.rhs, names, constants);\n return this;\n }\n get names() {\n return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};\n }\n}\nclass Assign extends Node {\n constructor(lhs, rhs, sideEffects) {\n super();\n this.lhs = lhs;\n this.rhs = rhs;\n this.sideEffects = sideEffects;\n }\n render({ _n }) {\n return `${this.lhs} = ${this.rhs};` + _n;\n }\n optimizeNames(names, constants) {\n if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)\n return;\n this.rhs = optimizeExpr(this.rhs, names, constants);\n return this;\n }\n get names() {\n const names = this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names };\n return addExprNames(names, this.rhs);\n }\n}\nclass AssignOp extends Assign {\n constructor(lhs, op, rhs, sideEffects) {\n super(lhs, rhs, sideEffects);\n this.op = op;\n }\n render({ _n }) {\n return `${this.lhs} ${this.op}= ${this.rhs};` + _n;\n }\n}\nclass Label extends Node {\n constructor(label) {\n super();\n this.label = label;\n this.names = {};\n }\n render({ _n }) {\n return `${this.label}:` + _n;\n }\n}\nclass Break extends Node {\n constructor(label) {\n super();\n this.label = label;\n this.names = {};\n }\n render({ _n }) {\n const label = this.label ? ` ${this.label}` : \"\";\n return `break${label};` + _n;\n }\n}\nclass Throw extends Node {\n constructor(error) {\n super();\n this.error = error;\n }\n render({ _n }) {\n return `throw ${this.error};` + _n;\n }\n get names() {\n return this.error.names;\n }\n}\nclass AnyCode extends Node {\n constructor(code) {\n super();\n this.code = code;\n }\n render({ _n }) {\n return `${this.code};` + _n;\n }\n optimizeNodes() {\n return `${this.code}` ? this : undefined;\n }\n optimizeNames(names, constants) {\n this.code = optimizeExpr(this.code, names, constants);\n return this;\n }\n get names() {\n return this.code instanceof code_1._CodeOrName ? this.code.names : {};\n }\n}\nclass ParentNode extends Node {\n constructor(nodes = []) {\n super();\n this.nodes = nodes;\n }\n render(opts) {\n return this.nodes.reduce((code, n) => code + n.render(opts), \"\");\n }\n optimizeNodes() {\n const { nodes } = this;\n let i = nodes.length;\n while (i--) {\n const n = nodes[i].optimizeNodes();\n if (Array.isArray(n))\n nodes.splice(i, 1, ...n);\n else if (n)\n nodes[i] = n;\n else\n nodes.splice(i, 1);\n }\n return nodes.length > 0 ? this : undefined;\n }\n optimizeNames(names, constants) {\n const { nodes } = this;\n let i = nodes.length;\n while (i--) {\n // iterating backwards improves 1-pass optimization\n const n = nodes[i];\n if (n.optimizeNames(names, constants))\n continue;\n subtractNames(names, n.names);\n nodes.splice(i, 1);\n }\n return nodes.length > 0 ? this : undefined;\n }\n get names() {\n return this.nodes.reduce((names, n) => addNames(names, n.names), {});\n }\n}\nclass BlockNode extends ParentNode {\n render(opts) {\n return \"{\" + opts._n + super.render(opts) + \"}\" + opts._n;\n }\n}\nclass Root extends ParentNode {\n}\nclass Else extends BlockNode {\n}\nElse.kind = \"else\";\nclass If extends BlockNode {\n constructor(condition, nodes) {\n super(nodes);\n this.condition = condition;\n }\n render(opts) {\n let code = `if(${this.condition})` + super.render(opts);\n if (this.else)\n code += \"else \" + this.else.render(opts);\n return code;\n }\n optimizeNodes() {\n super.optimizeNodes();\n const cond = this.condition;\n if (cond === true)\n return this.nodes; // else is ignored here\n let e = this.else;\n if (e) {\n const ns = e.optimizeNodes();\n e = this.else = Array.isArray(ns) ? new Else(ns) : ns;\n }\n if (e) {\n if (cond === false)\n return e instanceof If ? e : e.nodes;\n if (this.nodes.length)\n return this;\n return new If(not(cond), e instanceof If ? [e] : e.nodes);\n }\n if (cond === false || !this.nodes.length)\n return undefined;\n return this;\n }\n optimizeNames(names, constants) {\n var _a;\n this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);\n if (!(super.optimizeNames(names, constants) || this.else))\n return;\n this.condition = optimizeExpr(this.condition, names, constants);\n return this;\n }\n get names() {\n const names = super.names;\n addExprNames(names, this.condition);\n if (this.else)\n addNames(names, this.else.names);\n return names;\n }\n}\nIf.kind = \"if\";\nclass For extends BlockNode {\n}\nFor.kind = \"for\";\nclass ForLoop extends For {\n constructor(iteration) {\n super();\n this.iteration = iteration;\n }\n render(opts) {\n return `for(${this.iteration})` + super.render(opts);\n }\n optimizeNames(names, constants) {\n if (!super.optimizeNames(names, constants))\n return;\n this.iteration = optimizeExpr(this.iteration, names, constants);\n return this;\n }\n get names() {\n return addNames(super.names, this.iteration.names);\n }\n}\nclass ForRange extends For {\n constructor(varKind, name, from, to) {\n super();\n this.varKind = varKind;\n this.name = name;\n this.from = from;\n this.to = to;\n }\n render(opts) {\n const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;\n const { name, from, to } = this;\n return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);\n }\n get names() {\n const names = addExprNames(super.names, this.from);\n return addExprNames(names, this.to);\n }\n}\nclass ForIter extends For {\n constructor(loop, varKind, name, iterable) {\n super();\n this.loop = loop;\n this.varKind = varKind;\n this.name = name;\n this.iterable = iterable;\n }\n render(opts) {\n return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);\n }\n optimizeNames(names, constants) {\n if (!super.optimizeNames(names, constants))\n return;\n this.iterable = optimizeExpr(this.iterable, names, constants);\n return this;\n }\n get names() {\n return addNames(super.names, this.iterable.names);\n }\n}\nclass Func extends BlockNode {\n constructor(name, args, async) {\n super();\n this.name = name;\n this.args = args;\n this.async = async;\n }\n render(opts) {\n const _async = this.async ? \"async \" : \"\";\n return `${_async}function ${this.name}(${this.args})` + super.render(opts);\n }\n}\nFunc.kind = \"func\";\nclass Return extends ParentNode {\n render(opts) {\n return \"return \" + super.render(opts);\n }\n}\nReturn.kind = \"return\";\nclass Try extends BlockNode {\n render(opts) {\n let code = \"try\" + super.render(opts);\n if (this.catch)\n code += this.catch.render(opts);\n if (this.finally)\n code += this.finally.render(opts);\n return code;\n }\n optimizeNodes() {\n var _a, _b;\n super.optimizeNodes();\n (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();\n (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();\n return this;\n }\n optimizeNames(names, constants) {\n var _a, _b;\n super.optimizeNames(names, constants);\n (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);\n (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);\n return this;\n }\n get names() {\n const names = super.names;\n if (this.catch)\n addNames(names, this.catch.names);\n if (this.finally)\n addNames(names, this.finally.names);\n return names;\n }\n}\nclass Catch extends BlockNode {\n constructor(error) {\n super();\n this.error = error;\n }\n render(opts) {\n return `catch(${this.error})` + super.render(opts);\n }\n}\nCatch.kind = \"catch\";\nclass Finally extends BlockNode {\n render(opts) {\n return \"finally\" + super.render(opts);\n }\n}\nFinally.kind = \"finally\";\nclass CodeGen {\n constructor(extScope, opts = {}) {\n this._values = {};\n this._blockStarts = [];\n this._constants = {};\n this.opts = { ...opts, _n: opts.lines ? \"\\n\" : \"\" };\n this._extScope = extScope;\n this._scope = new scope_1.Scope({ parent: extScope });\n this._nodes = [new Root()];\n }\n toString() {\n return this._root.render(this.opts);\n }\n // returns unique name in the internal scope\n name(prefix) {\n return this._scope.name(prefix);\n }\n // reserves unique name in the external scope\n scopeName(prefix) {\n return this._extScope.name(prefix);\n }\n // reserves unique name in the external scope and assigns value to it\n scopeValue(prefixOrName, value) {\n const name = this._extScope.value(prefixOrName, value);\n const vs = this._values[name.prefix] || (this._values[name.prefix] = new Set());\n vs.add(name);\n return name;\n }\n getScopeValue(prefix, keyOrRef) {\n return this._extScope.getValue(prefix, keyOrRef);\n }\n // return code that assigns values in the external scope to the names that are used internally\n // (same names that were returned by gen.scopeName or gen.scopeValue)\n scopeRefs(scopeName) {\n return this._extScope.scopeRefs(scopeName, this._values);\n }\n scopeCode() {\n return this._extScope.scopeCode(this._values);\n }\n _def(varKind, nameOrPrefix, rhs, constant) {\n const name = this._scope.toName(nameOrPrefix);\n if (rhs !== undefined && constant)\n this._constants[name.str] = rhs;\n this._leafNode(new Def(varKind, name, rhs));\n return name;\n }\n // `const` declaration (`var` in es5 mode)\n const(nameOrPrefix, rhs, _constant) {\n return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);\n }\n // `let` declaration with optional assignment (`var` in es5 mode)\n let(nameOrPrefix, rhs, _constant) {\n return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);\n }\n // `var` declaration with optional assignment\n var(nameOrPrefix, rhs, _constant) {\n return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);\n }\n // assignment code\n assign(lhs, rhs, sideEffects) {\n return this._leafNode(new Assign(lhs, rhs, sideEffects));\n }\n // `+=` code\n add(lhs, rhs) {\n return this._leafNode(new AssignOp(lhs, exports.operators.ADD, rhs));\n }\n // appends passed SafeExpr to code or executes Block\n code(c) {\n if (typeof c == \"function\")\n c();\n else if (c !== code_1.nil)\n this._leafNode(new AnyCode(c));\n return this;\n }\n // returns code for object literal for the passed argument list of key-value pairs\n object(...keyValues) {\n const code = [\"{\"];\n for (const [key, value] of keyValues) {\n if (code.length > 1)\n code.push(\",\");\n code.push(key);\n if (key !== value || this.opts.es5) {\n code.push(\":\");\n (0, code_1.addCodeArg)(code, value);\n }\n }\n code.push(\"}\");\n return new code_1._Code(code);\n }\n // `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)\n if(condition, thenBody, elseBody) {\n this._blockNode(new If(condition));\n if (thenBody && elseBody) {\n this.code(thenBody).else().code(elseBody).endIf();\n }\n else if (thenBody) {\n this.code(thenBody).endIf();\n }\n else if (elseBody) {\n throw new Error('CodeGen: \"else\" body without \"then\" body');\n }\n return this;\n }\n // `else if` clause - invalid without `if` or after `else` clauses\n elseIf(condition) {\n return this._elseNode(new If(condition));\n }\n // `else` clause - only valid after `if` or `else if` clauses\n else() {\n return this._elseNode(new Else());\n }\n // end `if` statement (needed if gen.if was used only with condition)\n endIf() {\n return this._endBlockNode(If, Else);\n }\n _for(node, forBody) {\n this._blockNode(node);\n if (forBody)\n this.code(forBody).endFor();\n return this;\n }\n // a generic `for` clause (or statement if `forBody` is passed)\n for(iteration, forBody) {\n return this._for(new ForLoop(iteration), forBody);\n }\n // `for` statement for a range of values\n forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {\n const name = this._scope.toName(nameOrPrefix);\n return this._for(new ForRange(varKind, name, from, to), () => forBody(name));\n }\n // `for-of` statement (in es5 mode replace with a normal for loop)\n forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {\n const name = this._scope.toName(nameOrPrefix);\n if (this.opts.es5) {\n const arr = iterable instanceof code_1.Name ? iterable : this.var(\"_arr\", iterable);\n return this.forRange(\"_i\", 0, (0, code_1._) `${arr}.length`, (i) => {\n this.var(name, (0, code_1._) `${arr}[${i}]`);\n forBody(name);\n });\n }\n return this._for(new ForIter(\"of\", varKind, name, iterable), () => forBody(name));\n }\n // `for-in` statement.\n // With option `ownProperties` replaced with a `for-of` loop for object keys\n forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {\n if (this.opts.ownProperties) {\n return this.forOf(nameOrPrefix, (0, code_1._) `Object.keys(${obj})`, forBody);\n }\n const name = this._scope.toName(nameOrPrefix);\n return this._for(new ForIter(\"in\", varKind, name, obj), () => forBody(name));\n }\n // end `for` loop\n endFor() {\n return this._endBlockNode(For);\n }\n // `label` statement\n label(label) {\n return this._leafNode(new Label(label));\n }\n // `break` statement\n break(label) {\n return this._leafNode(new Break(label));\n }\n // `return` statement\n return(value) {\n const node = new Return();\n this._blockNode(node);\n this.code(value);\n if (node.nodes.length !== 1)\n throw new Error('CodeGen: \"return\" should have one node');\n return this._endBlockNode(Return);\n }\n // `try` statement\n try(tryBody, catchCode, finallyCode) {\n if (!catchCode && !finallyCode)\n throw new Error('CodeGen: \"try\" without \"catch\" and \"finally\"');\n const node = new Try();\n this._blockNode(node);\n this.code(tryBody);\n if (catchCode) {\n const error = this.name(\"e\");\n this._currNode = node.catch = new Catch(error);\n catchCode(error);\n }\n if (finallyCode) {\n this._currNode = node.finally = new Finally();\n this.code(finallyCode);\n }\n return this._endBlockNode(Catch, Finally);\n }\n // `throw` statement\n throw(error) {\n return this._leafNode(new Throw(error));\n }\n // start self-balancing block\n block(body, nodeCount) {\n this._blockStarts.push(this._nodes.length);\n if (body)\n this.code(body).endBlock(nodeCount);\n return this;\n }\n // end the current self-balancing block\n endBlock(nodeCount) {\n const len = this._blockStarts.pop();\n if (len === undefined)\n throw new Error(\"CodeGen: not in self-balancing block\");\n const toClose = this._nodes.length - len;\n if (toClose < 0 || (nodeCount !== undefined && toClose !== nodeCount)) {\n throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);\n }\n this._nodes.length = len;\n return this;\n }\n // `function` heading (or definition if funcBody is passed)\n func(name, args = code_1.nil, async, funcBody) {\n this._blockNode(new Func(name, args, async));\n if (funcBody)\n this.code(funcBody).endFunc();\n return this;\n }\n // end function definition\n endFunc() {\n return this._endBlockNode(Func);\n }\n optimize(n = 1) {\n while (n-- > 0) {\n this._root.optimizeNodes();\n this._root.optimizeNames(this._root.names, this._constants);\n }\n }\n _leafNode(node) {\n this._currNode.nodes.push(node);\n return this;\n }\n _blockNode(node) {\n this._currNode.nodes.push(node);\n this._nodes.push(node);\n }\n _endBlockNode(N1, N2) {\n const n = this._currNode;\n if (n instanceof N1 || (N2 && n instanceof N2)) {\n this._nodes.pop();\n return this;\n }\n throw new Error(`CodeGen: not in block \"${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}\"`);\n }\n _elseNode(node) {\n const n = this._currNode;\n if (!(n instanceof If)) {\n throw new Error('CodeGen: \"else\" without \"if\"');\n }\n this._currNode = n.else = node;\n return this;\n }\n get _root() {\n return this._nodes[0];\n }\n get _currNode() {\n const ns = this._nodes;\n return ns[ns.length - 1];\n }