@applitools/mcp 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -13655,1016 +13655,1037 @@ var codegen = {};
13655
13655
 
13656
13656
  var code$1 = {};
13657
13657
 
13658
- (function (exports$1) {
13659
- Object.defineProperty(exports$1, "__esModule", { value: true });
13660
- exports$1.regexpCode = exports$1.getEsmExportName = exports$1.getProperty = exports$1.safeStringify = exports$1.stringify = exports$1.strConcat = exports$1.addCodeArg = exports$1.str = exports$1._ = exports$1.nil = exports$1._Code = exports$1.Name = exports$1.IDENTIFIER = exports$1._CodeOrName = void 0;
13661
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
13662
- class _CodeOrName {
13663
- }
13664
- exports$1._CodeOrName = _CodeOrName;
13665
- exports$1.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
13666
- class Name extends _CodeOrName {
13667
- constructor(s) {
13668
- super();
13669
- if (!exports$1.IDENTIFIER.test(s))
13670
- throw new Error("CodeGen: name must be a valid identifier");
13671
- this.str = s;
13672
- }
13673
- toString() {
13674
- return this.str;
13675
- }
13676
- emptyStr() {
13677
- return false;
13678
- }
13679
- get names() {
13680
- return { [this.str]: 1 };
13681
- }
13682
- }
13683
- exports$1.Name = Name;
13684
- class _Code extends _CodeOrName {
13685
- constructor(code) {
13686
- super();
13687
- this._items = typeof code === "string" ? [code] : code;
13688
- }
13689
- toString() {
13690
- return this.str;
13691
- }
13692
- emptyStr() {
13693
- if (this._items.length > 1)
13694
- return false;
13695
- const item = this._items[0];
13696
- return item === "" || item === '""';
13697
- }
13698
- get str() {
13699
- var _a;
13700
- return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
13701
- }
13702
- get names() {
13703
- var _a;
13704
- return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
13705
- if (c instanceof Name)
13706
- names[c.str] = (names[c.str] || 0) + 1;
13707
- return names;
13708
- }, {})));
13709
- }
13710
- }
13711
- exports$1._Code = _Code;
13712
- exports$1.nil = new _Code("");
13713
- function _(strs, ...args) {
13714
- const code = [strs[0]];
13715
- let i = 0;
13716
- while (i < args.length) {
13717
- addCodeArg(code, args[i]);
13718
- code.push(strs[++i]);
13719
- }
13720
- return new _Code(code);
13721
- }
13722
- exports$1._ = _;
13723
- const plus = new _Code("+");
13724
- function str(strs, ...args) {
13725
- const expr = [safeStringify(strs[0])];
13726
- let i = 0;
13727
- while (i < args.length) {
13728
- expr.push(plus);
13729
- addCodeArg(expr, args[i]);
13730
- expr.push(plus, safeStringify(strs[++i]));
13731
- }
13732
- optimize(expr);
13733
- return new _Code(expr);
13734
- }
13735
- exports$1.str = str;
13736
- function addCodeArg(code, arg) {
13737
- if (arg instanceof _Code)
13738
- code.push(...arg._items);
13739
- else if (arg instanceof Name)
13740
- code.push(arg);
13741
- else
13742
- code.push(interpolate(arg));
13743
- }
13744
- exports$1.addCodeArg = addCodeArg;
13745
- function optimize(expr) {
13746
- let i = 1;
13747
- while (i < expr.length - 1) {
13748
- if (expr[i] === plus) {
13749
- const res = mergeExprItems(expr[i - 1], expr[i + 1]);
13750
- if (res !== undefined) {
13751
- expr.splice(i - 1, 3, res);
13752
- continue;
13753
- }
13754
- expr[i++] = "+";
13755
- }
13756
- i++;
13757
- }
13758
- }
13759
- function mergeExprItems(a, b) {
13760
- if (b === '""')
13761
- return a;
13762
- if (a === '""')
13763
- return b;
13764
- if (typeof a == "string") {
13765
- if (b instanceof Name || a[a.length - 1] !== '"')
13766
- return;
13767
- if (typeof b != "string")
13768
- return `${a.slice(0, -1)}${b}"`;
13769
- if (b[0] === '"')
13770
- return a.slice(0, -1) + b.slice(1);
13771
- return;
13772
- }
13773
- if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
13774
- return `"${a}${b.slice(1)}`;
13775
- return;
13776
- }
13777
- function strConcat(c1, c2) {
13778
- return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;
13779
- }
13780
- exports$1.strConcat = strConcat;
13781
- // TODO do not allow arrays here
13782
- function interpolate(x) {
13783
- return typeof x == "number" || typeof x == "boolean" || x === null
13784
- ? x
13785
- : safeStringify(Array.isArray(x) ? x.join(",") : x);
13786
- }
13787
- function stringify(x) {
13788
- return new _Code(safeStringify(x));
13789
- }
13790
- exports$1.stringify = stringify;
13791
- function safeStringify(x) {
13792
- return JSON.stringify(x)
13793
- .replace(/\u2028/g, "\\u2028")
13794
- .replace(/\u2029/g, "\\u2029");
13795
- }
13796
- exports$1.safeStringify = safeStringify;
13797
- function getProperty(key) {
13798
- return typeof key == "string" && exports$1.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;
13799
- }
13800
- exports$1.getProperty = getProperty;
13801
- //Does best effort to format the name properly
13802
- function getEsmExportName(key) {
13803
- if (typeof key == "string" && exports$1.IDENTIFIER.test(key)) {
13804
- return new _Code(`${key}`);
13805
- }
13806
- throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);
13807
- }
13808
- exports$1.getEsmExportName = getEsmExportName;
13809
- function regexpCode(rx) {
13810
- return new _Code(rx.toString());
13811
- }
13812
- exports$1.regexpCode = regexpCode;
13813
-
13814
- } (code$1));
13658
+ var hasRequiredCode$1;
13659
+
13660
+ function requireCode$1 () {
13661
+ if (hasRequiredCode$1) return code$1;
13662
+ hasRequiredCode$1 = 1;
13663
+ (function (exports$1) {
13664
+ Object.defineProperty(exports$1, "__esModule", { value: true });
13665
+ exports$1.regexpCode = exports$1.getEsmExportName = exports$1.getProperty = exports$1.safeStringify = exports$1.stringify = exports$1.strConcat = exports$1.addCodeArg = exports$1.str = exports$1._ = exports$1.nil = exports$1._Code = exports$1.Name = exports$1.IDENTIFIER = exports$1._CodeOrName = void 0;
13666
+ // eslint-disable-next-line @typescript-eslint/no-extraneous-class
13667
+ class _CodeOrName {
13668
+ }
13669
+ exports$1._CodeOrName = _CodeOrName;
13670
+ exports$1.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
13671
+ class Name extends _CodeOrName {
13672
+ constructor(s) {
13673
+ super();
13674
+ if (!exports$1.IDENTIFIER.test(s))
13675
+ throw new Error("CodeGen: name must be a valid identifier");
13676
+ this.str = s;
13677
+ }
13678
+ toString() {
13679
+ return this.str;
13680
+ }
13681
+ emptyStr() {
13682
+ return false;
13683
+ }
13684
+ get names() {
13685
+ return { [this.str]: 1 };
13686
+ }
13687
+ }
13688
+ exports$1.Name = Name;
13689
+ class _Code extends _CodeOrName {
13690
+ constructor(code) {
13691
+ super();
13692
+ this._items = typeof code === "string" ? [code] : code;
13693
+ }
13694
+ toString() {
13695
+ return this.str;
13696
+ }
13697
+ emptyStr() {
13698
+ if (this._items.length > 1)
13699
+ return false;
13700
+ const item = this._items[0];
13701
+ return item === "" || item === '""';
13702
+ }
13703
+ get str() {
13704
+ var _a;
13705
+ return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
13706
+ }
13707
+ get names() {
13708
+ var _a;
13709
+ return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
13710
+ if (c instanceof Name)
13711
+ names[c.str] = (names[c.str] || 0) + 1;
13712
+ return names;
13713
+ }, {})));
13714
+ }
13715
+ }
13716
+ exports$1._Code = _Code;
13717
+ exports$1.nil = new _Code("");
13718
+ function _(strs, ...args) {
13719
+ const code = [strs[0]];
13720
+ let i = 0;
13721
+ while (i < args.length) {
13722
+ addCodeArg(code, args[i]);
13723
+ code.push(strs[++i]);
13724
+ }
13725
+ return new _Code(code);
13726
+ }
13727
+ exports$1._ = _;
13728
+ const plus = new _Code("+");
13729
+ function str(strs, ...args) {
13730
+ const expr = [safeStringify(strs[0])];
13731
+ let i = 0;
13732
+ while (i < args.length) {
13733
+ expr.push(plus);
13734
+ addCodeArg(expr, args[i]);
13735
+ expr.push(plus, safeStringify(strs[++i]));
13736
+ }
13737
+ optimize(expr);
13738
+ return new _Code(expr);
13739
+ }
13740
+ exports$1.str = str;
13741
+ function addCodeArg(code, arg) {
13742
+ if (arg instanceof _Code)
13743
+ code.push(...arg._items);
13744
+ else if (arg instanceof Name)
13745
+ code.push(arg);
13746
+ else
13747
+ code.push(interpolate(arg));
13748
+ }
13749
+ exports$1.addCodeArg = addCodeArg;
13750
+ function optimize(expr) {
13751
+ let i = 1;
13752
+ while (i < expr.length - 1) {
13753
+ if (expr[i] === plus) {
13754
+ const res = mergeExprItems(expr[i - 1], expr[i + 1]);
13755
+ if (res !== undefined) {
13756
+ expr.splice(i - 1, 3, res);
13757
+ continue;
13758
+ }
13759
+ expr[i++] = "+";
13760
+ }
13761
+ i++;
13762
+ }
13763
+ }
13764
+ function mergeExprItems(a, b) {
13765
+ if (b === '""')
13766
+ return a;
13767
+ if (a === '""')
13768
+ return b;
13769
+ if (typeof a == "string") {
13770
+ if (b instanceof Name || a[a.length - 1] !== '"')
13771
+ return;
13772
+ if (typeof b != "string")
13773
+ return `${a.slice(0, -1)}${b}"`;
13774
+ if (b[0] === '"')
13775
+ return a.slice(0, -1) + b.slice(1);
13776
+ return;
13777
+ }
13778
+ if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
13779
+ return `"${a}${b.slice(1)}`;
13780
+ return;
13781
+ }
13782
+ function strConcat(c1, c2) {
13783
+ return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;
13784
+ }
13785
+ exports$1.strConcat = strConcat;
13786
+ // TODO do not allow arrays here
13787
+ function interpolate(x) {
13788
+ return typeof x == "number" || typeof x == "boolean" || x === null
13789
+ ? x
13790
+ : safeStringify(Array.isArray(x) ? x.join(",") : x);
13791
+ }
13792
+ function stringify(x) {
13793
+ return new _Code(safeStringify(x));
13794
+ }
13795
+ exports$1.stringify = stringify;
13796
+ function safeStringify(x) {
13797
+ return JSON.stringify(x)
13798
+ .replace(/\u2028/g, "\\u2028")
13799
+ .replace(/\u2029/g, "\\u2029");
13800
+ }
13801
+ exports$1.safeStringify = safeStringify;
13802
+ function getProperty(key) {
13803
+ return typeof key == "string" && exports$1.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;
13804
+ }
13805
+ exports$1.getProperty = getProperty;
13806
+ //Does best effort to format the name properly
13807
+ function getEsmExportName(key) {
13808
+ if (typeof key == "string" && exports$1.IDENTIFIER.test(key)) {
13809
+ return new _Code(`${key}`);
13810
+ }
13811
+ throw new Error(`CodeGen: invalid export name: ${key}, use explicit $id name mapping`);
13812
+ }
13813
+ exports$1.getEsmExportName = getEsmExportName;
13814
+ function regexpCode(rx) {
13815
+ return new _Code(rx.toString());
13816
+ }
13817
+ exports$1.regexpCode = regexpCode;
13818
+
13819
+ } (code$1));
13820
+ return code$1;
13821
+ }
13815
13822
 
13816
13823
  var scope = {};
13817
13824
 
