elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/compile/lexer.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/compile/lexer.ts
|
|
4
|
-
const isSpace = (ch) => ch === " " || ch === "\n" || ch === " " || ch === "\r";
|
|
5
|
-
const isIdentChar = (ch) => ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_" || ch === "$";
|
|
6
|
-
const isIdentCharCode = (code) => code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95 || code === 36;
|
|
7
4
|
function skipString(src, start) {
|
|
8
5
|
const quote = src[start];
|
|
9
6
|
let i = start + 1;
|
|
@@ -45,9 +42,274 @@ function skipString(src, start) {
|
|
|
45
42
|
}
|
|
46
43
|
return i;
|
|
47
44
|
}
|
|
45
|
+
const prefixKeywords = new Set([
|
|
46
|
+
"await",
|
|
47
|
+
"case",
|
|
48
|
+
"delete",
|
|
49
|
+
"do",
|
|
50
|
+
"else",
|
|
51
|
+
"in",
|
|
52
|
+
"instanceof",
|
|
53
|
+
"new",
|
|
54
|
+
"of",
|
|
55
|
+
"return",
|
|
56
|
+
"throw",
|
|
57
|
+
"typeof",
|
|
58
|
+
"void",
|
|
59
|
+
"yield"
|
|
60
|
+
]);
|
|
61
|
+
const isSpace = (char) => char === 32 || char >= 9 && char <= 13 || char >= 128 && /\s/.test(String.fromCharCode(char));
|
|
62
|
+
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128 && !isSpace(char);
|
|
63
|
+
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
64
|
+
function isHeader(tokens) {
|
|
65
|
+
let keyword = tokens.length - 1;
|
|
66
|
+
if (keyword > 0 && tokens[keyword].value === "await" && tokens[keyword - 1].value === "for") keyword--;
|
|
67
|
+
if (keyword < 0) return false;
|
|
68
|
+
const { k, value: v } = tokens[keyword];
|
|
69
|
+
if (k !== "i" || v !== "if" && v !== "while" && v !== "for" && v !== "with") return false;
|
|
70
|
+
if (keyword === 0) return true;
|
|
71
|
+
const before = tokens[keyword - 1];
|
|
72
|
+
return !(before.k === "p" && (before.value === "." || before.value === "?." || before.value === "#"));
|
|
73
|
+
}
|
|
74
|
+
function scanTokens(source) {
|
|
75
|
+
const tokens = [];
|
|
76
|
+
let index = 0;
|
|
77
|
+
let canEndExpression = false;
|
|
78
|
+
const headers = [];
|
|
79
|
+
const skipUnicodeEscape = () => {
|
|
80
|
+
index += 2;
|
|
81
|
+
if (source.charCodeAt(index) === 123) {
|
|
82
|
+
const end = source.indexOf("}", index + 1);
|
|
83
|
+
if (end === -1) return false;
|
|
84
|
+
index = end + 1;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
for (let digit = 0; digit < 4; digit++) {
|
|
88
|
+
const hex = source.charCodeAt(index + digit);
|
|
89
|
+
if (!(hex >= 48 && hex <= 57 || hex >= 65 && hex <= 70 || hex >= 97 && hex <= 102)) return false;
|
|
90
|
+
}
|
|
91
|
+
index += 4;
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
const scanCode = (templateExpression = false) => {
|
|
95
|
+
let templateDepth = 0;
|
|
96
|
+
while (index < source.length) {
|
|
97
|
+
const char = source.charCodeAt(index);
|
|
98
|
+
if (isSpace(char)) {
|
|
99
|
+
index++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === 92 && source.charCodeAt(index + 1) !== 117) return false;
|
|
103
|
+
if (char === 47) {
|
|
104
|
+
const next = source.charCodeAt(index + 1);
|
|
105
|
+
if (next === 47) {
|
|
106
|
+
index += 2;
|
|
107
|
+
while (index < source.length && source.charCodeAt(index) !== 10 && source.charCodeAt(index) !== 13 && source.charCodeAt(index) !== 8232 && source.charCodeAt(index) !== 8233) index++;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (next === 42) {
|
|
111
|
+
index += 2;
|
|
112
|
+
while (index + 1 < source.length && !(source.charCodeAt(index) === 42 && source.charCodeAt(index + 1) === 47)) index++;
|
|
113
|
+
if (index + 1 >= source.length) return false;
|
|
114
|
+
index += 2;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!canEndExpression) {
|
|
118
|
+
const previous = tokens.length ? tokens[tokens.length - 1] : void 0;
|
|
119
|
+
if (previous?.k === "i" && (previous.value === "of" || previous.value === "await" || previous.value === "yield")) return false;
|
|
120
|
+
index++;
|
|
121
|
+
let escaped = false;
|
|
122
|
+
let characterClass = false;
|
|
123
|
+
let closed = false;
|
|
124
|
+
while (index < source.length) {
|
|
125
|
+
const regexChar = source.charCodeAt(index++);
|
|
126
|
+
if (escaped) {
|
|
127
|
+
escaped = false;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (regexChar === 92) {
|
|
131
|
+
escaped = true;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (regexChar === 91) characterClass = true;
|
|
135
|
+
else if (regexChar === 93) characterClass = false;
|
|
136
|
+
else if (regexChar === 47 && !characterClass) {
|
|
137
|
+
closed = true;
|
|
138
|
+
break;
|
|
139
|
+
} else if (regexChar === 10 || regexChar === 13) return false;
|
|
140
|
+
}
|
|
141
|
+
if (!closed) return false;
|
|
142
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
143
|
+
canEndExpression = true;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const previous = tokens.length ? tokens[tokens.length - 1] : void 0;
|
|
147
|
+
if (previous?.k === "p" && previous.value === "}") return false;
|
|
148
|
+
tokens.push({
|
|
149
|
+
k: "p",
|
|
150
|
+
value: "/",
|
|
151
|
+
at: index
|
|
152
|
+
});
|
|
153
|
+
index++;
|
|
154
|
+
canEndExpression = false;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (char === 34 || char === 39) {
|
|
158
|
+
const quote = char;
|
|
159
|
+
const start = ++index;
|
|
160
|
+
let escaped = false;
|
|
161
|
+
while (index < source.length) {
|
|
162
|
+
const stringChar = source.charCodeAt(index);
|
|
163
|
+
if (escaped) escaped = false;
|
|
164
|
+
else if (stringChar === 92) escaped = true;
|
|
165
|
+
else if (stringChar === quote) break;
|
|
166
|
+
else if (stringChar === 10 || stringChar === 13) return false;
|
|
167
|
+
index++;
|
|
168
|
+
}
|
|
169
|
+
if (index >= source.length) return false;
|
|
170
|
+
tokens.push({
|
|
171
|
+
k: "s",
|
|
172
|
+
value: source.slice(start, index),
|
|
173
|
+
at: start - 1
|
|
174
|
+
});
|
|
175
|
+
index++;
|
|
176
|
+
canEndExpression = true;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (char === 96) {
|
|
180
|
+
index++;
|
|
181
|
+
let closed = false;
|
|
182
|
+
while (index < source.length) {
|
|
183
|
+
const templateChar = source.charCodeAt(index);
|
|
184
|
+
if (templateChar === 92) {
|
|
185
|
+
index += 2;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (templateChar === 96) {
|
|
189
|
+
index++;
|
|
190
|
+
closed = true;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
if (templateChar === 36 && source.charCodeAt(index + 1) === 123) {
|
|
194
|
+
index += 2;
|
|
195
|
+
canEndExpression = false;
|
|
196
|
+
if (!scanCode(true)) return false;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
index++;
|
|
200
|
+
}
|
|
201
|
+
if (!closed) return false;
|
|
202
|
+
canEndExpression = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (isIdentifierStart(char) || char === 92 && source.charCodeAt(index + 1) === 117) {
|
|
206
|
+
const start = index;
|
|
207
|
+
if (char === 92) {
|
|
208
|
+
if (!skipUnicodeEscape()) return false;
|
|
209
|
+
} else index++;
|
|
210
|
+
while (index < source.length) {
|
|
211
|
+
const identifierChar = source.charCodeAt(index);
|
|
212
|
+
if (isIdentifierPart(identifierChar)) {
|
|
213
|
+
index++;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (identifierChar === 92 && source.charCodeAt(index + 1) === 117) {
|
|
217
|
+
if (!skipUnicodeEscape()) return false;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
const identifierText = source.slice(start, index);
|
|
223
|
+
let value;
|
|
224
|
+
if (!identifierText.includes("\\u")) value = identifierText;
|
|
225
|
+
else {
|
|
226
|
+
let decoded = "";
|
|
227
|
+
let failed = false;
|
|
228
|
+
for (let i = 0; i < identifierText.length; i++) {
|
|
229
|
+
if (identifierText.charCodeAt(i) !== 92 || identifierText.charCodeAt(i + 1) !== 117) {
|
|
230
|
+
decoded += identifierText[i];
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
i += 2;
|
|
234
|
+
let hex;
|
|
235
|
+
if (identifierText.charCodeAt(i) === 123) {
|
|
236
|
+
const end = identifierText.indexOf("}", i + 1);
|
|
237
|
+
if (end === -1) {
|
|
238
|
+
failed = true;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
hex = identifierText.slice(i + 1, end);
|
|
242
|
+
i = end;
|
|
243
|
+
} else {
|
|
244
|
+
hex = identifierText.slice(i, i + 4);
|
|
245
|
+
if (hex.length !== 4) {
|
|
246
|
+
failed = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
i += 3;
|
|
250
|
+
}
|
|
251
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
252
|
+
if (!Number.isFinite(codePoint) || codePoint > 1114111) {
|
|
253
|
+
failed = true;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
decoded += String.fromCodePoint(codePoint);
|
|
257
|
+
}
|
|
258
|
+
value = failed ? void 0 : decoded;
|
|
259
|
+
}
|
|
260
|
+
if (value === void 0) return false;
|
|
261
|
+
canEndExpression = !prefixKeywords.has(value);
|
|
262
|
+
if (!canEndExpression && tokens.length) {
|
|
263
|
+
const previous = tokens[tokens.length - 1];
|
|
264
|
+
canEndExpression = previous.k === "p" && (previous.value === "." || previous.value === "?." || previous.value === "#");
|
|
265
|
+
}
|
|
266
|
+
tokens.push({
|
|
267
|
+
k: "i",
|
|
268
|
+
value,
|
|
269
|
+
at: start
|
|
270
|
+
});
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const leadingDot = char === 46 && source.charCodeAt(index + 1) >= 48 && source.charCodeAt(index + 1) <= 57;
|
|
274
|
+
if (char >= 48 && char <= 57 || leadingDot) {
|
|
275
|
+
index++;
|
|
276
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
277
|
+
if (!leadingDot && source.charCodeAt(index) === 46) {
|
|
278
|
+
index++;
|
|
279
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
280
|
+
}
|
|
281
|
+
canEndExpression = true;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (templateExpression) {
|
|
285
|
+
if (char === 123) templateDepth++;
|
|
286
|
+
else if (char === 125) {
|
|
287
|
+
if (templateDepth === 0) {
|
|
288
|
+
index++;
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
templateDepth--;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
let value = source[index];
|
|
295
|
+
const pair = source.slice(index, index + 2);
|
|
296
|
+
const triple = source.slice(index, index + 3);
|
|
297
|
+
if (triple === "...") value = triple;
|
|
298
|
+
else if (pair === "?." || pair === "=>" || pair === "++" || pair === "--") value = pair;
|
|
299
|
+
if (value === "(") headers.push(isHeader(tokens));
|
|
300
|
+
tokens.push({
|
|
301
|
+
k: "p",
|
|
302
|
+
value,
|
|
303
|
+
at: index
|
|
304
|
+
});
|
|
305
|
+
index += value.length;
|
|
306
|
+
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headers.pop() || value === "]" || value === "}";
|
|
307
|
+
}
|
|
308
|
+
return !templateExpression;
|
|
309
|
+
};
|
|
310
|
+
return scanCode() ? tokens : void 0;
|
|
311
|
+
}
|
|
48
312
|
|
|
49
313
|
//#endregion
|
|
50
|
-
exports.
|
|
51
|
-
exports.isIdentCharCode = isIdentCharCode;
|
|
52
|
-
exports.isSpace = isSpace;
|
|
314
|
+
exports.scanTokens = scanTokens;
|
|
53
315
|
exports.skipString = skipString;
|
package/dist/compile/lexer.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
//#region src/compile/lexer.ts
|
|
2
|
-
const isSpace = (ch) => ch === " " || ch === "\n" || ch === " " || ch === "\r";
|
|
3
|
-
const isIdentChar = (ch) => ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_" || ch === "$";
|
|
4
|
-
const isIdentCharCode = (code) => code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95 || code === 36;
|
|
5
2
|
function skipString(src, start) {
|
|
6
3
|
const quote = src[start];
|
|
7
4
|
let i = start + 1;
|
|
@@ -43,6 +40,273 @@ function skipString(src, start) {
|
|
|
43
40
|
}
|
|
44
41
|
return i;
|
|
45
42
|
}
|
|
43
|
+
const prefixKeywords = new Set([
|
|
44
|
+
"await",
|
|
45
|
+
"case",
|
|
46
|
+
"delete",
|
|
47
|
+
"do",
|
|
48
|
+
"else",
|
|
49
|
+
"in",
|
|
50
|
+
"instanceof",
|
|
51
|
+
"new",
|
|
52
|
+
"of",
|
|
53
|
+
"return",
|
|
54
|
+
"throw",
|
|
55
|
+
"typeof",
|
|
56
|
+
"void",
|
|
57
|
+
"yield"
|
|
58
|
+
]);
|
|
59
|
+
const isSpace = (char) => char === 32 || char >= 9 && char <= 13 || char >= 128 && /\s/.test(String.fromCharCode(char));
|
|
60
|
+
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128 && !isSpace(char);
|
|
61
|
+
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
62
|
+
function isHeader(tokens) {
|
|
63
|
+
let keyword = tokens.length - 1;
|
|
64
|
+
if (keyword > 0 && tokens[keyword].value === "await" && tokens[keyword - 1].value === "for") keyword--;
|
|
65
|
+
if (keyword < 0) return false;
|
|
66
|
+
const { k, value: v } = tokens[keyword];
|
|
67
|
+
if (k !== "i" || v !== "if" && v !== "while" && v !== "for" && v !== "with") return false;
|
|
68
|
+
if (keyword === 0) return true;
|
|
69
|
+
const before = tokens[keyword - 1];
|
|
70
|
+
return !(before.k === "p" && (before.value === "." || before.value === "?." || before.value === "#"));
|
|
71
|
+
}
|
|
72
|
+
function scanTokens(source) {
|
|
73
|
+
const tokens = [];
|
|
74
|
+
let index = 0;
|
|
75
|
+
let canEndExpression = false;
|
|
76
|
+
const headers = [];
|
|
77
|
+
const skipUnicodeEscape = () => {
|
|
78
|
+
index += 2;
|
|
79
|
+
if (source.charCodeAt(index) === 123) {
|
|
80
|
+
const end = source.indexOf("}", index + 1);
|
|
81
|
+
if (end === -1) return false;
|
|
82
|
+
index = end + 1;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
for (let digit = 0; digit < 4; digit++) {
|
|
86
|
+
const hex = source.charCodeAt(index + digit);
|
|
87
|
+
if (!(hex >= 48 && hex <= 57 || hex >= 65 && hex <= 70 || hex >= 97 && hex <= 102)) return false;
|
|
88
|
+
}
|
|
89
|
+
index += 4;
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
const scanCode = (templateExpression = false) => {
|
|
93
|
+
let templateDepth = 0;
|
|
94
|
+
while (index < source.length) {
|
|
95
|
+
const char = source.charCodeAt(index);
|
|
96
|
+
if (isSpace(char)) {
|
|
97
|
+
index++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (char === 92 && source.charCodeAt(index + 1) !== 117) return false;
|
|
101
|
+
if (char === 47) {
|
|
102
|
+
const next = source.charCodeAt(index + 1);
|
|
103
|
+
if (next === 47) {
|
|
104
|
+
index += 2;
|
|
105
|
+
while (index < source.length && source.charCodeAt(index) !== 10 && source.charCodeAt(index) !== 13 && source.charCodeAt(index) !== 8232 && source.charCodeAt(index) !== 8233) index++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (next === 42) {
|
|
109
|
+
index += 2;
|
|
110
|
+
while (index + 1 < source.length && !(source.charCodeAt(index) === 42 && source.charCodeAt(index + 1) === 47)) index++;
|
|
111
|
+
if (index + 1 >= source.length) return false;
|
|
112
|
+
index += 2;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!canEndExpression) {
|
|
116
|
+
const previous = tokens.length ? tokens[tokens.length - 1] : void 0;
|
|
117
|
+
if (previous?.k === "i" && (previous.value === "of" || previous.value === "await" || previous.value === "yield")) return false;
|
|
118
|
+
index++;
|
|
119
|
+
let escaped = false;
|
|
120
|
+
let characterClass = false;
|
|
121
|
+
let closed = false;
|
|
122
|
+
while (index < source.length) {
|
|
123
|
+
const regexChar = source.charCodeAt(index++);
|
|
124
|
+
if (escaped) {
|
|
125
|
+
escaped = false;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (regexChar === 92) {
|
|
129
|
+
escaped = true;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (regexChar === 91) characterClass = true;
|
|
133
|
+
else if (regexChar === 93) characterClass = false;
|
|
134
|
+
else if (regexChar === 47 && !characterClass) {
|
|
135
|
+
closed = true;
|
|
136
|
+
break;
|
|
137
|
+
} else if (regexChar === 10 || regexChar === 13) return false;
|
|
138
|
+
}
|
|
139
|
+
if (!closed) return false;
|
|
140
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
141
|
+
canEndExpression = true;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const previous = tokens.length ? tokens[tokens.length - 1] : void 0;
|
|
145
|
+
if (previous?.k === "p" && previous.value === "}") return false;
|
|
146
|
+
tokens.push({
|
|
147
|
+
k: "p",
|
|
148
|
+
value: "/",
|
|
149
|
+
at: index
|
|
150
|
+
});
|
|
151
|
+
index++;
|
|
152
|
+
canEndExpression = false;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (char === 34 || char === 39) {
|
|
156
|
+
const quote = char;
|
|
157
|
+
const start = ++index;
|
|
158
|
+
let escaped = false;
|
|
159
|
+
while (index < source.length) {
|
|
160
|
+
const stringChar = source.charCodeAt(index);
|
|
161
|
+
if (escaped) escaped = false;
|
|
162
|
+
else if (stringChar === 92) escaped = true;
|
|
163
|
+
else if (stringChar === quote) break;
|
|
164
|
+
else if (stringChar === 10 || stringChar === 13) return false;
|
|
165
|
+
index++;
|
|
166
|
+
}
|
|
167
|
+
if (index >= source.length) return false;
|
|
168
|
+
tokens.push({
|
|
169
|
+
k: "s",
|
|
170
|
+
value: source.slice(start, index),
|
|
171
|
+
at: start - 1
|
|
172
|
+
});
|
|
173
|
+
index++;
|
|
174
|
+
canEndExpression = true;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (char === 96) {
|
|
178
|
+
index++;
|
|
179
|
+
let closed = false;
|
|
180
|
+
while (index < source.length) {
|
|
181
|
+
const templateChar = source.charCodeAt(index);
|
|
182
|
+
if (templateChar === 92) {
|
|
183
|
+
index += 2;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (templateChar === 96) {
|
|
187
|
+
index++;
|
|
188
|
+
closed = true;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
if (templateChar === 36 && source.charCodeAt(index + 1) === 123) {
|
|
192
|
+
index += 2;
|
|
193
|
+
canEndExpression = false;
|
|
194
|
+
if (!scanCode(true)) return false;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
index++;
|
|
198
|
+
}
|
|
199
|
+
if (!closed) return false;
|
|
200
|
+
canEndExpression = true;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (isIdentifierStart(char) || char === 92 && source.charCodeAt(index + 1) === 117) {
|
|
204
|
+
const start = index;
|
|
205
|
+
if (char === 92) {
|
|
206
|
+
if (!skipUnicodeEscape()) return false;
|
|
207
|
+
} else index++;
|
|
208
|
+
while (index < source.length) {
|
|
209
|
+
const identifierChar = source.charCodeAt(index);
|
|
210
|
+
if (isIdentifierPart(identifierChar)) {
|
|
211
|
+
index++;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (identifierChar === 92 && source.charCodeAt(index + 1) === 117) {
|
|
215
|
+
if (!skipUnicodeEscape()) return false;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
const identifierText = source.slice(start, index);
|
|
221
|
+
let value;
|
|
222
|
+
if (!identifierText.includes("\\u")) value = identifierText;
|
|
223
|
+
else {
|
|
224
|
+
let decoded = "";
|
|
225
|
+
let failed = false;
|
|
226
|
+
for (let i = 0; i < identifierText.length; i++) {
|
|
227
|
+
if (identifierText.charCodeAt(i) !== 92 || identifierText.charCodeAt(i + 1) !== 117) {
|
|
228
|
+
decoded += identifierText[i];
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
i += 2;
|
|
232
|
+
let hex;
|
|
233
|
+
if (identifierText.charCodeAt(i) === 123) {
|
|
234
|
+
const end = identifierText.indexOf("}", i + 1);
|
|
235
|
+
if (end === -1) {
|
|
236
|
+
failed = true;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
hex = identifierText.slice(i + 1, end);
|
|
240
|
+
i = end;
|
|
241
|
+
} else {
|
|
242
|
+
hex = identifierText.slice(i, i + 4);
|
|
243
|
+
if (hex.length !== 4) {
|
|
244
|
+
failed = true;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
i += 3;
|
|
248
|
+
}
|
|
249
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
250
|
+
if (!Number.isFinite(codePoint) || codePoint > 1114111) {
|
|
251
|
+
failed = true;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
decoded += String.fromCodePoint(codePoint);
|
|
255
|
+
}
|
|
256
|
+
value = failed ? void 0 : decoded;
|
|
257
|
+
}
|
|
258
|
+
if (value === void 0) return false;
|
|
259
|
+
canEndExpression = !prefixKeywords.has(value);
|
|
260
|
+
if (!canEndExpression && tokens.length) {
|
|
261
|
+
const previous = tokens[tokens.length - 1];
|
|
262
|
+
canEndExpression = previous.k === "p" && (previous.value === "." || previous.value === "?." || previous.value === "#");
|
|
263
|
+
}
|
|
264
|
+
tokens.push({
|
|
265
|
+
k: "i",
|
|
266
|
+
value,
|
|
267
|
+
at: start
|
|
268
|
+
});
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const leadingDot = char === 46 && source.charCodeAt(index + 1) >= 48 && source.charCodeAt(index + 1) <= 57;
|
|
272
|
+
if (char >= 48 && char <= 57 || leadingDot) {
|
|
273
|
+
index++;
|
|
274
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
275
|
+
if (!leadingDot && source.charCodeAt(index) === 46) {
|
|
276
|
+
index++;
|
|
277
|
+
while (isIdentifierPart(source.charCodeAt(index))) index++;
|
|
278
|
+
}
|
|
279
|
+
canEndExpression = true;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (templateExpression) {
|
|
283
|
+
if (char === 123) templateDepth++;
|
|
284
|
+
else if (char === 125) {
|
|
285
|
+
if (templateDepth === 0) {
|
|
286
|
+
index++;
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
templateDepth--;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
let value = source[index];
|
|
293
|
+
const pair = source.slice(index, index + 2);
|
|
294
|
+
const triple = source.slice(index, index + 3);
|
|
295
|
+
if (triple === "...") value = triple;
|
|
296
|
+
else if (pair === "?." || pair === "=>" || pair === "++" || pair === "--") value = pair;
|
|
297
|
+
if (value === "(") headers.push(isHeader(tokens));
|
|
298
|
+
tokens.push({
|
|
299
|
+
k: "p",
|
|
300
|
+
value,
|
|
301
|
+
at: index
|
|
302
|
+
});
|
|
303
|
+
index += value.length;
|
|
304
|
+
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headers.pop() || value === "]" || value === "}";
|
|
305
|
+
}
|
|
306
|
+
return !templateExpression;
|
|
307
|
+
};
|
|
308
|
+
return scanCode() ? tokens : void 0;
|
|
309
|
+
}
|
|
46
310
|
|
|
47
311
|
//#endregion
|
|
48
|
-
export {
|
|
312
|
+
export { scanTokens, skipString };
|
package/dist/compile/utils.js
CHANGED
|
@@ -4,14 +4,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
function isAsyncFunction(fn) {
|
|
5
5
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
8
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
9
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
9
10
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
10
11
|
function mayReturnPromise(fn) {
|
|
11
12
|
let result = mayReturnPromiseCache.get(fn);
|
|
12
13
|
if (result !== void 0) return result;
|
|
13
|
-
const literal =
|
|
14
|
-
|
|
14
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
15
|
+
const arrow = matchArrow.exec(literal);
|
|
16
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
17
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
15
18
|
mayReturnPromiseCache.set(fn, result);
|
|
16
19
|
return result;
|
|
17
20
|
}
|
package/dist/compile/utils.mjs
CHANGED
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
function isAsyncFunction(fn) {
|
|
3
3
|
return fn.constructor.name === "AsyncFunction" || fn.constructor.name === "AsyncGeneratorFunction";
|
|
4
4
|
}
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const matchArrow = /^(?:[\w$]+|\([\w$\s,.[\]{}:]*\))\s*=>([\s\S]*)$/;
|
|
6
|
+
const matchFunction = /^(?:function(?:\s+[\w$]+)?|[\w$]+)\s*\([\w$\s,.[\]{}:]*\)\s*(\{[\s\S]*\})$/;
|
|
7
|
+
const matchLiteral = /^(?:true|false|null|-?\d+(?:\.\d+)?|'[^'\\]*'|"[^"\\]*")$/;
|
|
7
8
|
const mayReturnPromiseCache = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function mayReturnPromise(fn) {
|
|
9
10
|
let result = mayReturnPromiseCache.get(fn);
|
|
10
11
|
if (result !== void 0) return result;
|
|
11
|
-
const literal =
|
|
12
|
-
|
|
12
|
+
const literal = Function.prototype.toString.call(fn).trim();
|
|
13
|
+
const arrow = matchArrow.exec(literal);
|
|
14
|
+
const body = (arrow?.[1] ?? matchFunction.exec(literal)?.[1])?.trimStart();
|
|
15
|
+
result = literal.includes("[native code]") || !(body?.startsWith("{") && body.endsWith("}") && !/\breturn\b/.test(body) || arrow && matchLiteral.test(body));
|
|
13
16
|
mayReturnPromiseCache.set(fn, result);
|
|
14
17
|
return result;
|
|
15
18
|
}
|
package/dist/compiled.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { HandlerManifest, ValidatorManifest } from "./compile/aot.js";
|
|
|
7
7
|
* A build plugin (`elysia/plugin/*`) redirects this specifier to a module
|
|
8
8
|
* generated by `compileToSource`, which self-registers the frozen validator +
|
|
9
9
|
* handler manifest. Without a plugin it resolves here and is a harmless no-op.
|
|
10
|
-
* Both named exports mirror what `compileToSource` emits.
|
|
11
10
|
*
|
|
12
11
|
* @see compileToSource
|
|
13
12
|
*/
|
package/dist/compiled.js
CHANGED
|
@@ -7,7 +7,6 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
7
7
|
* A build plugin (`elysia/plugin/*`) redirects this specifier to a module
|
|
8
8
|
* generated by `compileToSource`, which self-registers the frozen validator +
|
|
9
9
|
* handler manifest. Without a plugin it resolves here and is a harmless no-op.
|
|
10
|
-
* Both named exports mirror what `compileToSource` emits.
|
|
11
10
|
*
|
|
12
11
|
* @see compileToSource
|
|
13
12
|
*/
|
package/dist/compiled.mjs
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* A build plugin (`elysia/plugin/*`) redirects this specifier to a module
|
|
6
6
|
* generated by `compileToSource`, which self-registers the frozen validator +
|
|
7
7
|
* handler manifest. Without a plugin it resolves here and is a harmless no-op.
|
|
8
|
-
* Both named exports mirror what `compileToSource` emits.
|
|
9
8
|
*
|
|
10
9
|
* @see compileToSource
|
|
11
10
|
*/
|
package/dist/context.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { BaseCookie } from "./cookie/types.js";
|
|
2
|
-
import { Cookie } from "./cookie/cookie.js";
|
|
3
2
|
import { StatusMap } from "./constants.js";
|
|
4
|
-
import {
|
|
3
|
+
import { SelectiveProblem, SelectiveStatus, problem, status } from "./error.js";
|
|
5
4
|
import { redirect } from "./utils.js";
|
|
5
|
+
import { Server } from "./universal/server.js";
|
|
6
|
+
import { Cookie } from "./cookie/cookie.js";
|
|
6
7
|
import { AfterResponseHandler, DefaultSingleton, HTTPHeaders, InputSchema, MaybePromise, Prettify, ResolvePath, RouteSchema, SingletonBase } from "./types.js";
|
|
7
|
-
import { SelectiveStatus, status } from "./error.js";
|
|
8
8
|
import { AnyElysia } from "./base.js";
|
|
9
9
|
|
|
10
10
|
//#region src/context.d.ts
|
|
11
11
|
declare function createBaseContext(app: AnyElysia): any;
|
|
12
|
-
declare function clearContextCache(): void;
|
|
12
|
+
declare function clearContextCache(app?: AnyElysia): void;
|
|
13
13
|
declare function createContext(app: AnyElysia): new (request: Request) => Context;
|
|
14
14
|
interface ContextBase<in out Route extends RouteSchema, in out Singleton extends SingletonBase> {
|
|
15
15
|
server: Server | null;
|
|
@@ -23,8 +23,13 @@ interface ContextBase<in out Route extends RouteSchema, in out Singleton extends
|
|
|
23
23
|
* Use `Context.cookie` instead
|
|
24
24
|
*/
|
|
25
25
|
cookie?: Record<string, BaseCookie>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Removed in 2.0, return `redirect(url)` instead
|
|
28
|
+
*/
|
|
29
|
+
redirect?: never;
|
|
26
30
|
};
|
|
27
31
|
status: {} extends Route['response'] ? typeof status : SelectiveStatus<Route['response']>;
|
|
32
|
+
problem: {} extends Route['response'] ? typeof problem : SelectiveProblem<Route['response']>;
|
|
28
33
|
/**
|
|
29
34
|
* Append a callback to run after the response is sent
|
|
30
35
|
*/
|
|
@@ -85,8 +90,13 @@ type PreContext<in out Singleton extends SingletonBase = {
|
|
|
85
90
|
set: {
|
|
86
91
|
headers: HTTPHeaders;
|
|
87
92
|
status?: number;
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Removed in 2.0, return `redirect(url)` instead
|
|
95
|
+
*/
|
|
96
|
+
redirect?: never;
|
|
88
97
|
};
|
|
89
98
|
status: typeof status;
|
|
99
|
+
problem: typeof problem;
|
|
90
100
|
} & Singleton['decorator']>;
|
|
91
101
|
//#endregion
|
|
92
102
|
export { Context, ErrorContext, LifecycleContext, PreContext, clearContextCache, createBaseContext, createContext };
|