fumadocs-openapi 10.8.4 → 10.8.6
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/css/generated/shared.css +22 -1
- package/dist/generate-file.d.ts +1 -1
- package/dist/generate-file.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/general/create-limiter.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/is-object.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/queue/queue.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/string/generate-hash.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/bundle.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +1 -1
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.14/node_modules/@scalar/json-magic/dist/helpers/normalize.js +33 -0
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +110 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/code.js +138 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +674 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/scope.js +141 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/errors.js +102 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +223 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/names.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/ref_error.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +133 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +146 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/applicability.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +172 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/defaults.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +433 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +113 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +583 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/data.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/index.js +42 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.js +50 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.js +36 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.js +85 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/schema.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/equal.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js +25 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/uri.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/validation_error.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +57 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +96 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +29 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +89 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +87 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/if.js +62 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +60 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +34 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/not.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +52 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +41 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/code.js +130 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/id.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +112 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +101 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/draft2020.js +35 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js +45 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js +15 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/index.js +10 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/metadata.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/next.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/index.js +13 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/const.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/enum.js +49 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/index.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitContains.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +33 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +47 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +38 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +70 -0
- package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +33 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +236 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +187 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +282 -0
- package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +78 -0
- package/dist/playground/client.js +1 -1
- package/dist/playground/schema.d.ts +0 -2
- package/dist/playground/schema.js +3 -2
- package/dist/server/index.d.ts +108 -3
- package/dist/server/index.js +181 -2
- package/dist/server/proxy.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/ui/base.d.ts +1 -1
- package/dist/ui/components/method-label.js +1 -4
- package/dist/ui/index.d.ts +1 -1
- package/dist/utils/document/process.js +4 -4
- package/dist/utils/pages/builder.d.ts +4 -3
- package/dist/utils/pages/builder.js +20 -1
- package/dist/utils/pages/to-text.d.ts +1 -1
- package/dist/utils/pages/to-text.js +23 -42
- package/package.json +12 -8
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.12/node_modules/@scalar/json-magic/dist/helpers/normalize.js +0 -26
- package/dist/server/create.d.ts +0 -40
- package/dist/server/create.js +0 -42
- package/dist/server/source-api.d.ts +0 -55
- package/dist/server/source-api.js +0 -149
- /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +0 -0
- /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +0 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../../../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { require_code } from "./code.js";
|
|
3
|
+
import { require_scope } from "./scope.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js
|
|
5
|
+
var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.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;
|
|
8
|
+
const code_1 = require_code();
|
|
9
|
+
const scope_1 = require_scope();
|
|
10
|
+
var code_2 = require_code();
|
|
11
|
+
Object.defineProperty(exports, "_", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return code_2._;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "str", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return code_2.str;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "strConcat", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return code_2.strConcat;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "nil", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return code_2.nil;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "getProperty", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function() {
|
|
38
|
+
return code_2.getProperty;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "stringify", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function() {
|
|
44
|
+
return code_2.stringify;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "regexpCode", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function() {
|
|
50
|
+
return code_2.regexpCode;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "Name", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function() {
|
|
56
|
+
return code_2.Name;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var scope_2 = require_scope();
|
|
60
|
+
Object.defineProperty(exports, "Scope", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return scope_2.Scope;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "ValueScope", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function() {
|
|
69
|
+
return scope_2.ValueScope;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "ValueScopeName", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function() {
|
|
75
|
+
return scope_2.ValueScopeName;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "varKinds", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function() {
|
|
81
|
+
return scope_2.varKinds;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
exports.operators = {
|
|
85
|
+
GT: new code_1._Code(">"),
|
|
86
|
+
GTE: new code_1._Code(">="),
|
|
87
|
+
LT: new code_1._Code("<"),
|
|
88
|
+
LTE: new code_1._Code("<="),
|
|
89
|
+
EQ: new code_1._Code("==="),
|
|
90
|
+
NEQ: new code_1._Code("!=="),
|
|
91
|
+
NOT: new code_1._Code("!"),
|
|
92
|
+
OR: new code_1._Code("||"),
|
|
93
|
+
AND: new code_1._Code("&&"),
|
|
94
|
+
ADD: new code_1._Code("+")
|
|
95
|
+
};
|
|
96
|
+
var Node = class {
|
|
97
|
+
optimizeNodes() {
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
optimizeNames(_names, _constants) {
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var Def = class extends Node {
|
|
105
|
+
constructor(varKind, name, rhs) {
|
|
106
|
+
super();
|
|
107
|
+
this.varKind = varKind;
|
|
108
|
+
this.name = name;
|
|
109
|
+
this.rhs = rhs;
|
|
110
|
+
}
|
|
111
|
+
render({ es5, _n }) {
|
|
112
|
+
const varKind = es5 ? scope_1.varKinds.var : this.varKind;
|
|
113
|
+
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
114
|
+
return `${varKind} ${this.name}${rhs};` + _n;
|
|
115
|
+
}
|
|
116
|
+
optimizeNames(names, constants) {
|
|
117
|
+
if (!names[this.name.str]) return;
|
|
118
|
+
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
get names() {
|
|
122
|
+
return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var Assign = class extends Node {
|
|
126
|
+
constructor(lhs, rhs, sideEffects) {
|
|
127
|
+
super();
|
|
128
|
+
this.lhs = lhs;
|
|
129
|
+
this.rhs = rhs;
|
|
130
|
+
this.sideEffects = sideEffects;
|
|
131
|
+
}
|
|
132
|
+
render({ _n }) {
|
|
133
|
+
return `${this.lhs} = ${this.rhs};` + _n;
|
|
134
|
+
}
|
|
135
|
+
optimizeNames(names, constants) {
|
|
136
|
+
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects) return;
|
|
137
|
+
this.rhs = optimizeExpr(this.rhs, names, constants);
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
get names() {
|
|
141
|
+
return addExprNames(this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names }, this.rhs);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var AssignOp = class extends Assign {
|
|
145
|
+
constructor(lhs, op, rhs, sideEffects) {
|
|
146
|
+
super(lhs, rhs, sideEffects);
|
|
147
|
+
this.op = op;
|
|
148
|
+
}
|
|
149
|
+
render({ _n }) {
|
|
150
|
+
return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var Label = class extends Node {
|
|
154
|
+
constructor(label) {
|
|
155
|
+
super();
|
|
156
|
+
this.label = label;
|
|
157
|
+
this.names = {};
|
|
158
|
+
}
|
|
159
|
+
render({ _n }) {
|
|
160
|
+
return `${this.label}:` + _n;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var Break = class extends Node {
|
|
164
|
+
constructor(label) {
|
|
165
|
+
super();
|
|
166
|
+
this.label = label;
|
|
167
|
+
this.names = {};
|
|
168
|
+
}
|
|
169
|
+
render({ _n }) {
|
|
170
|
+
return `break${this.label ? ` ${this.label}` : ""};` + _n;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var Throw = class extends Node {
|
|
174
|
+
constructor(error) {
|
|
175
|
+
super();
|
|
176
|
+
this.error = error;
|
|
177
|
+
}
|
|
178
|
+
render({ _n }) {
|
|
179
|
+
return `throw ${this.error};` + _n;
|
|
180
|
+
}
|
|
181
|
+
get names() {
|
|
182
|
+
return this.error.names;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var AnyCode = class extends Node {
|
|
186
|
+
constructor(code) {
|
|
187
|
+
super();
|
|
188
|
+
this.code = code;
|
|
189
|
+
}
|
|
190
|
+
render({ _n }) {
|
|
191
|
+
return `${this.code};` + _n;
|
|
192
|
+
}
|
|
193
|
+
optimizeNodes() {
|
|
194
|
+
return `${this.code}` ? this : void 0;
|
|
195
|
+
}
|
|
196
|
+
optimizeNames(names, constants) {
|
|
197
|
+
this.code = optimizeExpr(this.code, names, constants);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
get names() {
|
|
201
|
+
return this.code instanceof code_1._CodeOrName ? this.code.names : {};
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var ParentNode = class extends Node {
|
|
205
|
+
constructor(nodes = []) {
|
|
206
|
+
super();
|
|
207
|
+
this.nodes = nodes;
|
|
208
|
+
}
|
|
209
|
+
render(opts) {
|
|
210
|
+
return this.nodes.reduce((code, n) => code + n.render(opts), "");
|
|
211
|
+
}
|
|
212
|
+
optimizeNodes() {
|
|
213
|
+
const { nodes } = this;
|
|
214
|
+
let i = nodes.length;
|
|
215
|
+
while (i--) {
|
|
216
|
+
const n = nodes[i].optimizeNodes();
|
|
217
|
+
if (Array.isArray(n)) nodes.splice(i, 1, ...n);
|
|
218
|
+
else if (n) nodes[i] = n;
|
|
219
|
+
else nodes.splice(i, 1);
|
|
220
|
+
}
|
|
221
|
+
return nodes.length > 0 ? this : void 0;
|
|
222
|
+
}
|
|
223
|
+
optimizeNames(names, constants) {
|
|
224
|
+
const { nodes } = this;
|
|
225
|
+
let i = nodes.length;
|
|
226
|
+
while (i--) {
|
|
227
|
+
const n = nodes[i];
|
|
228
|
+
if (n.optimizeNames(names, constants)) continue;
|
|
229
|
+
subtractNames(names, n.names);
|
|
230
|
+
nodes.splice(i, 1);
|
|
231
|
+
}
|
|
232
|
+
return nodes.length > 0 ? this : void 0;
|
|
233
|
+
}
|
|
234
|
+
get names() {
|
|
235
|
+
return this.nodes.reduce((names, n) => addNames(names, n.names), {});
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var BlockNode = class extends ParentNode {
|
|
239
|
+
render(opts) {
|
|
240
|
+
return "{" + opts._n + super.render(opts) + "}" + opts._n;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var Root = class extends ParentNode {};
|
|
244
|
+
var Else = class extends BlockNode {};
|
|
245
|
+
Else.kind = "else";
|
|
246
|
+
var If = class If extends BlockNode {
|
|
247
|
+
constructor(condition, nodes) {
|
|
248
|
+
super(nodes);
|
|
249
|
+
this.condition = condition;
|
|
250
|
+
}
|
|
251
|
+
render(opts) {
|
|
252
|
+
let code = `if(${this.condition})` + super.render(opts);
|
|
253
|
+
if (this.else) code += "else " + this.else.render(opts);
|
|
254
|
+
return code;
|
|
255
|
+
}
|
|
256
|
+
optimizeNodes() {
|
|
257
|
+
super.optimizeNodes();
|
|
258
|
+
const cond = this.condition;
|
|
259
|
+
if (cond === true) return this.nodes;
|
|
260
|
+
let e = this.else;
|
|
261
|
+
if (e) {
|
|
262
|
+
const ns = e.optimizeNodes();
|
|
263
|
+
e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
|
|
264
|
+
}
|
|
265
|
+
if (e) {
|
|
266
|
+
if (cond === false) return e instanceof If ? e : e.nodes;
|
|
267
|
+
if (this.nodes.length) return this;
|
|
268
|
+
return new If(not(cond), e instanceof If ? [e] : e.nodes);
|
|
269
|
+
}
|
|
270
|
+
if (cond === false || !this.nodes.length) return void 0;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
optimizeNames(names, constants) {
|
|
274
|
+
var _a;
|
|
275
|
+
this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
|
|
276
|
+
if (!(super.optimizeNames(names, constants) || this.else)) return;
|
|
277
|
+
this.condition = optimizeExpr(this.condition, names, constants);
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
get names() {
|
|
281
|
+
const names = super.names;
|
|
282
|
+
addExprNames(names, this.condition);
|
|
283
|
+
if (this.else) addNames(names, this.else.names);
|
|
284
|
+
return names;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
If.kind = "if";
|
|
288
|
+
var For = class extends BlockNode {};
|
|
289
|
+
For.kind = "for";
|
|
290
|
+
var ForLoop = class extends For {
|
|
291
|
+
constructor(iteration) {
|
|
292
|
+
super();
|
|
293
|
+
this.iteration = iteration;
|
|
294
|
+
}
|
|
295
|
+
render(opts) {
|
|
296
|
+
return `for(${this.iteration})` + super.render(opts);
|
|
297
|
+
}
|
|
298
|
+
optimizeNames(names, constants) {
|
|
299
|
+
if (!super.optimizeNames(names, constants)) return;
|
|
300
|
+
this.iteration = optimizeExpr(this.iteration, names, constants);
|
|
301
|
+
return this;
|
|
302
|
+
}
|
|
303
|
+
get names() {
|
|
304
|
+
return addNames(super.names, this.iteration.names);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var ForRange = class extends For {
|
|
308
|
+
constructor(varKind, name, from, to) {
|
|
309
|
+
super();
|
|
310
|
+
this.varKind = varKind;
|
|
311
|
+
this.name = name;
|
|
312
|
+
this.from = from;
|
|
313
|
+
this.to = to;
|
|
314
|
+
}
|
|
315
|
+
render(opts) {
|
|
316
|
+
const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
|
|
317
|
+
const { name, from, to } = this;
|
|
318
|
+
return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
|
|
319
|
+
}
|
|
320
|
+
get names() {
|
|
321
|
+
return addExprNames(addExprNames(super.names, this.from), this.to);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
var ForIter = class extends For {
|
|
325
|
+
constructor(loop, varKind, name, iterable) {
|
|
326
|
+
super();
|
|
327
|
+
this.loop = loop;
|
|
328
|
+
this.varKind = varKind;
|
|
329
|
+
this.name = name;
|
|
330
|
+
this.iterable = iterable;
|
|
331
|
+
}
|
|
332
|
+
render(opts) {
|
|
333
|
+
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
334
|
+
}
|
|
335
|
+
optimizeNames(names, constants) {
|
|
336
|
+
if (!super.optimizeNames(names, constants)) return;
|
|
337
|
+
this.iterable = optimizeExpr(this.iterable, names, constants);
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
get names() {
|
|
341
|
+
return addNames(super.names, this.iterable.names);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
var Func = class extends BlockNode {
|
|
345
|
+
constructor(name, args, async) {
|
|
346
|
+
super();
|
|
347
|
+
this.name = name;
|
|
348
|
+
this.args = args;
|
|
349
|
+
this.async = async;
|
|
350
|
+
}
|
|
351
|
+
render(opts) {
|
|
352
|
+
return `${this.async ? "async " : ""}function ${this.name}(${this.args})` + super.render(opts);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
Func.kind = "func";
|
|
356
|
+
var Return = class extends ParentNode {
|
|
357
|
+
render(opts) {
|
|
358
|
+
return "return " + super.render(opts);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
Return.kind = "return";
|
|
362
|
+
var Try = class extends BlockNode {
|
|
363
|
+
render(opts) {
|
|
364
|
+
let code = "try" + super.render(opts);
|
|
365
|
+
if (this.catch) code += this.catch.render(opts);
|
|
366
|
+
if (this.finally) code += this.finally.render(opts);
|
|
367
|
+
return code;
|
|
368
|
+
}
|
|
369
|
+
optimizeNodes() {
|
|
370
|
+
var _a, _b;
|
|
371
|
+
super.optimizeNodes();
|
|
372
|
+
(_a = this.catch) === null || _a === void 0 || _a.optimizeNodes();
|
|
373
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNodes();
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
optimizeNames(names, constants) {
|
|
377
|
+
var _a, _b;
|
|
378
|
+
super.optimizeNames(names, constants);
|
|
379
|
+
(_a = this.catch) === null || _a === void 0 || _a.optimizeNames(names, constants);
|
|
380
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants);
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
get names() {
|
|
384
|
+
const names = super.names;
|
|
385
|
+
if (this.catch) addNames(names, this.catch.names);
|
|
386
|
+
if (this.finally) addNames(names, this.finally.names);
|
|
387
|
+
return names;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var Catch = class extends BlockNode {
|
|
391
|
+
constructor(error) {
|
|
392
|
+
super();
|
|
393
|
+
this.error = error;
|
|
394
|
+
}
|
|
395
|
+
render(opts) {
|
|
396
|
+
return `catch(${this.error})` + super.render(opts);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
Catch.kind = "catch";
|
|
400
|
+
var Finally = class extends BlockNode {
|
|
401
|
+
render(opts) {
|
|
402
|
+
return "finally" + super.render(opts);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
Finally.kind = "finally";
|
|
406
|
+
var CodeGen = class {
|
|
407
|
+
constructor(extScope, opts = {}) {
|
|
408
|
+
this._values = {};
|
|
409
|
+
this._blockStarts = [];
|
|
410
|
+
this._constants = {};
|
|
411
|
+
this.opts = {
|
|
412
|
+
...opts,
|
|
413
|
+
_n: opts.lines ? "\n" : ""
|
|
414
|
+
};
|
|
415
|
+
this._extScope = extScope;
|
|
416
|
+
this._scope = new scope_1.Scope({ parent: extScope });
|
|
417
|
+
this._nodes = [new Root()];
|
|
418
|
+
}
|
|
419
|
+
toString() {
|
|
420
|
+
return this._root.render(this.opts);
|
|
421
|
+
}
|
|
422
|
+
name(prefix) {
|
|
423
|
+
return this._scope.name(prefix);
|
|
424
|
+
}
|
|
425
|
+
scopeName(prefix) {
|
|
426
|
+
return this._extScope.name(prefix);
|
|
427
|
+
}
|
|
428
|
+
scopeValue(prefixOrName, value) {
|
|
429
|
+
const name = this._extScope.value(prefixOrName, value);
|
|
430
|
+
(this._values[name.prefix] || (this._values[name.prefix] = /* @__PURE__ */ new Set())).add(name);
|
|
431
|
+
return name;
|
|
432
|
+
}
|
|
433
|
+
getScopeValue(prefix, keyOrRef) {
|
|
434
|
+
return this._extScope.getValue(prefix, keyOrRef);
|
|
435
|
+
}
|
|
436
|
+
scopeRefs(scopeName) {
|
|
437
|
+
return this._extScope.scopeRefs(scopeName, this._values);
|
|
438
|
+
}
|
|
439
|
+
scopeCode() {
|
|
440
|
+
return this._extScope.scopeCode(this._values);
|
|
441
|
+
}
|
|
442
|
+
_def(varKind, nameOrPrefix, rhs, constant) {
|
|
443
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
444
|
+
if (rhs !== void 0 && constant) this._constants[name.str] = rhs;
|
|
445
|
+
this._leafNode(new Def(varKind, name, rhs));
|
|
446
|
+
return name;
|
|
447
|
+
}
|
|
448
|
+
const(nameOrPrefix, rhs, _constant) {
|
|
449
|
+
return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
|
|
450
|
+
}
|
|
451
|
+
let(nameOrPrefix, rhs, _constant) {
|
|
452
|
+
return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
|
|
453
|
+
}
|
|
454
|
+
var(nameOrPrefix, rhs, _constant) {
|
|
455
|
+
return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
|
|
456
|
+
}
|
|
457
|
+
assign(lhs, rhs, sideEffects) {
|
|
458
|
+
return this._leafNode(new Assign(lhs, rhs, sideEffects));
|
|
459
|
+
}
|
|
460
|
+
add(lhs, rhs) {
|
|
461
|
+
return this._leafNode(new AssignOp(lhs, exports.operators.ADD, rhs));
|
|
462
|
+
}
|
|
463
|
+
code(c) {
|
|
464
|
+
if (typeof c == "function") c();
|
|
465
|
+
else if (c !== code_1.nil) this._leafNode(new AnyCode(c));
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
object(...keyValues) {
|
|
469
|
+
const code = ["{"];
|
|
470
|
+
for (const [key, value] of keyValues) {
|
|
471
|
+
if (code.length > 1) code.push(",");
|
|
472
|
+
code.push(key);
|
|
473
|
+
if (key !== value || this.opts.es5) {
|
|
474
|
+
code.push(":");
|
|
475
|
+
(0, code_1.addCodeArg)(code, value);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
code.push("}");
|
|
479
|
+
return new code_1._Code(code);
|
|
480
|
+
}
|
|
481
|
+
if(condition, thenBody, elseBody) {
|
|
482
|
+
this._blockNode(new If(condition));
|
|
483
|
+
if (thenBody && elseBody) this.code(thenBody).else().code(elseBody).endIf();
|
|
484
|
+
else if (thenBody) this.code(thenBody).endIf();
|
|
485
|
+
else if (elseBody) throw new Error("CodeGen: \"else\" body without \"then\" body");
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
elseIf(condition) {
|
|
489
|
+
return this._elseNode(new If(condition));
|
|
490
|
+
}
|
|
491
|
+
else() {
|
|
492
|
+
return this._elseNode(new Else());
|
|
493
|
+
}
|
|
494
|
+
endIf() {
|
|
495
|
+
return this._endBlockNode(If, Else);
|
|
496
|
+
}
|
|
497
|
+
_for(node, forBody) {
|
|
498
|
+
this._blockNode(node);
|
|
499
|
+
if (forBody) this.code(forBody).endFor();
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
for(iteration, forBody) {
|
|
503
|
+
return this._for(new ForLoop(iteration), forBody);
|
|
504
|
+
}
|
|
505
|
+
forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
|
|
506
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
507
|
+
return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
|
|
508
|
+
}
|
|
509
|
+
forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
|
|
510
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
511
|
+
if (this.opts.es5) {
|
|
512
|
+
const arr = iterable instanceof code_1.Name ? iterable : this.var("_arr", iterable);
|
|
513
|
+
return this.forRange("_i", 0, (0, code_1._)`${arr}.length`, (i) => {
|
|
514
|
+
this.var(name, (0, code_1._)`${arr}[${i}]`);
|
|
515
|
+
forBody(name);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
519
|
+
}
|
|
520
|
+
forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
521
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj})`, forBody);
|
|
522
|
+
const name = this._scope.toName(nameOrPrefix);
|
|
523
|
+
return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
|
|
524
|
+
}
|
|
525
|
+
endFor() {
|
|
526
|
+
return this._endBlockNode(For);
|
|
527
|
+
}
|
|
528
|
+
label(label) {
|
|
529
|
+
return this._leafNode(new Label(label));
|
|
530
|
+
}
|
|
531
|
+
break(label) {
|
|
532
|
+
return this._leafNode(new Break(label));
|
|
533
|
+
}
|
|
534
|
+
return(value) {
|
|
535
|
+
const node = new Return();
|
|
536
|
+
this._blockNode(node);
|
|
537
|
+
this.code(value);
|
|
538
|
+
if (node.nodes.length !== 1) throw new Error("CodeGen: \"return\" should have one node");
|
|
539
|
+
return this._endBlockNode(Return);
|
|
540
|
+
}
|
|
541
|
+
try(tryBody, catchCode, finallyCode) {
|
|
542
|
+
if (!catchCode && !finallyCode) throw new Error("CodeGen: \"try\" without \"catch\" and \"finally\"");
|
|
543
|
+
const node = new Try();
|
|
544
|
+
this._blockNode(node);
|
|
545
|
+
this.code(tryBody);
|
|
546
|
+
if (catchCode) {
|
|
547
|
+
const error = this.name("e");
|
|
548
|
+
this._currNode = node.catch = new Catch(error);
|
|
549
|
+
catchCode(error);
|
|
550
|
+
}
|
|
551
|
+
if (finallyCode) {
|
|
552
|
+
this._currNode = node.finally = new Finally();
|
|
553
|
+
this.code(finallyCode);
|
|
554
|
+
}
|
|
555
|
+
return this._endBlockNode(Catch, Finally);
|
|
556
|
+
}
|
|
557
|
+
throw(error) {
|
|
558
|
+
return this._leafNode(new Throw(error));
|
|
559
|
+
}
|
|
560
|
+
block(body, nodeCount) {
|
|
561
|
+
this._blockStarts.push(this._nodes.length);
|
|
562
|
+
if (body) this.code(body).endBlock(nodeCount);
|
|
563
|
+
return this;
|
|
564
|
+
}
|
|
565
|
+
endBlock(nodeCount) {
|
|
566
|
+
const len = this._blockStarts.pop();
|
|
567
|
+
if (len === void 0) throw new Error("CodeGen: not in self-balancing block");
|
|
568
|
+
const toClose = this._nodes.length - len;
|
|
569
|
+
if (toClose < 0 || nodeCount !== void 0 && toClose !== nodeCount) throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);
|
|
570
|
+
this._nodes.length = len;
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
573
|
+
func(name, args = code_1.nil, async, funcBody) {
|
|
574
|
+
this._blockNode(new Func(name, args, async));
|
|
575
|
+
if (funcBody) this.code(funcBody).endFunc();
|
|
576
|
+
return this;
|
|
577
|
+
}
|
|
578
|
+
endFunc() {
|
|
579
|
+
return this._endBlockNode(Func);
|
|
580
|
+
}
|
|
581
|
+
optimize(n = 1) {
|
|
582
|
+
while (n-- > 0) {
|
|
583
|
+
this._root.optimizeNodes();
|
|
584
|
+
this._root.optimizeNames(this._root.names, this._constants);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
_leafNode(node) {
|
|
588
|
+
this._currNode.nodes.push(node);
|
|
589
|
+
return this;
|
|
590
|
+
}
|
|
591
|
+
_blockNode(node) {
|
|
592
|
+
this._currNode.nodes.push(node);
|
|
593
|
+
this._nodes.push(node);
|
|
594
|
+
}
|
|
595
|
+
_endBlockNode(N1, N2) {
|
|
596
|
+
const n = this._currNode;
|
|
597
|
+
if (n instanceof N1 || N2 && n instanceof N2) {
|
|
598
|
+
this._nodes.pop();
|
|
599
|
+
return this;
|
|
600
|
+
}
|
|
601
|
+
throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
|
|
602
|
+
}
|
|
603
|
+
_elseNode(node) {
|
|
604
|
+
const n = this._currNode;
|
|
605
|
+
if (!(n instanceof If)) throw new Error("CodeGen: \"else\" without \"if\"");
|
|
606
|
+
this._currNode = n.else = node;
|
|
607
|
+
return this;
|
|
608
|
+
}
|
|
609
|
+
get _root() {
|
|
610
|
+
return this._nodes[0];
|
|
611
|
+
}
|
|
612
|
+
get _currNode() {
|
|
613
|
+
const ns = this._nodes;
|
|
614
|
+
return ns[ns.length - 1];
|
|
615
|
+
}
|
|
616
|
+
set _currNode(node) {
|
|
617
|
+
const ns = this._nodes;
|
|
618
|
+
ns[ns.length - 1] = node;
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
exports.CodeGen = CodeGen;
|
|
622
|
+
function addNames(names, from) {
|
|
623
|
+
for (const n in from) names[n] = (names[n] || 0) + (from[n] || 0);
|
|
624
|
+
return names;
|
|
625
|
+
}
|
|
626
|
+
function addExprNames(names, from) {
|
|
627
|
+
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
628
|
+
}
|
|
629
|
+
function optimizeExpr(expr, names, constants) {
|
|
630
|
+
if (expr instanceof code_1.Name) return replaceName(expr);
|
|
631
|
+
if (!canOptimize(expr)) return expr;
|
|
632
|
+
return new code_1._Code(expr._items.reduce((items, c) => {
|
|
633
|
+
if (c instanceof code_1.Name) c = replaceName(c);
|
|
634
|
+
if (c instanceof code_1._Code) items.push(...c._items);
|
|
635
|
+
else items.push(c);
|
|
636
|
+
return items;
|
|
637
|
+
}, []));
|
|
638
|
+
function replaceName(n) {
|
|
639
|
+
const c = constants[n.str];
|
|
640
|
+
if (c === void 0 || names[n.str] !== 1) return n;
|
|
641
|
+
delete names[n.str];
|
|
642
|
+
return c;
|
|
643
|
+
}
|
|
644
|
+
function canOptimize(e) {
|
|
645
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== void 0);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function subtractNames(names, from) {
|
|
649
|
+
for (const n in from) names[n] = (names[n] || 0) - (from[n] || 0);
|
|
650
|
+
}
|
|
651
|
+
function not(x) {
|
|
652
|
+
return typeof x == "boolean" || typeof x == "number" || x === null ? !x : (0, code_1._)`!${par(x)}`;
|
|
653
|
+
}
|
|
654
|
+
exports.not = not;
|
|
655
|
+
const andCode = mappend(exports.operators.AND);
|
|
656
|
+
function and(...args) {
|
|
657
|
+
return args.reduce(andCode);
|
|
658
|
+
}
|
|
659
|
+
exports.and = and;
|
|
660
|
+
const orCode = mappend(exports.operators.OR);
|
|
661
|
+
function or(...args) {
|
|
662
|
+
return args.reduce(orCode);
|
|
663
|
+
}
|
|
664
|
+
exports.or = or;
|
|
665
|
+
function mappend(op) {
|
|
666
|
+
return (x, y) => x === code_1.nil ? y : y === code_1.nil ? x : (0, code_1._)`${par(x)} ${op} ${par(y)}`;
|
|
667
|
+
}
|
|
668
|
+
function par(x) {
|
|
669
|
+
return x instanceof code_1.Name ? x : (0, code_1._)`(${x})`;
|
|
670
|
+
}
|
|
671
|
+
}));
|
|
672
|
+
//#endregion
|
|
673
|
+
export default require_codegen();
|
|
674
|
+
export { require_codegen };
|