13818
- (function (exports$1) {
13819
- Object.defineProperty(exports$1, "__esModule", { value: true });
13820
- exports$1.ValueScope = exports$1.ValueScopeName = exports$1.Scope = exports$1.varKinds = exports$1.UsedValueState = void 0;
13821
- const code_1 = code$1;
13822
- class ValueError extends Error {
13823
- constructor(name) {
13824
- super(`CodeGen: "code" for ${name} not defined`);
13825
- this.value = name.value;
13826
- }
13827
- }
13828
- var UsedValueState;
13829
- (function (UsedValueState) {
13830
- UsedValueState[UsedValueState["Started"] = 0] = "Started";
13831
- UsedValueState[UsedValueState["Completed"] = 1] = "Completed";
13832
- })(UsedValueState || (exports$1.UsedValueState = UsedValueState = {}));
13833
- exports$1.varKinds = {
13834
- const: new code_1.Name("const"),
13835
- let: new code_1.Name("let"),
13836
- var: new code_1.Name("var"),
13837
- };
13838
- class Scope {
13839
- constructor({ prefixes, parent } = {}) {
13840
- this._names = {};
13841
- this._prefixes = prefixes;
13842
- this._parent = parent;
13843
- }
13844
- toName(nameOrPrefix) {
13845
- return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);
13846
- }
13847
- name(prefix) {
13848
- return new code_1.Name(this._newName(prefix));
13849
- }
13850
- _newName(prefix) {
13851
- const ng = this._names[prefix] || this._nameGroup(prefix);
13852
- return `${prefix}${ng.index++}`;
13853
- }
13854
- _nameGroup(prefix) {
13855
- var _a, _b;
13856
- 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))) {
13857
- throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`);
13858
- }
13859
- return (this._names[prefix] = { prefix, index: 0 });
13860
- }
13861
- }
13862
- exports$1.Scope = Scope;
13863
- class ValueScopeName extends code_1.Name {
13864
- constructor(prefix, nameStr) {
13865
- super(nameStr);
13866
- this.prefix = prefix;
13867
- }
13868
- setValue(value, { property, itemIndex }) {
13869
- this.value = value;
13870
- this.scopePath = (0, code_1._) `.${new code_1.Name(property)}[${itemIndex}]`;
13871
- }
13872
- }
13873
- exports$1.ValueScopeName = ValueScopeName;
13874
- const line = (0, code_1._) `\n`;
13875
- class ValueScope extends Scope {
13876
- constructor(opts) {
13877
- super(opts);
13878
- this._values = {};
13879
- this._scope = opts.scope;
13880
- this.opts = { ...opts, _n: opts.lines ? line : code_1.nil };
13881
- }
13882
- get() {
13883
- return this._scope;
13884
- }
13885
- name(prefix) {
13886
- return new ValueScopeName(prefix, this._newName(prefix));
13887
- }
13888
- value(nameOrPrefix, value) {
13889
- var _a;
13890
- if (value.ref === undefined)
13891
- throw new Error("CodeGen: ref must be passed in value");
13892
- const name = this.toName(nameOrPrefix);
13893
- const { prefix } = name;
13894
- const valueKey = (_a = value.key) !== null && _a !== void 0 ? _a : value.ref;
13895
- let vs = this._values[prefix];
13896
- if (vs) {
13897
- const _name = vs.get(valueKey);
13898
- if (_name)
13899
- return _name;
13900
- }
13901
- else {
13902
- vs = this._values[prefix] = new Map();
13903
- }
13904
- vs.set(valueKey, name);
13905
- const s = this._scope[prefix] || (this._scope[prefix] = []);
13906
- const itemIndex = s.length;
13907
- s[itemIndex] = value.ref;
13908
- name.setValue(value, { property: prefix, itemIndex });
13909
- return name;
13910
- }
13911
- getValue(prefix, keyOrRef) {
13912
- const vs = this._values[prefix];
13913
- if (!vs)
13914
- return;
13915
- return vs.get(keyOrRef);
13916
- }
13917
- scopeRefs(scopeName, values = this._values) {
13918
- return this._reduceValues(values, (name) => {
13919
- if (name.scopePath === undefined)
13920
- throw new Error(`CodeGen: name "${name}" has no value`);
13921
- return (0, code_1._) `${scopeName}${name.scopePath}`;
13922
- });
13923
- }
13924
- scopeCode(values = this._values, usedValues, getCode) {
13925
- return this._reduceValues(values, (name) => {
13926
- if (name.value === undefined)
13927
- throw new Error(`CodeGen: name "${name}" has no value`);
13928
- return name.value.code;
13929
- }, usedValues, getCode);
13930
- }
13931
- _reduceValues(values, valueCode, usedValues = {}, getCode) {
13932
- let code = code_1.nil;
13933
- for (const prefix in values) {
13934
- const vs = values[prefix];
13935
- if (!vs)
13936
- continue;
13937
- const nameSet = (usedValues[prefix] = usedValues[prefix] || new Map());
13938
- vs.forEach((name) => {
13939
- if (nameSet.has(name))
13940
- return;
13941
- nameSet.set(name, UsedValueState.Started);
13942
- let c = valueCode(name);
13943
- if (c) {
13944
- const def = this.opts.es5 ? exports$1.varKinds.var : exports$1.varKinds.const;
13945
- code = (0, code_1._) `${code}${def} ${name} = ${c};${this.opts._n}`;
13946
- }
13947
- else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {
13948
- code = (0, code_1._) `${code}${c}${this.opts._n}`;
13949
- }
13950
- else {
13951
- throw new ValueError(name);
13952
- }
13953
- nameSet.set(name, UsedValueState.Completed);
13954
- });
13955
- }
13956
- return code;
13957
- }
13958
- }
13959
- exports$1.ValueScope = ValueScope;
13960
-
13961
- } (scope));
13825
+ var hasRequiredScope;
13962
13826
 
13963
- (function (exports$1) {
13964
- Object.defineProperty(exports$1, "__esModule", { value: true });
13965
- exports$1.or = exports$1.and = exports$1.not = exports$1.CodeGen = exports$1.operators = exports$1.varKinds = exports$1.ValueScopeName = exports$1.ValueScope = exports$1.Scope = exports$1.Name = exports$1.regexpCode = exports$1.stringify = exports$1.getProperty = exports$1.nil = exports$1.strConcat = exports$1.str = exports$1._ = void 0;
13966
- const code_1 = code$1;
13967
- const scope_1 = scope;
13968
- var code_2 = code$1;
13969
- Object.defineProperty(exports$1, "_", { enumerable: true, get: function () { return code_2._; } });
13970
- Object.defineProperty(exports$1, "str", { enumerable: true, get: function () { return code_2.str; } });
13971
- Object.defineProperty(exports$1, "strConcat", { enumerable: true, get: function () { return code_2.strConcat; } });
13972
- Object.defineProperty(exports$1, "nil", { enumerable: true, get: function () { return code_2.nil; } });
13973
- Object.defineProperty(exports$1, "getProperty", { enumerable: true, get: function () { return code_2.getProperty; } });
13974
- Object.defineProperty(exports$1, "stringify", { enumerable: true, get: function () { return code_2.stringify; } });
13975
- Object.defineProperty(exports$1, "regexpCode", { enumerable: true, get: function () { return code_2.regexpCode; } });
13976
- Object.defineProperty(exports$1, "Name", { enumerable: true, get: function () { return code_2.Name; } });
13977
- var scope_2 = scope;
13978
- Object.defineProperty(exports$1, "Scope", { enumerable: true, get: function () { return scope_2.Scope; } });
13979
- Object.defineProperty(exports$1, "ValueScope", { enumerable: true, get: function () { return scope_2.ValueScope; } });
13980
- Object.defineProperty(exports$1, "ValueScopeName", { enumerable: true, get: function () { return scope_2.ValueScopeName; } });
13981
- Object.defineProperty(exports$1, "varKinds", { enumerable: true, get: function () { return scope_2.varKinds; } });
13982
- exports$1.operators = {
13983
- GT: new code_1._Code(">"),
13984
- GTE: new code_1._Code(">="),
13985
- LT: new code_1._Code("<"),
13986
- LTE: new code_1._Code("<="),
13987
- EQ: new code_1._Code("==="),
13988
- NEQ: new code_1._Code("!=="),
13989
- NOT: new code_1._Code("!"),
13990
- OR: new code_1._Code("||"),
13991
- AND: new code_1._Code("&&"),
13992
- ADD: new code_1._Code("+"),
13993
- };
13994
- class Node {
13995
- optimizeNodes() {
13996
- return this;
13997
- }
13998
- optimizeNames(_names, _constants) {
13999
- return this;
14000
- }
14001
- }
14002
- class Def extends Node {
14003
- constructor(varKind, name, rhs) {
14004
- super();
14005
- this.varKind = varKind;
14006
- this.name = name;
14007
- this.rhs = rhs;
14008
- }
14009
- render({ es5, _n }) {
14010
- const varKind = es5 ? scope_1.varKinds.var : this.varKind;
14011
- const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`;
14012
- return `${varKind} ${this.name}${rhs};` + _n;
14013
- }
14014
- optimizeNames(names, constants) {
14015
- if (!names[this.name.str])
14016
- return;
14017
- if (this.rhs)
14018
- this.rhs = optimizeExpr(this.rhs, names, constants);
14019
- return this;
14020
- }
14021
- get names() {
14022
- return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};
14023
- }
14024
- }
14025
- class Assign extends Node {
14026
- constructor(lhs, rhs, sideEffects) {
14027
- super();
14028
- this.lhs = lhs;
14029
- this.rhs = rhs;
14030
- this.sideEffects = sideEffects;
14031
- }
14032
- render({ _n }) {
14033
- return `${this.lhs} = ${this.rhs};` + _n;
14034
- }
14035
- optimizeNames(names, constants) {
14036
- if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
14037
- return;
14038
- this.rhs = optimizeExpr(this.rhs, names, constants);
14039
- return this;
14040
- }
14041
- get names() {
14042
- const names = this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names };
14043
- return addExprNames(names, this.rhs);
14044
- }
14045
- }
14046
- class AssignOp extends Assign {
14047
- constructor(lhs, op, rhs, sideEffects) {
14048
- super(lhs, rhs, sideEffects);
14049
- this.op = op;
14050
- }
14051
- render({ _n }) {
14052
- return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
14053
- }
14054
- }
14055
- class Label extends Node {
14056
- constructor(label) {
14057
- super();
14058
- this.label = label;
14059
- this.names = {};
14060
- }
14061
- render({ _n }) {
14062
- return `${this.label}:` + _n;
14063
- }
14064
- }
14065
- class Break extends Node {
14066
- constructor(label) {
14067
- super();
14068
- this.label = label;
14069
- this.names = {};
14070
- }
14071
- render({ _n }) {
14072
- const label = this.label ? ` ${this.label}` : "";
14073
- return `break${label};` + _n;
14074
- }
14075
- }
14076
- class Throw extends Node {
14077
- constructor(error) {
14078
- super();
14079
- this.error = error;
14080
- }
14081
- render({ _n }) {
14082
- return `throw ${this.error};` + _n;
14083
- }
14084
- get names() {
14085
- return this.error.names;
14086
- }
14087
- }
14088
- class AnyCode extends Node {
14089
- constructor(code) {
14090
- super();
14091
- this.code = code;
14092
- }
14093
- render({ _n }) {
14094
- return `${this.code};` + _n;
14095
- }
14096
- optimizeNodes() {
14097
- return `${this.code}` ? this : undefined;
14098
- }
14099
- optimizeNames(names, constants) {
14100
- this.code = optimizeExpr(this.code, names, constants);
14101
- return this;
14102
- }
14103
- get names() {
14104
- return this.code instanceof code_1._CodeOrName ? this.code.names : {};
14105
- }
14106
- }
14107
- class ParentNode extends Node {
14108
- constructor(nodes = []) {
14109
- super();
14110
- this.nodes = nodes;
14111
- }
14112
- render(opts) {
14113
- return this.nodes.reduce((code, n) => code + n.render(opts), "");
14114
- }
14115
- optimizeNodes() {
14116
- const { nodes } = this;
14117
- let i = nodes.length;
14118
- while (i--) {
14119
- const n = nodes[i].optimizeNodes();
14120
- if (Array.isArray(n))
14121
- nodes.splice(i, 1, ...n);
14122
- else if (n)
14123
- nodes[i] = n;
14124
- else
14125
- nodes.splice(i, 1);
14126
- }
14127
- return nodes.length > 0 ? this : undefined;
14128
- }
14129
- optimizeNames(names, constants) {
14130
- const { nodes } = this;
14131
- let i = nodes.length;
14132
- while (i--) {
14133
- // iterating backwards improves 1-pass optimization
14134
- const n = nodes[i];
14135
- if (n.optimizeNames(names, constants))
14136
- continue;
14137
- subtractNames(names, n.names);
14138
- nodes.splice(i, 1);
14139
- }
14140
- return nodes.length > 0 ? this : undefined;
14141
- }
14142
- get names() {
14143
- return this.nodes.reduce((names, n) => addNames(names, n.names), {});
14144
- }
14145
- }
14146
- class BlockNode extends ParentNode {
14147
- render(opts) {
14148
- return "{" + opts._n + super.render(opts) + "}" + opts._n;
14149
- }
14150
- }
14151
- class Root extends ParentNode {
14152
- }
14153
- class Else extends BlockNode {
14154
- }
14155
- Else.kind = "else";
14156
- class If extends BlockNode {
14157
- constructor(condition, nodes) {
14158
- super(nodes);
14159
- this.condition = condition;
14160
- }
14161
- render(opts) {
14162
- let code = `if(${this.condition})` + super.render(opts);
14163
- if (this.else)
14164
- code += "else " + this.else.render(opts);
14165
- return code;
14166
- }
14167
- optimizeNodes() {
14168
- super.optimizeNodes();
14169
- const cond = this.condition;
14170
- if (cond === true)
14171
- return this.nodes; // else is ignored here
14172
- let e = this.else;
14173
- if (e) {
14174
- const ns = e.optimizeNodes();
14175
- e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
14176
- }
14177
- if (e) {
14178
- if (cond === false)
14179
- return e instanceof If ? e : e.nodes;
14180
- if (this.nodes.length)
14181
- return this;
14182
- return new If(not(cond), e instanceof If ? [e] : e.nodes);
14183
- }
14184
- if (cond === false || !this.nodes.length)
14185
- return undefined;
14186
- return this;
14187
- }
14188
- optimizeNames(names, constants) {
14189
- var _a;
14190
- this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
14191
- if (!(super.optimizeNames(names, constants) || this.else))
14192
- return;
14193
- this.condition = optimizeExpr(this.condition, names, constants);
14194
- return this;
14195
- }
14196
- get names() {
14197
- const names = super.names;
14198
- addExprNames(names, this.condition);
14199
- if (this.else)
14200
- addNames(names, this.else.names);
14201
- return names;
14202
- }
14203
- }
14204
- If.kind = "if";
14205
- class For extends BlockNode {
14206
- }
14207
- For.kind = "for";
14208
- class ForLoop extends For {
14209
- constructor(iteration) {
14210
- super();
14211
- this.iteration = iteration;
14212
- }
14213
- render(opts) {
14214
- return `for(${this.iteration})` + super.render(opts);
14215
- }
14216
- optimizeNames(names, constants) {
14217
- if (!super.optimizeNames(names, constants))
14218
- return;
14219
- this.iteration = optimizeExpr(this.iteration, names, constants);
14220
- return this;
14221
- }
14222
- get names() {
14223
- return addNames(super.names, this.iteration.names);
14224
- }
14225
- }
14226
- class ForRange extends For {
14227
- constructor(varKind, name, from, to) {
14228
- super();
14229
- this.varKind = varKind;
14230
- this.name = name;
14231
- this.from = from;
14232
- this.to = to;
14233
- }
14234
- render(opts) {
14235
- const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
14236
- const { name, from, to } = this;
14237
- return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
14238
- }
14239
- get names() {
14240
- const names = addExprNames(super.names, this.from);
14241
- return addExprNames(names, this.to);
14242
- }
14243
- }
14244
- class ForIter extends For {
14245
- constructor(loop, varKind, name, iterable) {
14246
- super();
14247
- this.loop = loop;
14248
- this.varKind = varKind;
14249
- this.name = name;
14250
- this.iterable = iterable;
14251
- }
14252
- render(opts) {
14253
- return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
14254
- }
14255
- optimizeNames(names, constants) {
14256
- if (!super.optimizeNames(names, constants))
14257
- return;
14258
- this.iterable = optimizeExpr(this.iterable, names, constants);
14259
- return this;
14260
- }
14261
- get names() {
14262
- return addNames(super.names, this.iterable.names);
14263
- }
14264
- }
14265
- class Func extends BlockNode {
14266
- constructor(name, args, async) {
14267
- super();
14268
- this.name = name;
14269
- this.args = args;
14270
- this.async = async;
14271
- }
14272
- render(opts) {
14273
- const _async = this.async ? "async " : "";
14274
- return `${_async}function ${this.name}(${this.args})` + super.render(opts);
14275
- }
14276
- }
14277
- Func.kind = "func";
14278
- class Return extends ParentNode {
14279
- render(opts) {
14280
- return "return " + super.render(opts);
14281
- }
14282
- }
14283
- Return.kind = "return";
14284
- class Try extends BlockNode {
14285
- render(opts) {
14286
- let code = "try" + super.render(opts);
14287
- if (this.catch)
14288
- code += this.catch.render(opts);
14289
- if (this.finally)
14290
- code += this.finally.render(opts);
14291
- return code;
14292
- }
14293
- optimizeNodes() {
14294
- var _a, _b;
14295
- super.optimizeNodes();
14296
- (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();
14297
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
14298
- return this;
14299
- }
14300
- optimizeNames(names, constants) {
14301
- var _a, _b;
14302
- super.optimizeNames(names, constants);
14303
- (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
14304
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);
14305
- return this;
14306
- }
14307
- get names() {
14308
- const names = super.names;
14309
- if (this.catch)
14310
- addNames(names, this.catch.names);
14311
- if (this.finally)
14312
- addNames(names, this.finally.names);
14313
- return names;
14314
- }
14315
- }
14316
- class Catch extends BlockNode {
14317
- constructor(error) {
14318
- super();
14319
- this.error = error;
14320
- }
14321
- render(opts) {
14322
- return `catch(${this.error})` + super.render(opts);
14323
- }
14324
- }
14325
- Catch.kind = "catch";
14326
- class Finally extends BlockNode {
14327
- render(opts) {
14328
- return "finally" + super.render(opts);
14329
- }
14330
- }
14331
- Finally.kind = "finally";
14332
- class CodeGen {
14333
- constructor(extScope, opts = {}) {
14334
- this._values = {};
14335
- this._blockStarts = [];
14336
- this._constants = {};
14337
- this.opts = { ...opts, _n: opts.lines ? "\n" : "" };
14338
- this._extScope = extScope;
14339
- this._scope = new scope_1.Scope({ parent: extScope });
14340
- this._nodes = [new Root()];
14341
- }
14342
- toString() {
14343
- return this._root.render(this.opts);
14344
- }
14345
- // returns unique name in the internal scope
14346
- name(prefix) {
14347
- return this._scope.name(prefix);
14348
- }
14349
- // reserves unique name in the external scope
14350
- scopeName(prefix) {
14351
- return this._extScope.name(prefix);
14352
- }
14353
- // reserves unique name in the external scope and assigns value to it
14354
- scopeValue(prefixOrName, value) {
14355
- const name = this._extScope.value(prefixOrName, value);
14356
- const vs = this._values[name.prefix] || (this._values[name.prefix] = new Set());
14357
- vs.add(name);
14358
- return name;
14359
- }
14360
- getScopeValue(prefix, keyOrRef) {
14361
- return this._extScope.getValue(prefix, keyOrRef);
14362
- }
14363
- // return code that assigns values in the external scope to the names that are used internally
14364
- // (same names that were returned by gen.scopeName or gen.scopeValue)
14365
- scopeRefs(scopeName) {
14366
- return this._extScope.scopeRefs(scopeName, this._values);
14367
- }
14368
- scopeCode() {
14369
- return this._extScope.scopeCode(this._values);
14370
- }
14371
- _def(varKind, nameOrPrefix, rhs, constant) {
14372
- const name = this._scope.toName(nameOrPrefix);
14373
- if (rhs !== undefined && constant)
14374
- this._constants[name.str] = rhs;
14375
- this._leafNode(new Def(varKind, name, rhs));
14376
- return name;
14377
- }
14378
- // `const` declaration (`var` in es5 mode)
14379
- const(nameOrPrefix, rhs, _constant) {
14380
- return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
14381
- }
14382
- // `let` declaration with optional assignment (`var` in es5 mode)
14383
- let(nameOrPrefix, rhs, _constant) {
14384
- return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
14385
- }
14386
- // `var` declaration with optional assignment
14387
- var(nameOrPrefix, rhs, _constant) {
14388
- return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
14389
- }
14390
- // assignment code
14391
- assign(lhs, rhs, sideEffects) {
14392
- return this._leafNode(new Assign(lhs, rhs, sideEffects));
14393
- }
14394
- // `+=` code
14395
- add(lhs, rhs) {
14396
- return this._leafNode(new AssignOp(lhs, exports$1.operators.ADD, rhs));
14397
- }
14398
- // appends passed SafeExpr to code or executes Block
14399
- code(c) {
14400
- if (typeof c == "function")
14401
- c();
14402
- else if (c !== code_1.nil)
14403
- this._leafNode(new AnyCode(c));
14404
- return this;
14405
- }
14406
- // returns code for object literal for the passed argument list of key-value pairs
14407
- object(...keyValues) {
14408
- const code = ["{"];
14409
- for (const [key, value] of keyValues) {
14410
- if (code.length > 1)
14411
- code.push(",");
14412
- code.push(key);
14413
- if (key !== value || this.opts.es5) {
14414
- code.push(":");
14415
- (0, code_1.addCodeArg)(code, value);
14416
- }
14417
- }
14418
- code.push("}");
14419
- return new code_1._Code(code);
14420
- }
14421
- // `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
14422
- if(condition, thenBody, elseBody) {
14423
- this._blockNode(new If(condition));
14424
- if (thenBody && elseBody) {
14425
- this.code(thenBody).else().code(elseBody).endIf();
14426
- }
14427
- else if (thenBody) {
14428
- this.code(thenBody).endIf();
14429
- }
14430
- else if (elseBody) {
14431
- throw new Error('CodeGen: "else" body without "then" body');
14432
- }
14433
- return this;
14434
- }
14435
- // `else if` clause - invalid without `if` or after `else` clauses
14436
- elseIf(condition) {
14437
- return this._elseNode(new If(condition));
14438
- }
14439
- // `else` clause - only valid after `if` or `else if` clauses
14440
- else() {
14441
- return this._elseNode(new Else());
14442
- }
14443
- // end `if` statement (needed if gen.if was used only with condition)
14444
- endIf() {
14445
- return this._endBlockNode(If, Else);
14446
- }
14447
- _for(node, forBody) {
14448
- this._blockNode(node);
14449
- if (forBody)
14450
- this.code(forBody).endFor();
14451
- return this;
14452
- }
14453
- // a generic `for` clause (or statement if `forBody` is passed)
14454
- for(iteration, forBody) {
14455
- return this._for(new ForLoop(iteration), forBody);
14456
- }
14457
- // `for` statement for a range of values
14458
- forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
14459
- const name = this._scope.toName(nameOrPrefix);
14460
- return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
14461
- }
14462
- // `for-of` statement (in es5 mode replace with a normal for loop)
14463
- forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
14464
- const name = this._scope.toName(nameOrPrefix);
14465
- if (this.opts.es5) {
14466
- const arr = iterable instanceof code_1.Name ? iterable : this.var("_arr", iterable);
14467
- return this.forRange("_i", 0, (0, code_1._) `${arr}.length`, (i) => {
14468
- this.var(name, (0, code_1._) `${arr}[${i}]`);
14469
- forBody(name);
14470
- });
14471
- }
14472
- return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
14473
- }
14474
- // `for-in` statement.
14475
- // With option `ownProperties` replaced with a `for-of` loop for object keys
14476
- forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
14477
- if (this.opts.ownProperties) {
14478
- return this.forOf(nameOrPrefix, (0, code_1._) `Object.keys(${obj})`, forBody);
14479
- }
14480
- const name = this._scope.toName(nameOrPrefix);
14481
- return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
14482
- }
14483
- // end `for` loop
14484
- endFor() {
14485
- return this._endBlockNode(For);
14486
- }
14487
- // `label` statement
14488
- label(label) {
14489
- return this._leafNode(new Label(label));
14490
- }
14491
- // `break` statement
14492
- break(label) {
14493
- return this._leafNode(new Break(label));
14494
- }
14495
- // `return` statement
14496
- return(value) {
14497
- const node = new Return();
14498
- this._blockNode(node);
14499
- this.code(value);
14500
- if (node.nodes.length !== 1)
14501
- throw new Error('CodeGen: "return" should have one node');
14502
- return this._endBlockNode(Return);
14503
- }
14504
- // `try` statement
14505
- try(tryBody, catchCode, finallyCode) {
14506
- if (!catchCode && !finallyCode)
14507
- throw new Error('CodeGen: "try" without "catch" and "finally"');
14508
- const node = new Try();
14509
- this._blockNode(node);
14510
- this.code(tryBody);
14511
- if (catchCode) {
14512
- const error = this.name("e");
14513
- this._currNode = node.catch = new Catch(error);
14514
- catchCode(error);
14515
- }
14516
- if (finallyCode) {
14517
- this._currNode = node.finally = new Finally();
14518
- this.code(finallyCode);
14519
- }
14520
- return this._endBlockNode(Catch, Finally);
14521
- }
14522
- // `throw` statement
14523
- throw(error) {
14524
- return this._leafNode(new Throw(error));
14525
- }
14526
- // start self-balancing block
14527
- block(body, nodeCount) {
14528
- this._blockStarts.push(this._nodes.length);
14529
- if (body)
14530
- this.code(body).endBlock(nodeCount);
14531
- return this;
14532
- }
14533
- // end the current self-balancing block
14534
- endBlock(nodeCount) {
14535
- const len = this._blockStarts.pop();
14536
- if (len === undefined)
14537
- throw new Error("CodeGen: not in self-balancing block");
14538
- const toClose = this._nodes.length - len;
14539
- if (toClose < 0 || (nodeCount !== undefined && toClose !== nodeCount)) {
14540
- throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);
14541
- }
14542
- this._nodes.length = len;
14543
- return this;
14544
- }
14545
- // `function` heading (or definition if funcBody is passed)
14546
- func(name, args = code_1.nil, async, funcBody) {
14547
- this._blockNode(new Func(name, args, async));
14548
- if (funcBody)
14549
- this.code(funcBody).endFunc();
14550
- return this;
14551
- }
14552
- // end function definition
14553
- endFunc() {
14554
- return this._endBlockNode(Func);
14555
- }
14556
- optimize(n = 1) {
14557
- while (n-- > 0) {
14558
- this._root.optimizeNodes();
14559
- this._root.optimizeNames(this._root.names, this._constants);
14560
- }
14561
- }
14562
- _leafNode(node) {
14563
- this._currNode.nodes.push(node);
14564
- return this;
14565
- }
14566
- _blockNode(node) {
14567
- this._currNode.nodes.push(node);
14568
- this._nodes.push(node);
14569
- }
14570
- _endBlockNode(N1, N2) {
14571
- const n = this._currNode;
14572
- if (n instanceof N1 || (N2 && n instanceof N2)) {
14573
- this._nodes.pop();
14574
- return this;
14575
- }
14576
- throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
14577
- }
14578
- _elseNode(node) {
14579
- const n = this._currNode;
14580
- if (!(n instanceof If)) {
14581
- throw new Error('CodeGen: "else" without "if"');
14582
- }
14583
- this._currNode = n.else = node;
14584
- return this;
14585
- }
14586
- get _root() {
14587
- return this._nodes[0];
14588
- }
14589
- get _currNode() {
14590
- const ns = this._nodes;
14591
- return ns[ns.length - 1];
14592
- }
14593
- set _currNode(node) {
14594
- const ns = this._nodes;
14595
- ns[ns.length - 1] = node;
14596
- }
14597
- }
14598
- exports$1.CodeGen = CodeGen;
14599
- function addNames(names, from) {
14600
- for (const n in from)
14601
- names[n] = (names[n] || 0) + (from[n] || 0);
14602
- return names;
14603
- }
14604
- function addExprNames(names, from) {
14605
- return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
14606
- }
14607
- function optimizeExpr(expr, names, constants) {
14608
- if (expr instanceof code_1.Name)
14609
- return replaceName(expr);
14610
- if (!canOptimize(expr))
14611
- return expr;
14612
- return new code_1._Code(expr._items.reduce((items, c) => {
14613
- if (c instanceof code_1.Name)
14614
- c = replaceName(c);
14615
- if (c instanceof code_1._Code)
14616
- items.push(...c._items);
14617
- else
14618
- items.push(c);
14619
- return items;
14620
- }, []));
14621
- function replaceName(n) {
14622
- const c = constants[n.str];
14623
- if (c === undefined || names[n.str] !== 1)
14624
- return n;
14625
- delete names[n.str];
14626
- return c;
14627
- }
14628
- function canOptimize(e) {
14629
- return (e instanceof code_1._Code &&
14630
- e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== undefined));
14631
- }
14632
- }
14633
- function subtractNames(names, from) {
14634
- for (const n in from)
14635
- names[n] = (names[n] || 0) - (from[n] || 0);
14636
- }
14637
- function not(x) {
14638
- return typeof x == "boolean" || typeof x == "number" || x === null ? !x : (0, code_1._) `!${par(x)}`;
14639
- }
14640
- exports$1.not = not;
14641
- const andCode = mappend(exports$1.operators.AND);
14642
- // boolean AND (&&) expression with the passed arguments
14643
- function and(...args) {
14644
- return args.reduce(andCode);
14645
- }
14646
- exports$1.and = and;
14647
- const orCode = mappend(exports$1.operators.OR);
14648
- // boolean OR (||) expression with the passed arguments
14649
- function or(...args) {
14650
- return args.reduce(orCode);
14651
- }
14652
- exports$1.or = or;
14653
- function mappend(op) {
14654
- return (x, y) => (x === code_1.nil ? y : y === code_1.nil ? x : (0, code_1._) `${par(x)} ${op} ${par(y)}`);
14655
- }
14656
- function par(x) {
14657
- return x instanceof code_1.Name ? x : (0, code_1._) `(${x})`;
14658
- }
14659
-
14660
- } (codegen));
13827
+ function requireScope () {
13828
+ if (hasRequiredScope) return scope;
13829
+ hasRequiredScope = 1;
13830
+ (function (exports$1) {
13831
+ Object.defineProperty(exports$1, "__esModule", { value: true });
13832
+ exports$1.ValueScope = exports$1.ValueScopeName = exports$1.Scope = exports$1.varKinds = exports$1.UsedValueState = void 0;
13833
+ const code_1 = requireCode$1();
13834
+ class ValueError extends Error {
13835
+ constructor(name) {
13836
+ super(`CodeGen: "code" for ${name} not defined`);
13837
+ this.value = name.value;
13838
+ }
13839
+ }
13840
+ var UsedValueState;
13841
+ (function (UsedValueState) {
13842
+ UsedValueState[UsedValueState["Started"] = 0] = "Started";
13843
+ UsedValueState[UsedValueState["Completed"] = 1] = "Completed";
13844
+ })(UsedValueState || (exports$1.UsedValueState = UsedValueState = {}));
13845
+ exports$1.varKinds = {
13846
+ const: new code_1.Name("const"),
13847
+ let: new code_1.Name("let"),
13848
+ var: new code_1.Name("var"),
13849
+ };
13850
+ class Scope {
13851
+ constructor({ prefixes, parent } = {}) {
13852
+ this._names = {};
13853
+ this._prefixes = prefixes;
13854
+ this._parent = parent;
13855
+ }
13856
+ toName(nameOrPrefix) {
13857
+ return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);
13858
+ }
13859
+ name(prefix) {
13860
+ return new code_1.Name(this._newName(prefix));
13861
+ }
13862
+ _newName(prefix) {
13863
+ const ng = this._names[prefix] || this._nameGroup(prefix);
13864
+ return `${prefix}${ng.index++}`;
13865
+ }
13866
+ _nameGroup(prefix) {
13867
+ var _a, _b;
13868
+ 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))) {
13869
+ throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`);
13870
+ }
13871
+ return (this._names[prefix] = { prefix, index: 0 });
13872
+ }
13873
+ }
13874
+ exports$1.Scope = Scope;
13875
+ class ValueScopeName extends code_1.Name {
13876
+ constructor(prefix, nameStr) {
13877
+ super(nameStr);
13878
+ this.prefix = prefix;
13879
+ }
13880
+ setValue(value, { property, itemIndex }) {
13881
+ this.value = value;
13882
+ this.scopePath = (0, code_1._) `.${new code_1.Name(property)}[${itemIndex}]`;
13883
+ }
13884
+ }
13885
+ exports$1.ValueScopeName = ValueScopeName;
13886
+ const line = (0, code_1._) `\n`;
13887
+ class ValueScope extends Scope {
13888
+ constructor(opts) {
13889
+ super(opts);
13890
+ this._values = {};
13891
+ this._scope = opts.scope;
13892
+ this.opts = { ...opts, _n: opts.lines ? line : code_1.nil };
13893
+ }
13894
+ get() {
13895
+ return this._scope;
13896
+ }
13897
+ name(prefix) {
13898
+ return new ValueScopeName(prefix, this._newName(prefix));
13899
+ }
13900
+ value(nameOrPrefix, value) {
13901
+ var _a;
13902
+ if (value.ref === undefined)
13903
+ throw new Error("CodeGen: ref must be passed in value");
13904
+ const name = this.toName(nameOrPrefix);
13905
+ const { prefix } = name;
13906
+ const valueKey = (_a = value.key) !== null && _a !== void 0 ? _a : value.ref;
13907
+ let vs = this._values[prefix];
13908
+ if (vs) {
13909
+ const _name = vs.get(valueKey);
13910
+ if (_name)
13911
+ return _name;
13912
+ }
13913
+ else {
13914
+ vs = this._values[prefix] = new Map();
13915
+ }
13916
+ vs.set(valueKey, name);
13917
+ const s = this._scope[prefix] || (this._scope[prefix] = []);
13918
+ const itemIndex = s.length;
13919
+ s[itemIndex] = value.ref;
13920
+ name.setValue(value, { property: prefix, itemIndex });
13921
+ return name;
13922
+ }
13923
+ getValue(prefix, keyOrRef) {
13924
+ const vs = this._values[prefix];
13925
+ if (!vs)
13926
+ return;
13927
+ return vs.get(keyOrRef);
13928
+ }
13929
+ scopeRefs(scopeName, values = this._values) {
13930
+ return this._reduceValues(values, (name) => {
13931
+ if (name.scopePath === undefined)
13932
+ throw new Error(`CodeGen: name "${name}" has no value`);
13933
+ return (0, code_1._) `${scopeName}${name.scopePath}`;
13934
+ });
13935
+ }
13936
+ scopeCode(values = this._values, usedValues, getCode) {
13937
+ return this._reduceValues(values, (name) => {
13938
+ if (name.value === undefined)
13939
+ throw new Error(`CodeGen: name "${name}" has no value`);
13940
+ return name.value.code;
13941
+ }, usedValues, getCode);
13942
+ }
13943
+ _reduceValues(values, valueCode, usedValues = {}, getCode) {
13944
+ let code = code_1.nil;
13945
+ for (const prefix in values) {
13946
+ const vs = values[prefix];
13947
+ if (!vs)
13948
+ continue;
13949
+ const nameSet = (usedValues[prefix] = usedValues[prefix] || new Map());
13950
+ vs.forEach((name) => {
13951
+ if (nameSet.has(name))
13952
+ return;
13953
+ nameSet.set(name, UsedValueState.Started);
13954
+ let c = valueCode(name);
13955
+ if (c) {
13956
+ const def = this.opts.es5 ? exports$1.varKinds.var : exports$1.varKinds.const;
13957
+ code = (0, code_1._) `${code}${def} ${name} = ${c};${this.opts._n}`;
13958
+ }
13959
+ else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {
13960
+ code = (0, code_1._) `${code}${c}${this.opts._n}`;
13961
+ }
13962
+ else {
13963
+ throw new ValueError(name);
13964
+ }
13965
+ nameSet.set(name, UsedValueState.Completed);
13966
+ });
13967
+ }
13968
+ return code;
13969
+ }
13970
+ }
13971
+ exports$1.ValueScope = ValueScope;
13972
+
13973
+ } (scope));
13974
+ return scope;
13975
+ }
13976
+
13977
+ var hasRequiredCodegen;
13978
+
13979
+ function requireCodegen () {
13980
+ if (hasRequiredCodegen) return codegen;
13981
+ hasRequiredCodegen = 1;
13982
+ (function (exports$1) {
13983
+ Object.defineProperty(exports$1, "__esModule", { value: true });
13984
+ exports$1.or = exports$1.and = exports$1.not = exports$1.CodeGen = exports$1.operators = exports$1.varKinds = exports$1.ValueScopeName = exports$1.ValueScope = exports$1.Scope = exports$1.Name = exports$1.regexpCode = exports$1.stringify = exports$1.getProperty = exports$1.nil = exports$1.strConcat = exports$1.str = exports$1._ = void 0;
13985
+ const code_1 = requireCode$1();
13986
+ const scope_1 = requireScope();
13987
+ var code_2 = requireCode$1();
13988
+ Object.defineProperty(exports$1, "_", { enumerable: true, get: function () { return code_2._; } });
13989
+ Object.defineProperty(exports$1, "str", { enumerable: true, get: function () { return code_2.str; } });
13990
+ Object.defineProperty(exports$1, "strConcat", { enumerable: true, get: function () { return code_2.strConcat; } });
13991
+ Object.defineProperty(exports$1, "nil", { enumerable: true, get: function () { return code_2.nil; } });
13992
+ Object.defineProperty(exports$1, "getProperty", { enumerable: true, get: function () { return code_2.getProperty; } });
13993
+ Object.defineProperty(exports$1, "stringify", { enumerable: true, get: function () { return code_2.stringify; } });
13994
+ Object.defineProperty(exports$1, "regexpCode", { enumerable: true, get: function () { return code_2.regexpCode; } });
13995
+ Object.defineProperty(exports$1, "Name", { enumerable: true, get: function () { return code_2.Name; } });
13996
+ var scope_2 = requireScope();
13997
+ Object.defineProperty(exports$1, "Scope", { enumerable: true, get: function () { return scope_2.Scope; } });
13998
+ Object.defineProperty(exports$1, "ValueScope", { enumerable: true, get: function () { return scope_2.ValueScope; } });
13999
+ Object.defineProperty(exports$1, "ValueScopeName", { enumerable: true, get: function () { return scope_2.ValueScopeName; } });
14000
+ Object.defineProperty(exports$1, "varKinds", { enumerable: true, get: function () { return scope_2.varKinds; } });
14001
+ exports$1.operators = {
14002
+ GT: new code_1._Code(">"),
14003
+ GTE: new code_1._Code(">="),
14004
+ LT: new code_1._Code("<"),
14005
+ LTE: new code_1._Code("<="),
14006
+ EQ: new code_1._Code("==="),
14007
+ NEQ: new code_1._Code("!=="),
14008
+ NOT: new code_1._Code("!"),
14009
+ OR: new code_1._Code("||"),
14010
+ AND: new code_1._Code("&&"),
14011
+ ADD: new code_1._Code("+"),
14012
+ };
14013
+ class Node {
14014
+ optimizeNodes() {
14015
+ return this;
14016
+ }
14017
+ optimizeNames(_names, _constants) {
14018
+ return this;
14019
+ }
14020
+ }
14021
+ class Def extends Node {
14022
+ constructor(varKind, name, rhs) {
14023
+ super();
14024
+ this.varKind = varKind;
14025
+ this.name = name;
14026
+ this.rhs = rhs;
14027
+ }
14028
+ render({ es5, _n }) {
14029
+ const varKind = es5 ? scope_1.varKinds.var : this.varKind;
14030
+ const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`;
14031
+ return `${varKind} ${this.name}${rhs};` + _n;
14032
+ }
14033
+ optimizeNames(names, constants) {
14034
+ if (!names[this.name.str])
14035
+ return;
14036
+ if (this.rhs)
14037
+ this.rhs = optimizeExpr(this.rhs, names, constants);
14038
+ return this;
14039
+ }
14040
+ get names() {
14041
+ return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};
14042
+ }
14043
+ }
14044
+ class Assign extends Node {
14045
+ constructor(lhs, rhs, sideEffects) {
14046
+ super();
14047
+ this.lhs = lhs;
14048
+ this.rhs = rhs;
14049
+ this.sideEffects = sideEffects;
14050
+ }
14051
+ render({ _n }) {
14052
+ return `${this.lhs} = ${this.rhs};` + _n;
14053
+ }
14054
+ optimizeNames(names, constants) {
14055
+ if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
14056
+ return;
14057
+ this.rhs = optimizeExpr(this.rhs, names, constants);
14058
+ return this;
14059
+ }
14060
+ get names() {
14061
+ const names = this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names };
14062
+ return addExprNames(names, this.rhs);
14063
+ }
14064
+ }
14065
+ class AssignOp extends Assign {
14066
+ constructor(lhs, op, rhs, sideEffects) {
14067
+ super(lhs, rhs, sideEffects);
14068
+ this.op = op;
14069
+ }
14070
+ render({ _n }) {
14071
+ return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
14072
+ }
14073
+ }
14074
+ class Label extends Node {
14075
+ constructor(label) {
14076
+ super();
14077
+ this.label = label;
14078
+ this.names = {};
14079
+ }
14080
+ render({ _n }) {
14081
+ return `${this.label}:` + _n;
14082
+ }
14083
+ }
14084
+ class Break extends Node {
14085
+ constructor(label) {
14086
+ super();
14087
+ this.label = label;
14088
+ this.names = {};
14089
+ }
14090
+ render({ _n }) {
14091
+ const label = this.label ? ` ${this.label}` : "";
14092
+ return `break${label};` + _n;
14093
+ }
14094
+ }
14095
+ class Throw extends Node {
14096
+ constructor(error) {
14097
+ super();
14098
+ this.error = error;
14099
+ }
14100
+ render({ _n }) {
14101
+ return `throw ${this.error};` + _n;
14102
+ }
14103
+ get names() {
14104
+ return this.error.names;
14105
+ }
14106
+ }
14107
+ class AnyCode extends Node {
14108
+ constructor(code) {
14109
+ super();
14110
+ this.code = code;
14111
+ }
14112
+ render({ _n }) {
14113
+ return `${this.code};` + _n;
14114
+ }
14115
+ optimizeNodes() {
14116
+ return `${this.code}` ? this : undefined;
14117
+ }
14118
+ optimizeNames(names, constants) {
14119
+ this.code = optimizeExpr(this.code, names, constants);
14120
+ return this;
14121
+ }
14122
+ get names() {
14123
+ return this.code instanceof code_1._CodeOrName ? this.code.names : {};
14124
+ }
14125
+ }
14126
+ class ParentNode extends Node {
14127
+ constructor(nodes = []) {
14128
+ super();
14129
+ this.nodes = nodes;
14130
+ }
14131
+ render(opts) {
14132
+ return this.nodes.reduce((code, n) => code + n.render(opts), "");
14133
+ }
14134
+ optimizeNodes() {
14135
+ const { nodes } = this;
14136
+ let i = nodes.length;
14137
+ while (i--) {
14138
+ const n = nodes[i].optimizeNodes();
14139
+ if (Array.isArray(n))
14140
+ nodes.splice(i, 1, ...n);
14141
+ else if (n)
14142
+ nodes[i] = n;
14143
+ else
14144
+ nodes.splice(i, 1);
14145
+ }
14146
+ return nodes.length > 0 ? this : undefined;
14147
+ }
14148
+ optimizeNames(names, constants) {
14149
+ const { nodes } = this;
14150
+ let i = nodes.length;
14151
+ while (i--) {
14152
+ // iterating backwards improves 1-pass optimization
14153
+ const n = nodes[i];
14154
+ if (n.optimizeNames(names, constants))
14155
+ continue;
14156
+ subtractNames(names, n.names);
14157
+ nodes.splice(i, 1);
14158
+ }
14159
+ return nodes.length > 0 ? this : undefined;
14160
+ }
14161
+ get names() {
14162
+ return this.nodes.reduce((names, n) => addNames(names, n.names), {});
14163
+ }
14164
+ }
14165
+ class BlockNode extends ParentNode {
14166
+ render(opts) {
14167
+ return "{" + opts._n + super.render(opts) + "}" + opts._n;
14168
+ }
14169
+ }
14170
+ class Root extends ParentNode {
14171
+ }
14172
+ class Else extends BlockNode {
14173
+ }
14174
+ Else.kind = "else";
14175
+ class If extends BlockNode {
14176
+ constructor(condition, nodes) {
14177
+ super(nodes);
14178
+ this.condition = condition;
14179
+ }
14180
+ render(opts) {
14181
+ let code = `if(${this.condition})` + super.render(opts);
14182
+ if (this.else)
14183
+ code += "else " + this.else.render(opts);
14184
+ return code;
14185
+ }
14186
+ optimizeNodes() {
14187
+ super.optimizeNodes();
14188
+ const cond = this.condition;
14189
+ if (cond === true)
14190
+ return this.nodes; // else is ignored here
14191
+ let e = this.else;
14192
+ if (e) {
14193
+ const ns = e.optimizeNodes();
14194
+ e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
14195
+ }
14196
+ if (e) {
14197
+ if (cond === false)
14198
+ return e instanceof If ? e : e.nodes;
14199
+ if (this.nodes.length)
14200
+ return this;
14201
+ return new If(not(cond), e instanceof If ? [e] : e.nodes);
14202
+ }
14203
+ if (cond === false || !this.nodes.length)
14204
+ return undefined;
14205
+ return this;
14206
+ }
14207
+ optimizeNames(names, constants) {
14208
+ var _a;
14209
+ this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
14210
+ if (!(super.optimizeNames(names, constants) || this.else))
14211
+ return;
14212
+ this.condition = optimizeExpr(this.condition, names, constants);
14213
+ return this;
14214
+ }
14215
+ get names() {
14216
+ const names = super.names;
14217
+ addExprNames(names, this.condition);
14218
+ if (this.else)
14219
+ addNames(names, this.else.names);
14220
+ return names;
14221
+ }
14222
+ }
14223
+ If.kind = "if";
14224
+ class For extends BlockNode {
14225
+ }
14226
+ For.kind = "for";
14227
+ class ForLoop extends For {
14228
+ constructor(iteration) {
14229
+ super();
14230
+ this.iteration = iteration;
14231
+ }
14232
+ render(opts) {
14233
+ return `for(${this.iteration})` + super.render(opts);
14234
+ }
14235
+ optimizeNames(names, constants) {
14236
+ if (!super.optimizeNames(names, constants))
14237
+ return;
14238
+ this.iteration = optimizeExpr(this.iteration, names, constants);
14239
+ return this;
14240
+ }
14241
+ get names() {
14242
+ return addNames(super.names, this.iteration.names);
14243
+ }
14244
+ }
14245
+ class ForRange extends For {
14246
+ constructor(varKind, name, from, to) {
14247
+ super();
14248
+ this.varKind = varKind;
14249
+ this.name = name;
14250
+ this.from = from;
14251
+ this.to = to;
14252
+ }
14253
+ render(opts) {
14254
+ const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
14255
+ const { name, from, to } = this;
14256
+ return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
14257
+ }
14258
+ get names() {
14259
+ const names = addExprNames(super.names, this.from);
14260
+ return addExprNames(names, this.to);
14261
+ }
14262
+ }
14263
+ class ForIter extends For {
14264
+ constructor(loop, varKind, name, iterable) {
14265
+ super();
14266
+ this.loop = loop;
14267
+ this.varKind = varKind;
14268
+ this.name = name;
14269
+ this.iterable = iterable;
14270
+ }
14271
+ render(opts) {
14272
+ return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
14273
+ }
14274
+ optimizeNames(names, constants) {
14275
+ if (!super.optimizeNames(names, constants))
14276
+ return;
14277
+ this.iterable = optimizeExpr(this.iterable, names, constants);
14278
+ return this;
14279
+ }
14280
+ get names() {
14281
+ return addNames(super.names, this.iterable.names);
14282
+ }
14283
+ }
14284
+ class Func extends BlockNode {
14285
+ constructor(name, args, async) {
14286
+ super();
14287
+ this.name = name;
14288
+ this.args = args;
14289
+ this.async = async;
14290
+ }
14291
+ render(opts) {
14292
+ const _async = this.async ? "async " : "";
14293
+ return `${_async}function ${this.name}(${this.args})` + super.render(opts);
14294
+ }
14295
+ }
14296
+ Func.kind = "func";
14297
+ class Return extends ParentNode {
14298
+ render(opts) {
14299
+ return "return " + super.render(opts);
14300
+ }
14301
+ }
14302
+ Return.kind = "return";
14303
+ class Try extends BlockNode {
14304
+ render(opts) {
14305
+ let code = "try" + super.render(opts);
14306
+ if (this.catch)
14307
+ code += this.catch.render(opts);
14308
+ if (this.finally)
14309
+ code += this.finally.render(opts);
14310
+ return code;
14311
+ }
14312
+ optimizeNodes() {
14313
+ var _a, _b;
14314
+ super.optimizeNodes();
14315
+ (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();
14316
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
14317
+ return this;
14318
+ }
14319
+ optimizeNames(names, constants) {
14320
+ var _a, _b;
14321
+ super.optimizeNames(names, constants);
14322
+ (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
14323
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);
14324
+ return this;
14325
+ }
14326
+ get names() {
14327
+ const names = super.names;
14328
+ if (this.catch)
14329
+ addNames(names, this.catch.names);
14330
+ if (this.finally)
14331
+ addNames(names, this.finally.names);
14332
+ return names;
14333
+ }
14334
+ }
14335
+ class Catch extends BlockNode {
14336
+ constructor(error) {
14337
+ super();
14338
+ this.error = error;
14339
+ }
14340
+ render(opts) {
14341
+ return `catch(${this.error})` + super.render(opts);
14342
+ }
14343
+ }
14344
+ Catch.kind = "catch";
14345
+ class Finally extends BlockNode {
14346
+ render(opts) {
14347
+ return "finally" + super.render(opts);
14348
+ }
14349
+ }
14350
+ Finally.kind = "finally";
14351
+ class CodeGen {
14352
+ constructor(extScope, opts = {}) {
14353
+ this._values = {};
14354
+ this._blockStarts = [];
14355
+ this._constants = {};
14356
+ this.opts = { ...opts, _n: opts.lines ? "\n" : "" };
14357
+ this._extScope = extScope;
14358
+ this._scope = new scope_1.Scope({ parent: extScope });
14359
+ this._nodes = [new Root()];
14360
+ }
14361
+ toString() {
14362
+ return this._root.render(this.opts);
14363
+ }
14364
+ // returns unique name in the internal scope
14365
+ name(prefix) {
14366
+ return this._scope.name(prefix);
14367
+ }
14368
+ // reserves unique name in the external scope
14369
+ scopeName(prefix) {
14370
+ return this._extScope.name(prefix);
14371
+ }
14372
+ // reserves unique name in the external scope and assigns value to it
14373
+ scopeValue(prefixOrName, value) {
14374
+ const name = this._extScope.value(prefixOrName, value);
14375
+ const vs = this._values[name.prefix] || (this._values[name.prefix] = new Set());
14376
+ vs.add(name);
14377
+ return name;
14378
+ }
14379
+ getScopeValue(prefix, keyOrRef) {
14380
+ return this._extScope.getValue(prefix, keyOrRef);
14381
+ }
14382
+ // return code that assigns values in the external scope to the names that are used internally
14383
+ // (same names that were returned by gen.scopeName or gen.scopeValue)
14384
+ scopeRefs(scopeName) {
14385
+ return this._extScope.scopeRefs(scopeName, this._values);
14386
+ }
14387
+ scopeCode() {
14388
+ return this._extScope.scopeCode(this._values);
14389
+ }
14390
+ _def(varKind, nameOrPrefix, rhs, constant) {
14391
+ const name = this._scope.toName(nameOrPrefix);
14392
+ if (rhs !== undefined && constant)
14393
+ this._constants[name.str] = rhs;
14394
+ this._leafNode(new Def(varKind, name, rhs));
14395
+ return name;
14396
+ }
14397
+ // `const` declaration (`var` in es5 mode)
14398
+ const(nameOrPrefix, rhs, _constant) {
14399
+ return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
14400
+ }
14401
+ // `let` declaration with optional assignment (`var` in es5 mode)
14402
+ let(nameOrPrefix, rhs, _constant) {
14403
+ return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
14404
+ }
14405
+ // `var` declaration with optional assignment
14406
+ var(nameOrPrefix, rhs, _constant) {
14407
+ return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
14408
+ }
14409
+ // assignment code
14410
+ assign(lhs, rhs, sideEffects) {
14411
+ return this._leafNode(new Assign(lhs, rhs, sideEffects));
14412
+ }
14413
+ // `+=` code
14414
+ add(lhs, rhs) {
14415
+ return this._leafNode(new AssignOp(lhs, exports$1.operators.ADD, rhs));
14416
+ }
14417
+ // appends passed SafeExpr to code or executes Block
14418
+ code(c) {
14419
+ if (typeof c == "function")
14420
+ c();
14421
+ else if (c !== code_1.nil)
14422
+ this._leafNode(new AnyCode(c));
14423
+ return this;
14424
+ }
14425
+ // returns code for object literal for the passed argument list of key-value pairs
14426
+ object(...keyValues) {
14427
+ const code = ["{"];
14428
+ for (const [key, value] of keyValues) {
14429
+ if (code.length > 1)
14430
+ code.push(",");
14431
+ code.push(key);
14432
+ if (key !== value || this.opts.es5) {
14433
+ code.push(":");
14434
+ (0, code_1.addCodeArg)(code, value);
14435
+ }
14436
+ }
14437
+ code.push("}");
14438
+ return new code_1._Code(code);
14439
+ }
14440
+ // `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
14441
+ if(condition, thenBody, elseBody) {
14442
+ this._blockNode(new If(condition));
14443
+ if (thenBody && elseBody) {
14444
+ this.code(thenBody).else().code(elseBody).endIf();
14445
+ }
14446
+ else if (thenBody) {
14447
+ this.code(thenBody).endIf();
14448
+ }
14449
+ else if (elseBody) {
14450
+ throw new Error('CodeGen: "else" body without "then" body');
14451
+ }
14452
+ return this;
14453
+ }
14454
+ // `else if` clause - invalid without `if` or after `else` clauses
14455
+ elseIf(condition) {
14456
+ return this._elseNode(new If(condition));
14457
+ }
14458
+ // `else` clause - only valid after `if` or `else if` clauses
14459
+ else() {
14460
+ return this._elseNode(new Else());
14461
+ }
14462
+ // end `if` statement (needed if gen.if was used only with condition)
14463
+ endIf() {
14464
+ return this._endBlockNode(If, Else);
14465
+ }
14466
+ _for(node, forBody) {
14467
+ this._blockNode(node);
14468
+ if (forBody)
14469
+ this.code(forBody).endFor();
14470
+ return this;
14471
+ }
14472
+ // a generic `for` clause (or statement if `forBody` is passed)
14473
+ for(iteration, forBody) {
14474
+ return this._for(new ForLoop(iteration), forBody);
14475
+ }
14476
+ // `for` statement for a range of values
14477
+ forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
14478
+ const name = this._scope.toName(nameOrPrefix);
14479
+ return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
14480
+ }
14481
+ // `for-of` statement (in es5 mode replace with a normal for loop)
14482
+ forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
14483
+ const name = this._scope.toName(nameOrPrefix);
14484
+ if (this.opts.es5) {
14485
+ const arr = iterable instanceof code_1.Name ? iterable : this.var("_arr", iterable);
14486
+ return this.forRange("_i", 0, (0, code_1._) `${arr}.length`, (i) => {
14487
+ this.var(name, (0, code_1._) `${arr}[${i}]`);
14488
+ forBody(name);
14489
+ });
14490
+ }
14491
+ return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
14492
+ }
14493
+ // `for-in` statement.
14494
+ // With option `ownProperties` replaced with a `for-of` loop for object keys
14495
+ forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
14496
+ if (this.opts.ownProperties) {
14497
+ return this.forOf(nameOrPrefix, (0, code_1._) `Object.keys(${obj})`, forBody);
14498
+ }
14499
+ const name = this._scope.toName(nameOrPrefix);
14500
+ return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
14501
+ }
14502
+ // end `for` loop
14503
+ endFor() {
14504
+ return this._endBlockNode(For);
14505
+ }
14506
+ // `label` statement
14507
+ label(label) {
14508
+ return this._leafNode(new Label(label));
14509
+ }
14510
+ // `break` statement
14511
+ break(label) {
14512
+ return this._leafNode(new Break(label));
14513
+ }
14514
+ // `return` statement
14515
+ return(value) {
14516
+ const node = new Return();
14517
+ this._blockNode(node);
14518
+ this.code(value);
14519
+ if (node.nodes.length !== 1)
14520
+ throw new Error('CodeGen: "return" should have one node');
14521
+ return this._endBlockNode(Return);
14522
+ }
14523
+ // `try` statement
14524
+ try(tryBody, catchCode, finallyCode) {
14525
+ if (!catchCode && !finallyCode)
14526
+ throw new Error('CodeGen: "try" without "catch" and "finally"');
14527
+ const node = new Try();
14528
+ this._blockNode(node);
14529
+ this.code(tryBody);
14530
+ if (catchCode) {
14531
+ const error = this.name("e");
14532
+ this._currNode = node.catch = new Catch(error);
14533
+ catchCode(error);
14534
+ }
14535
+ if (finallyCode) {
14536
+ this._currNode = node.finally = new Finally();
14537
+ this.code(finallyCode);
14538
+ }
14539
+ return this._endBlockNode(Catch, Finally);
14540
+ }
14541
+ // `throw` statement
14542
+ throw(error) {
14543
+ return this._leafNode(new Throw(error));
14544
+ }
14545
+ // start self-balancing block
14546
+ block(body, nodeCount) {
14547
+ this._blockStarts.push(this._nodes.length);
14548
+ if (body)
14549
+ this.code(body).endBlock(nodeCount);
14550
+ return this;
14551
+ }
14552
+ // end the current self-balancing block
14553
+ endBlock(nodeCount) {
14554
+ const len = this._blockStarts.pop();
14555
+ if (len === undefined)
14556
+ throw new Error("CodeGen: not in self-balancing block");
14557
+ const toClose = this._nodes.length - len;
14558
+ if (toClose < 0 || (nodeCount !== undefined && toClose !== nodeCount)) {
14559
+ throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);
14560
+ }
14561
+ this._nodes.length = len;
14562
+ return this;
14563
+ }
14564
+ // `function` heading (or definition if funcBody is passed)
14565
+ func(name, args = code_1.nil, async, funcBody) {
14566
+ this._blockNode(new Func(name, args, async));
14567
+ if (funcBody)
14568
+ this.code(funcBody).endFunc();
14569
+ return this;
14570
+ }
14571
+ // end function definition
14572
+ endFunc() {
14573
+ return this._endBlockNode(Func);
14574
+ }
14575
+ optimize(n = 1) {
14576
+ while (n-- > 0) {
14577
+ this._root.optimizeNodes();
14578
+ this._root.optimizeNames(this._root.names, this._constants);
14579
+ }
14580
+ }
14581
+ _leafNode(node) {
14582
+ this._currNode.nodes.push(node);
14583
+ return this;
14584
+ }
14585
+ _blockNode(node) {
14586
+ this._currNode.nodes.push(node);
14587
+ this._nodes.push(node);
14588
+ }
14589
+ _endBlockNode(N1, N2) {
14590
+ const n = this._currNode;
14591
+ if (n instanceof N1 || (N2 && n instanceof N2)) {
14592
+ this._nodes.pop();
14593
+ return this;
14594
+ }
14595
+ throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
14596
+ }
14597
+ _elseNode(node) {
14598
+ const n = this._currNode;
14599
+ if (!(n instanceof If)) {
14600
+ throw new Error('CodeGen: "else" without "if"');
14601
+ }
14602
+ this._currNode = n.else = node;
14603
+ return this;
14604
+ }
14605
+ get _root() {
14606
+ return this._nodes[0];
14607
+ }
14608
+ get _currNode() {
14609
+ const ns = this._nodes;
14610
+ return ns[ns.length - 1];
14611
+ }
14612
+ set _currNode(node) {
14613
+ const ns = this._nodes;
14614
+ ns[ns.length - 1] = node;
14615
+ }
14616
+ }
14617
+ exports$1.CodeGen = CodeGen;
14618
+ function addNames(names, from) {
14619
+ for (const n in from)
14620
+ names[n] = (names[n] || 0) + (from[n] || 0);
14621
+ return names;
14622
+ }
14623
+ function addExprNames(names, from) {
14624
+ return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
14625
+ }
14626
+ function optimizeExpr(expr, names, constants) {
14627
+ if (expr instanceof code_1.Name)
14628
+ return replaceName(expr);
14629
+ if (!canOptimize(expr))
14630
+ return expr;
14631
+ return new code_1._Code(expr._items.reduce((items, c) => {
14632
+ if (c instanceof code_1.Name)
14633
+ c = replaceName(c);
14634
+ if (c instanceof code_1._Code)
14635
+ items.push(...c._items);
14636
+ else
14637
+ items.push(c);
14638
+ return items;
14639
+ }, []));
14640
+ function replaceName(n) {
14641
+ const c = constants[n.str];
14642
+ if (c === undefined || names[n.str] !== 1)
14643
+ return n;
14644
+ delete names[n.str];
14645
+ return c;
14646
+ }
14647
+ function canOptimize(e) {
14648
+ return (e instanceof code_1._Code &&
14649
+ e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== undefined));
14650
+ }
14651
+ }
14652
+ function subtractNames(names, from) {
14653
+ for (const n in from)
14654
+ names[n] = (names[n] || 0) - (from[n] || 0);
14655
+ }
14656
+ function not(x) {
14657
+ return typeof x == "boolean" || typeof x == "number" || x === null ? !x : (0, code_1._) `!${par(x)}`;
14658
+ }
14659
+ exports$1.not = not;
14660
+ const andCode = mappend(exports$1.operators.AND);
14661
+ // boolean AND (&&) expression with the passed arguments
14662
+ function and(...args) {
14663
+ return args.reduce(andCode);
14664
+ }
14665
+ exports$1.and = and;
14666
+ const orCode = mappend(exports$1.operators.OR);
14667
+ // boolean OR (||) expression with the passed arguments
14668
+ function or(...args) {
14669
+ return args.reduce(orCode);
14670
+ }
14671
+ exports$1.or = or;
14672
+ function mappend(op) {
14673
+ return (x, y) => (x === code_1.nil ? y : y === code_1.nil ? x : (0, code_1._) `${par(x)} ${op} ${par(y)}`);
14674
+ }
14675
+ function par(x) {
14676
+ return x instanceof code_1.Name ? x : (0, code_1._) `(${x})`;
14677
+ }
14678
+
14679
+ } (codegen));
14680
+ return codegen;
14681
+ }
14661
14682
 
14662
14683
  var util = {};
14663
14684
 
14664
14685
  Object.defineProperty(util, "__esModule", { value: true });
14665
14686
  util.checkStrictMode = util.getErrorPath = util.Type = util.useFunc = util.setEvaluated = util.evaluatedPropsToName = util.mergeEvaluated = util.eachItem = util.unescapeJsonPointer = util.escapeJsonPointer = util.escapeFragment = util.unescapeFragment = util.schemaRefOrVal = util.schemaHasRulesButRef = util.schemaHasRules = util.checkUnknownRules = util.alwaysValidSchema = util.toHash = void 0;
14666
- const codegen_1$o = codegen;
14667
- const code_1$9 = code$1;
14687
+ const codegen_1$o = requireCodegen();
14688
+ const code_1$9 = requireCode$1();
14668
14689
  // TODO refactor to use Set
14669
14690
  function toHash(arr) {
14670
14691
  const hash = {};
@@ -14846,7 +14867,7 @@ function requireNames () {
14846
14867
  if (hasRequiredNames) return names;
14847
14868
  hasRequiredNames = 1;
14848
14869
  Object.defineProperty(names, "__esModule", { value: true });
14849
- const codegen_1 = codegen;
14870
+ const codegen_1 = requireCodegen();
14850
14871
  const names$1 = {
14851
14872
  // validation function arguments
14852
14873
  data: new codegen_1.Name("data"), // data passed to validation function
@@ -14883,7 +14904,7 @@ function requireErrors () {
14883
14904
  (function (exports$1) {
14884
14905
  Object.defineProperty(exports$1, "__esModule", { value: true });
14885
14906
  exports$1.extendErrors = exports$1.resetErrorsCount = exports$1.reportExtraError = exports$1.reportError = exports$1.keyword$DataError = exports$1.keywordError = void 0;
14886
- const codegen_1 = codegen;
14907
+ const codegen_1 = requireCodegen();
14887
14908
  const util_1 = util;
14888
14909
  const names_1 = requireNames();
14889
14910
  exports$1.keywordError = {
@@ -15015,7 +15036,7 @@ function requireBoolSchema () {
15015
15036
  Object.defineProperty(boolSchema, "__esModule", { value: true });
15016
15037
  boolSchema.boolOrEmptySchema = boolSchema.topBoolOrEmptySchema = void 0;
15017
15038
  const errors_1 = requireErrors();
15018
- const codegen_1 = codegen;
15039
+ const codegen_1 = requireCodegen();
15019
15040
  const names_1 = requireNames();
15020
15041
  const boolError = {
15021
15042
  message: "boolean schema is false",
@@ -15126,7 +15147,7 @@ dataType.reportTypeError = dataType.checkDataTypes = dataType.checkDataType = da
15126
15147
  const rules_1 = rules;
15127
15148
  const applicability_1 = requireApplicability();
15128
15149
  const errors_1 = requireErrors();
15129
- const codegen_1$n = codegen;
15150
+ const codegen_1$n = requireCodegen();
15130
15151
  const util_1$m = util;
15131
15152
  var DataType;
15132
15153
  (function (DataType) {
@@ -15332,7 +15353,7 @@ function requireDefaults () {
15332
15353
  hasRequiredDefaults = 1;
15333
15354
  Object.defineProperty(defaults, "__esModule", { value: true });
15334
15355
  defaults.assignDefaults = void 0;
15335
- const codegen_1 = codegen;
15356
+ const codegen_1 = requireCodegen();
15336
15357
  const util_1 = util;
15337
15358
  function assignDefaults(it, ty) {
15338
15359
  const { properties, items } = it.schema;
@@ -15378,7 +15399,7 @@ function requireCode () {
15378
15399
  hasRequiredCode = 1;
15379
15400
  Object.defineProperty(code, "__esModule", { value: true });
15380
15401
  code.validateUnion = code.validateArray = code.usePattern = code.callValidateCode = code.schemaProperties = code.allSchemaProperties = code.noPropertyInData = code.propertyInData = code.isOwnProperty = code.hasPropFunc = code.reportMissingProp = code.checkMissingProp = code.checkReportMissingProp = void 0;
15381
- const codegen_1 = codegen;
15402
+ const codegen_1 = requireCodegen();
15382
15403
  const util_1 = util;
15383
15404
  const names_1 = requireNames();
15384
15405
  const util_2 = util;
@@ -15516,7 +15537,7 @@ function requireKeyword () {
15516
15537
  hasRequiredKeyword = 1;
15517
15538
  Object.defineProperty(keyword, "__esModule", { value: true });
15518
15539
  keyword.validateKeywordUsage = keyword.validSchemaType = keyword.funcKeywordCode = keyword.macroKeywordCode = void 0;
15519
- const codegen_1 = codegen;
15540
+ const codegen_1 = requireCodegen();
15520
15541
  const names_1 = requireNames();
15521
15542
  const code_1 = requireCode();
15522
15543
  const errors_1 = requireErrors();
@@ -15649,7 +15670,7 @@ function requireSubschema () {
15649
15670
  hasRequiredSubschema = 1;
15650
15671
  Object.defineProperty(subschema, "__esModule", { value: true });
15651
15672
  subschema.extendSubschemaMode = subschema.extendSubschemaData = subschema.getSubschema = void 0;
15652
- const codegen_1 = codegen;
15673
+ const codegen_1 = requireCodegen();
15653
15674
  const util_1 = util;
15654
15675
  function getSubschema(it, { keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
15655
15676
  if (keyword !== undefined && schema !== undefined) {
@@ -16041,7 +16062,7 @@ function requireValidate () {
16041
16062
  const defaults_1 = requireDefaults();
16042
16063
  const keyword_1 = requireKeyword();
16043
16064
  const subschema_1 = requireSubschema();
16044
- const codegen_1 = codegen;
16065
+ const codegen_1 = requireCodegen();
16045
16066
  const names_1 = requireNames();
16046
16067
  const resolve_1 = resolve$2;
16047
16068
  const util_1 = util;
@@ -16598,7 +16619,7 @@ var compile = {};
16598
16619
 
16599
16620
  Object.defineProperty(compile, "__esModule", { value: true });
16600
16621
  compile.resolveSchema = compile.getCompilingSchema = compile.resolveRef = compile.compileSchema = compile.SchemaEnv = void 0;
16601
- const codegen_1$m = codegen;
16622
+ const codegen_1$m = requireCodegen();
16602
16623
  const validation_error_1 = requireValidation_error();
16603
16624
  const names_1$2 = requireNames();
16604
16625
  const resolve_1 = resolve$2;
@@ -17644,7 +17665,7 @@ uri$1.default = uri;
17644
17665
  exports$1.CodeGen = exports$1.Name = exports$1.nil = exports$1.stringify = exports$1.str = exports$1._ = exports$1.KeywordCxt = void 0;
17645
17666
  var validate_1 = requireValidate();
17646
17667
  Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
17647
- var codegen_1 = codegen;
17668
+ var codegen_1 = requireCodegen();
17648
17669
  Object.defineProperty(exports$1, "_", { enumerable: true, get: function () { return codegen_1._; } });
17649
17670
  Object.defineProperty(exports$1, "str", { enumerable: true, get: function () { return codegen_1.str; } });
17650
17671
  Object.defineProperty(exports$1, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
@@ -17655,7 +17676,7 @@ uri$1.default = uri;
17655
17676
  const ref_error_1 = requireRef_error();
17656
17677
  const rules_1 = rules;
17657
17678
  const compile_1 = compile;
17658
- const codegen_2 = codegen;
17679
+ const codegen_2 = requireCodegen();
17659
17680
  const resolve_1 = resolve$2;
17660
17681
  const dataType_1 = dataType;
17661
17682
  const util_1 = util;
@@ -18280,7 +18301,7 @@ Object.defineProperty(ref, "__esModule", { value: true });
18280
18301
  ref.callRef = ref.getValidate = void 0;
18281
18302
  const ref_error_1$1 = requireRef_error();
18282
18303
  const code_1$8 = requireCode();
18283
- const codegen_1$l = codegen;
18304
+ const codegen_1$l = requireCodegen();
18284
18305
  const names_1$1 = requireNames();
18285
18306
  const compile_1$1 = compile;
18286
18307
  const util_1$j = util;
@@ -18417,7 +18438,7 @@ var validation$1 = {};
18417
18438
  var limitNumber = {};
18418
18439
 
18419
18440
  Object.defineProperty(limitNumber, "__esModule", { value: true });
18420
- const codegen_1$k = codegen;
18441
+ const codegen_1$k = requireCodegen();
18421
18442
  const ops = codegen_1$k.operators;
18422
18443
  const KWDs = {
18423
18444
  maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -18445,7 +18466,7 @@ limitNumber.default = def$q;
18445
18466
  var multipleOf = {};
18446
18467
 
18447
18468
  Object.defineProperty(multipleOf, "__esModule", { value: true });
18448
- const codegen_1$j = codegen;
18469
+ const codegen_1$j = requireCodegen();
18449
18470
  const error$h = {
18450
18471
  message: ({ schemaCode }) => (0, codegen_1$j.str) `must be multiple of ${schemaCode}`,
18451
18472
  params: ({ schemaCode }) => (0, codegen_1$j._) `{multipleOf: ${schemaCode}}`,
@@ -18497,7 +18518,7 @@ ucs2length$1.default = ucs2length;
18497
18518
  ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default';
18498
18519
 
18499
18520
  Object.defineProperty(limitLength, "__esModule", { value: true });
18500
- const codegen_1$i = codegen;
18521
+ const codegen_1$i = requireCodegen();
18501
18522
  const util_1$i = util;
18502
18523
  const ucs2length_1 = ucs2length$1;
18503
18524
  const error$g = {
@@ -18526,7 +18547,7 @@ var pattern = {};
18526
18547
 
18527
18548
  Object.defineProperty(pattern, "__esModule", { value: true });
18528
18549
  const code_1$7 = requireCode();
18529
- const codegen_1$h = codegen;
18550
+ const codegen_1$h = requireCodegen();
18530
18551
  const error$f = {
18531
18552
  message: ({ schemaCode }) => (0, codegen_1$h.str) `must match pattern "${schemaCode}"`,
18532
18553
  params: ({ schemaCode }) => (0, codegen_1$h._) `{pattern: ${schemaCode}}`,
@@ -18550,7 +18571,7 @@ pattern.default = def$n;
18550
18571
  var limitProperties = {};
18551
18572
 
18552
18573
  Object.defineProperty(limitProperties, "__esModule", { value: true });
18553
- const codegen_1$g = codegen;
18574
+ const codegen_1$g = requireCodegen();
18554
18575
  const error$e = {
18555
18576
  message({ keyword, schemaCode }) {
18556
18577
  const comp = keyword === "maxProperties" ? "more" : "fewer";
@@ -18576,7 +18597,7 @@ var required = {};
18576
18597
 
18577
18598
  Object.defineProperty(required, "__esModule", { value: true });
18578
18599
  const code_1$6 = requireCode();
18579
- const codegen_1$f = codegen;
18600
+ const codegen_1$f = requireCodegen();
18580
18601
  const util_1$h = util;
18581
18602
  const error$d = {
18582
18603
  message: ({ params: { missingProperty } }) => (0, codegen_1$f.str) `must have required property '${missingProperty}'`,
@@ -18655,7 +18676,7 @@ required.default = def$l;
18655
18676
  var limitItems = {};
18656
18677
 
18657
18678
  Object.defineProperty(limitItems, "__esModule", { value: true });
18658
- const codegen_1$e = codegen;
18679
+ const codegen_1$e = requireCodegen();
18659
18680
  const error$c = {
18660
18681
  message({ keyword, schemaCode }) {
18661
18682
  const comp = keyword === "maxItems" ? "more" : "fewer";
@@ -18689,7 +18710,7 @@ equal$1.default = equal;
18689
18710
 
18690
18711
  Object.defineProperty(uniqueItems, "__esModule", { value: true });
18691
18712
  const dataType_1 = dataType;
18692
- const codegen_1$d = codegen;
18713
+ const codegen_1$d = requireCodegen();
18693
18714
  const util_1$g = util;
18694
18715
  const equal_1$2 = equal$1;
18695
18716
  const error$b = {
@@ -18753,7 +18774,7 @@ uniqueItems.default = def$j;
18753
18774
  var _const = {};
18754
18775
 
18755
18776
  Object.defineProperty(_const, "__esModule", { value: true });
18756
- const codegen_1$c = codegen;
18777
+ const codegen_1$c = requireCodegen();
18757
18778
  const util_1$f = util;
18758
18779
  const equal_1$1 = equal$1;
18759
18780
  const error$a = {
@@ -18779,7 +18800,7 @@ _const.default = def$i;
18779
18800
  var _enum = {};
18780
18801
 
18781
18802
  Object.defineProperty(_enum, "__esModule", { value: true });
18782
- const codegen_1$b = codegen;
18803
+ const codegen_1$b = requireCodegen();
18783
18804
  const util_1$e = util;
18784
18805
  const equal_1 = equal$1;
18785
18806
  const error$9 = {
@@ -18863,7 +18884,7 @@ var additionalItems = {};
18863
18884
 
18864
18885
  Object.defineProperty(additionalItems, "__esModule", { value: true });
18865
18886
  additionalItems.validateAdditionalItems = void 0;
18866
- const codegen_1$a = codegen;
18887
+ const codegen_1$a = requireCodegen();
18867
18888
  const util_1$d = util;
18868
18889
  const error$8 = {
18869
18890
  message: ({ params: { len } }) => (0, codegen_1$a.str) `must NOT have more than ${len} items`,
@@ -18915,7 +18936,7 @@ var items = {};
18915
18936
 
18916
18937
  Object.defineProperty(items, "__esModule", { value: true });
18917
18938
  items.validateTuple = void 0;
18918
- const codegen_1$9 = codegen;
18939
+ const codegen_1$9 = requireCodegen();
18919
18940
  const util_1$c = util;
18920
18941
  const code_1$5 = requireCode();
18921
18942
  const def$f = {
@@ -18978,7 +18999,7 @@ prefixItems.default = def$e;
18978
18999
  var items2020 = {};
18979
19000
 
18980
19001
  Object.defineProperty(items2020, "__esModule", { value: true });
18981
- const codegen_1$8 = codegen;
19002
+ const codegen_1$8 = requireCodegen();
18982
19003
  const util_1$b = util;
18983
19004
  const code_1$4 = requireCode();
18984
19005
  const additionalItems_1$1 = additionalItems;
@@ -19009,7 +19030,7 @@ items2020.default = def$d;
19009
19030
  var contains = {};
19010
19031
 
19011
19032
  Object.defineProperty(contains, "__esModule", { value: true });
19012
- const codegen_1$7 = codegen;
19033
+ const codegen_1$7 = requireCodegen();
19013
19034
  const util_1$a = util;
19014
19035
  const error$6 = {
19015
19036
  message: ({ params: { min, max } }) => max === undefined
@@ -19107,7 +19128,7 @@ var dependencies$1 = {};
19107
19128
  (function (exports$1) {
19108
19129
  Object.defineProperty(exports$1, "__esModule", { value: true });
19109
19130
  exports$1.validateSchemaDeps = exports$1.validatePropertyDeps = exports$1.error = void 0;
19110
- const codegen_1 = codegen;
19131
+ const codegen_1 = requireCodegen();
19111
19132
  const util_1 = util;
19112
19133
  const code_1 = requireCode();
19113
19134
  exports$1.error = {
@@ -19194,7 +19215,7 @@ var dependencies$1 = {};
19194
19215
  var propertyNames = {};
19195
19216
 
19196
19217
  Object.defineProperty(propertyNames, "__esModule", { value: true });
19197
- const codegen_1$6 = codegen;
19218
+ const codegen_1$6 = requireCodegen();
19198
19219
  const util_1$9 = util;
19199
19220
  const error$5 = {
19200
19221
  message: "property name must be valid",
@@ -19234,7 +19255,7 @@ var additionalProperties = {};
19234
19255
 
19235
19256
  Object.defineProperty(additionalProperties, "__esModule", { value: true });
19236
19257
  const code_1$3 = requireCode();
19237
- const codegen_1$5 = codegen;
19258
+ const codegen_1$5 = requireCodegen();
19238
19259
  const names_1 = requireNames();
19239
19260
  const util_1$8 = util;
19240
19261
  const error$4 = {
@@ -19396,7 +19417,7 @@ var patternProperties = {};
19396
19417
 
19397
19418
  Object.defineProperty(patternProperties, "__esModule", { value: true });
19398
19419
  const code_1$1 = requireCode();
19399
- const codegen_1$4 = codegen;
19420
+ const codegen_1$4 = requireCodegen();
19400
19421
  const util_1$6 = util;
19401
19422
  const util_2 = util;
19402
19423
  const def$8 = {
@@ -19511,7 +19532,7 @@ anyOf.default = def$6;
19511
19532
  var oneOf = {};
19512
19533
 
19513
19534
  Object.defineProperty(oneOf, "__esModule", { value: true });
19514
- const codegen_1$3 = codegen;
19535
+ const codegen_1$3 = requireCodegen();
19515
19536
  const util_1$4 = util;
19516
19537
  const error$3 = {
19517
19538
  message: "must match exactly one schema in oneOf",
@@ -19596,7 +19617,7 @@ allOf.default = def$4;
19596
19617
  var _if = {};
19597
19618
 
19598
19619
  Object.defineProperty(_if, "__esModule", { value: true });
19599
- const codegen_1$2 = codegen;
19620
+ const codegen_1$2 = requireCodegen();
19600
19621
  const util_1$2 = util;
19601
19622
  const error$2 = {
19602
19623
  message: ({ params }) => (0, codegen_1$2.str) `must match "${params.ifClause}" schema`,
@@ -19722,7 +19743,7 @@ var format$2 = {};
19722
19743
  var format$1 = {};
19723
19744
 
19724
19745
  Object.defineProperty(format$1, "__esModule", { value: true });
19725
- const codegen_1$1 = codegen;
19746
+ const codegen_1$1 = requireCodegen();
19726
19747
  const error$1 = {
19727
19748
  message: ({ schemaCode }) => (0, codegen_1$1.str) `must match format "${schemaCode}"`,
19728
19749
  params: ({ schemaCode }) => (0, codegen_1$1._) `{format: ${schemaCode}}`,
@@ -19865,7 +19886,7 @@ var DiscrError;
19865
19886
  })(DiscrError || (types.DiscrError = DiscrError = {}));
19866
19887
 
19867
19888
  Object.defineProperty(discriminator, "__esModule", { value: true });
19868
- const codegen_1 = codegen;
19889
+ const codegen_1 = requireCodegen();
19869
19890
  const types_1 = types;
19870
19891
  const compile_1 = compile;
19871
19892
  const ref_error_1 = requireRef_error();
@@ -20257,7 +20278,7 @@ var require$$3 = {
20257
20278
  exports$1.default = Ajv;
20258
20279
  var validate_1 = requireValidate();
20259
20280
  Object.defineProperty(exports$1, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
20260
- var codegen_1 = codegen;
20281
+ var codegen_1 = requireCodegen();
20261
20282
  Object.defineProperty(exports$1, "_", { enumerable: true, get: function () { return codegen_1._; } });
20262
20283
  Object.defineProperty(exports$1, "str", { enumerable: true, get: function () { return codegen_1.str; } });
20263
20284
  Object.defineProperty(exports$1, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
@@ -20494,7 +20515,7 @@ var limit = {};
20494
20515
  Object.defineProperty(exports$1, "__esModule", { value: true });
20495
20516
  exports$1.formatLimitDefinition = void 0;
20496
20517
  const ajv_1 = ajvExports;
20497
- const codegen_1 = codegen;
20518
+ const codegen_1 = requireCodegen();
20498
20519
  const ops = codegen_1.operators;
20499
20520
  const KWDs = {
20500
20521
  formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
@@ -20565,7 +20586,7 @@ var limit = {};
20565
20586
  Object.defineProperty(exports$1, "__esModule", { value: true });
20566
20587
  const formats_1 = formats;
20567
20588
  const limit_1 = limit;
20568
- const codegen_1 = codegen;
20589
+ const codegen_1 = requireCodegen();
20569
20590
  const fullName = new codegen_1.Name("fullFormats");
20570
20591
  const fastName = new codegen_1.Name("fastFormats");
20571
20592
  const formatsPlugin = (ajv, opts = { keywords: true }) => {
@@ -23037,8 +23058,8 @@ function getAutomationFramework(workingDirectory, activeFile) {
23037
23058
  }
23038
23059
 
23039
23060
  var name = "@applitools/mcp";
23040
- var mcpName = "io.github.Applitools/applitools";
23041
- var version = "0.4.0";
23061
+ var mcpName = "io.github.applitools/applitools";
23062
+ var version = "0.4.1";
23042
23063
  var description = "Applitools MCP server for AI coding assistants";
23043
23064
  var main = "./dist/index.js";
23044
23065
  var bin = "./dist/index.js";