@voidzero-dev/vite-plus-test 0.1.9 → 0.1.11
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/LICENSE.md +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +168 -59
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +23 -6
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-playwright/locators.js +1 -1
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +32 -20
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +85 -9
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +35 -26
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
|
2
|
-
import c from '../../vendor/tinyrainbow.mjs';
|
|
3
|
-
|
|
4
|
-
var jsTokens_1;
|
|
5
|
-
var hasRequiredJsTokens;
|
|
6
|
-
|
|
7
|
-
function requireJsTokens () {
|
|
8
|
-
if (hasRequiredJsTokens) return jsTokens_1;
|
|
9
|
-
hasRequiredJsTokens = 1;
|
|
10
|
-
// Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
|
|
11
|
-
// License: MIT.
|
|
12
|
-
var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
|
13
|
-
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
|
14
|
-
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
|
15
|
-
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
|
16
|
-
StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
|
|
17
|
-
NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
|
|
18
|
-
Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
|
19
|
-
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
|
20
|
-
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
|
21
|
-
MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
|
|
22
|
-
SingleLineComment = /\/\/.*/y;
|
|
23
|
-
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
|
24
|
-
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
|
25
|
-
JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
|
|
26
|
-
JSXText = /[^<>{}]+/y;
|
|
27
|
-
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
|
28
|
-
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
|
29
|
-
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
|
30
|
-
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
|
31
|
-
Newline = RegExp(LineTerminatorSequence.source);
|
|
32
|
-
jsTokens_1 = function*(input, {jsx = false} = {}) {
|
|
33
|
-
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
|
34
|
-
({length} = input);
|
|
35
|
-
lastIndex = 0;
|
|
36
|
-
lastSignificantToken = "";
|
|
37
|
-
stack = [
|
|
38
|
-
{tag: "JS"}
|
|
39
|
-
];
|
|
40
|
-
braces = [];
|
|
41
|
-
parenNesting = 0;
|
|
42
|
-
postfixIncDec = false;
|
|
43
|
-
while (lastIndex < length) {
|
|
44
|
-
mode = stack[stack.length - 1];
|
|
45
|
-
switch (mode.tag) {
|
|
46
|
-
case "JS":
|
|
47
|
-
case "JSNonExpressionParen":
|
|
48
|
-
case "InterpolationInTemplate":
|
|
49
|
-
case "InterpolationInJSX":
|
|
50
|
-
if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
51
|
-
RegularExpressionLiteral.lastIndex = lastIndex;
|
|
52
|
-
if (match = RegularExpressionLiteral.exec(input)) {
|
|
53
|
-
lastIndex = RegularExpressionLiteral.lastIndex;
|
|
54
|
-
lastSignificantToken = match[0];
|
|
55
|
-
postfixIncDec = true;
|
|
56
|
-
yield ({
|
|
57
|
-
type: "RegularExpressionLiteral",
|
|
58
|
-
value: match[0],
|
|
59
|
-
closed: match[1] !== void 0 && match[1] !== "\\"
|
|
60
|
-
});
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
Punctuator.lastIndex = lastIndex;
|
|
65
|
-
if (match = Punctuator.exec(input)) {
|
|
66
|
-
punctuator = match[0];
|
|
67
|
-
nextLastIndex = Punctuator.lastIndex;
|
|
68
|
-
nextLastSignificantToken = punctuator;
|
|
69
|
-
switch (punctuator) {
|
|
70
|
-
case "(":
|
|
71
|
-
if (lastSignificantToken === "?NonExpressionParenKeyword") {
|
|
72
|
-
stack.push({
|
|
73
|
-
tag: "JSNonExpressionParen",
|
|
74
|
-
nesting: parenNesting
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
parenNesting++;
|
|
78
|
-
postfixIncDec = false;
|
|
79
|
-
break;
|
|
80
|
-
case ")":
|
|
81
|
-
parenNesting--;
|
|
82
|
-
postfixIncDec = true;
|
|
83
|
-
if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
|
|
84
|
-
stack.pop();
|
|
85
|
-
nextLastSignificantToken = "?NonExpressionParenEnd";
|
|
86
|
-
postfixIncDec = false;
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
case "{":
|
|
90
|
-
Punctuator.lastIndex = 0;
|
|
91
|
-
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
|
92
|
-
braces.push(isExpression);
|
|
93
|
-
postfixIncDec = false;
|
|
94
|
-
break;
|
|
95
|
-
case "}":
|
|
96
|
-
switch (mode.tag) {
|
|
97
|
-
case "InterpolationInTemplate":
|
|
98
|
-
if (braces.length === mode.nesting) {
|
|
99
|
-
Template.lastIndex = lastIndex;
|
|
100
|
-
match = Template.exec(input);
|
|
101
|
-
lastIndex = Template.lastIndex;
|
|
102
|
-
lastSignificantToken = match[0];
|
|
103
|
-
if (match[1] === "${") {
|
|
104
|
-
lastSignificantToken = "?InterpolationInTemplate";
|
|
105
|
-
postfixIncDec = false;
|
|
106
|
-
yield ({
|
|
107
|
-
type: "TemplateMiddle",
|
|
108
|
-
value: match[0]
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
stack.pop();
|
|
112
|
-
postfixIncDec = true;
|
|
113
|
-
yield ({
|
|
114
|
-
type: "TemplateTail",
|
|
115
|
-
value: match[0],
|
|
116
|
-
closed: match[1] === "`"
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case "InterpolationInJSX":
|
|
123
|
-
if (braces.length === mode.nesting) {
|
|
124
|
-
stack.pop();
|
|
125
|
-
lastIndex += 1;
|
|
126
|
-
lastSignificantToken = "}";
|
|
127
|
-
yield ({
|
|
128
|
-
type: "JSXPunctuator",
|
|
129
|
-
value: "}"
|
|
130
|
-
});
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
postfixIncDec = braces.pop();
|
|
135
|
-
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
|
136
|
-
break;
|
|
137
|
-
case "]":
|
|
138
|
-
postfixIncDec = true;
|
|
139
|
-
break;
|
|
140
|
-
case "++":
|
|
141
|
-
case "--":
|
|
142
|
-
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
|
143
|
-
break;
|
|
144
|
-
case "<":
|
|
145
|
-
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
146
|
-
stack.push({tag: "JSXTag"});
|
|
147
|
-
lastIndex += 1;
|
|
148
|
-
lastSignificantToken = "<";
|
|
149
|
-
yield ({
|
|
150
|
-
type: "JSXPunctuator",
|
|
151
|
-
value: punctuator
|
|
152
|
-
});
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
postfixIncDec = false;
|
|
156
|
-
break;
|
|
157
|
-
default:
|
|
158
|
-
postfixIncDec = false;
|
|
159
|
-
}
|
|
160
|
-
lastIndex = nextLastIndex;
|
|
161
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
162
|
-
yield ({
|
|
163
|
-
type: "Punctuator",
|
|
164
|
-
value: punctuator
|
|
165
|
-
});
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
Identifier.lastIndex = lastIndex;
|
|
169
|
-
if (match = Identifier.exec(input)) {
|
|
170
|
-
lastIndex = Identifier.lastIndex;
|
|
171
|
-
nextLastSignificantToken = match[0];
|
|
172
|
-
switch (match[0]) {
|
|
173
|
-
case "for":
|
|
174
|
-
case "if":
|
|
175
|
-
case "while":
|
|
176
|
-
case "with":
|
|
177
|
-
if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
|
|
178
|
-
nextLastSignificantToken = "?NonExpressionParenKeyword";
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
182
|
-
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
|
183
|
-
yield ({
|
|
184
|
-
type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
|
|
185
|
-
value: match[0]
|
|
186
|
-
});
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
StringLiteral.lastIndex = lastIndex;
|
|
190
|
-
if (match = StringLiteral.exec(input)) {
|
|
191
|
-
lastIndex = StringLiteral.lastIndex;
|
|
192
|
-
lastSignificantToken = match[0];
|
|
193
|
-
postfixIncDec = true;
|
|
194
|
-
yield ({
|
|
195
|
-
type: "StringLiteral",
|
|
196
|
-
value: match[0],
|
|
197
|
-
closed: match[2] !== void 0
|
|
198
|
-
});
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
NumericLiteral.lastIndex = lastIndex;
|
|
202
|
-
if (match = NumericLiteral.exec(input)) {
|
|
203
|
-
lastIndex = NumericLiteral.lastIndex;
|
|
204
|
-
lastSignificantToken = match[0];
|
|
205
|
-
postfixIncDec = true;
|
|
206
|
-
yield ({
|
|
207
|
-
type: "NumericLiteral",
|
|
208
|
-
value: match[0]
|
|
209
|
-
});
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
Template.lastIndex = lastIndex;
|
|
213
|
-
if (match = Template.exec(input)) {
|
|
214
|
-
lastIndex = Template.lastIndex;
|
|
215
|
-
lastSignificantToken = match[0];
|
|
216
|
-
if (match[1] === "${") {
|
|
217
|
-
lastSignificantToken = "?InterpolationInTemplate";
|
|
218
|
-
stack.push({
|
|
219
|
-
tag: "InterpolationInTemplate",
|
|
220
|
-
nesting: braces.length
|
|
221
|
-
});
|
|
222
|
-
postfixIncDec = false;
|
|
223
|
-
yield ({
|
|
224
|
-
type: "TemplateHead",
|
|
225
|
-
value: match[0]
|
|
226
|
-
});
|
|
227
|
-
} else {
|
|
228
|
-
postfixIncDec = true;
|
|
229
|
-
yield ({
|
|
230
|
-
type: "NoSubstitutionTemplate",
|
|
231
|
-
value: match[0],
|
|
232
|
-
closed: match[1] === "`"
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
break;
|
|
238
|
-
case "JSXTag":
|
|
239
|
-
case "JSXTagEnd":
|
|
240
|
-
JSXPunctuator.lastIndex = lastIndex;
|
|
241
|
-
if (match = JSXPunctuator.exec(input)) {
|
|
242
|
-
lastIndex = JSXPunctuator.lastIndex;
|
|
243
|
-
nextLastSignificantToken = match[0];
|
|
244
|
-
switch (match[0]) {
|
|
245
|
-
case "<":
|
|
246
|
-
stack.push({tag: "JSXTag"});
|
|
247
|
-
break;
|
|
248
|
-
case ">":
|
|
249
|
-
stack.pop();
|
|
250
|
-
if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
|
|
251
|
-
nextLastSignificantToken = "?JSX";
|
|
252
|
-
postfixIncDec = true;
|
|
253
|
-
} else {
|
|
254
|
-
stack.push({tag: "JSXChildren"});
|
|
255
|
-
}
|
|
256
|
-
break;
|
|
257
|
-
case "{":
|
|
258
|
-
stack.push({
|
|
259
|
-
tag: "InterpolationInJSX",
|
|
260
|
-
nesting: braces.length
|
|
261
|
-
});
|
|
262
|
-
nextLastSignificantToken = "?InterpolationInJSX";
|
|
263
|
-
postfixIncDec = false;
|
|
264
|
-
break;
|
|
265
|
-
case "/":
|
|
266
|
-
if (lastSignificantToken === "<") {
|
|
267
|
-
stack.pop();
|
|
268
|
-
if (stack[stack.length - 1].tag === "JSXChildren") {
|
|
269
|
-
stack.pop();
|
|
270
|
-
}
|
|
271
|
-
stack.push({tag: "JSXTagEnd"});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
lastSignificantToken = nextLastSignificantToken;
|
|
275
|
-
yield ({
|
|
276
|
-
type: "JSXPunctuator",
|
|
277
|
-
value: match[0]
|
|
278
|
-
});
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
JSXIdentifier.lastIndex = lastIndex;
|
|
282
|
-
if (match = JSXIdentifier.exec(input)) {
|
|
283
|
-
lastIndex = JSXIdentifier.lastIndex;
|
|
284
|
-
lastSignificantToken = match[0];
|
|
285
|
-
yield ({
|
|
286
|
-
type: "JSXIdentifier",
|
|
287
|
-
value: match[0]
|
|
288
|
-
});
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
JSXString.lastIndex = lastIndex;
|
|
292
|
-
if (match = JSXString.exec(input)) {
|
|
293
|
-
lastIndex = JSXString.lastIndex;
|
|
294
|
-
lastSignificantToken = match[0];
|
|
295
|
-
yield ({
|
|
296
|
-
type: "JSXString",
|
|
297
|
-
value: match[0],
|
|
298
|
-
closed: match[2] !== void 0
|
|
299
|
-
});
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
break;
|
|
303
|
-
case "JSXChildren":
|
|
304
|
-
JSXText.lastIndex = lastIndex;
|
|
305
|
-
if (match = JSXText.exec(input)) {
|
|
306
|
-
lastIndex = JSXText.lastIndex;
|
|
307
|
-
lastSignificantToken = match[0];
|
|
308
|
-
yield ({
|
|
309
|
-
type: "JSXText",
|
|
310
|
-
value: match[0]
|
|
311
|
-
});
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
switch (input[lastIndex]) {
|
|
315
|
-
case "<":
|
|
316
|
-
stack.push({tag: "JSXTag"});
|
|
317
|
-
lastIndex++;
|
|
318
|
-
lastSignificantToken = "<";
|
|
319
|
-
yield ({
|
|
320
|
-
type: "JSXPunctuator",
|
|
321
|
-
value: "<"
|
|
322
|
-
});
|
|
323
|
-
continue;
|
|
324
|
-
case "{":
|
|
325
|
-
stack.push({
|
|
326
|
-
tag: "InterpolationInJSX",
|
|
327
|
-
nesting: braces.length
|
|
328
|
-
});
|
|
329
|
-
lastIndex++;
|
|
330
|
-
lastSignificantToken = "?InterpolationInJSX";
|
|
331
|
-
postfixIncDec = false;
|
|
332
|
-
yield ({
|
|
333
|
-
type: "JSXPunctuator",
|
|
334
|
-
value: "{"
|
|
335
|
-
});
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
WhiteSpace.lastIndex = lastIndex;
|
|
340
|
-
if (match = WhiteSpace.exec(input)) {
|
|
341
|
-
lastIndex = WhiteSpace.lastIndex;
|
|
342
|
-
yield ({
|
|
343
|
-
type: "WhiteSpace",
|
|
344
|
-
value: match[0]
|
|
345
|
-
});
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
LineTerminatorSequence.lastIndex = lastIndex;
|
|
349
|
-
if (match = LineTerminatorSequence.exec(input)) {
|
|
350
|
-
lastIndex = LineTerminatorSequence.lastIndex;
|
|
351
|
-
postfixIncDec = false;
|
|
352
|
-
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
353
|
-
lastSignificantToken = "?NoLineTerminatorHere";
|
|
354
|
-
}
|
|
355
|
-
yield ({
|
|
356
|
-
type: "LineTerminatorSequence",
|
|
357
|
-
value: match[0]
|
|
358
|
-
});
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
MultiLineComment.lastIndex = lastIndex;
|
|
362
|
-
if (match = MultiLineComment.exec(input)) {
|
|
363
|
-
lastIndex = MultiLineComment.lastIndex;
|
|
364
|
-
if (Newline.test(match[0])) {
|
|
365
|
-
postfixIncDec = false;
|
|
366
|
-
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
367
|
-
lastSignificantToken = "?NoLineTerminatorHere";
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
yield ({
|
|
371
|
-
type: "MultiLineComment",
|
|
372
|
-
value: match[0],
|
|
373
|
-
closed: match[1] !== void 0
|
|
374
|
-
});
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
SingleLineComment.lastIndex = lastIndex;
|
|
378
|
-
if (match = SingleLineComment.exec(input)) {
|
|
379
|
-
lastIndex = SingleLineComment.lastIndex;
|
|
380
|
-
postfixIncDec = false;
|
|
381
|
-
yield ({
|
|
382
|
-
type: "SingleLineComment",
|
|
383
|
-
value: match[0]
|
|
384
|
-
});
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
|
388
|
-
lastIndex += firstCodePoint.length;
|
|
389
|
-
lastSignificantToken = firstCodePoint;
|
|
390
|
-
postfixIncDec = false;
|
|
391
|
-
yield ({
|
|
392
|
-
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
|
393
|
-
value: firstCodePoint
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return void 0;
|
|
397
|
-
};
|
|
398
|
-
return jsTokens_1;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
var jsTokensExports = /*@__PURE__*/ requireJsTokens();
|
|
402
|
-
var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokensExports);
|
|
403
|
-
|
|
404
|
-
// src/index.ts
|
|
405
|
-
var reservedWords = {
|
|
406
|
-
keyword: [
|
|
407
|
-
"break",
|
|
408
|
-
"case",
|
|
409
|
-
"catch",
|
|
410
|
-
"continue",
|
|
411
|
-
"debugger",
|
|
412
|
-
"default",
|
|
413
|
-
"do",
|
|
414
|
-
"else",
|
|
415
|
-
"finally",
|
|
416
|
-
"for",
|
|
417
|
-
"function",
|
|
418
|
-
"if",
|
|
419
|
-
"return",
|
|
420
|
-
"switch",
|
|
421
|
-
"throw",
|
|
422
|
-
"try",
|
|
423
|
-
"var",
|
|
424
|
-
"const",
|
|
425
|
-
"while",
|
|
426
|
-
"with",
|
|
427
|
-
"new",
|
|
428
|
-
"this",
|
|
429
|
-
"super",
|
|
430
|
-
"class",
|
|
431
|
-
"extends",
|
|
432
|
-
"export",
|
|
433
|
-
"import",
|
|
434
|
-
"null",
|
|
435
|
-
"true",
|
|
436
|
-
"false",
|
|
437
|
-
"in",
|
|
438
|
-
"instanceof",
|
|
439
|
-
"typeof",
|
|
440
|
-
"void",
|
|
441
|
-
"delete"
|
|
442
|
-
],
|
|
443
|
-
strict: [
|
|
444
|
-
"implements",
|
|
445
|
-
"interface",
|
|
446
|
-
"let",
|
|
447
|
-
"package",
|
|
448
|
-
"private",
|
|
449
|
-
"protected",
|
|
450
|
-
"public",
|
|
451
|
-
"static",
|
|
452
|
-
"yield"
|
|
453
|
-
]
|
|
454
|
-
}, keywords = new Set(reservedWords.keyword), reservedWordsStrictSet = new Set(reservedWords.strict), sometimesKeywords = /* @__PURE__ */ new Set(["as", "async", "from", "get", "of", "set"]);
|
|
455
|
-
function isReservedWord(word) {
|
|
456
|
-
return word === "await" || word === "enum";
|
|
457
|
-
}
|
|
458
|
-
function isStrictReservedWord(word) {
|
|
459
|
-
return isReservedWord(word) || reservedWordsStrictSet.has(word);
|
|
460
|
-
}
|
|
461
|
-
function isKeyword(word) {
|
|
462
|
-
return keywords.has(word);
|
|
463
|
-
}
|
|
464
|
-
var BRACKET = /^[()[\]{}]$/, getTokenType = function(token) {
|
|
465
|
-
if (token.type === "IdentifierName") {
|
|
466
|
-
if (isKeyword(token.value) || isStrictReservedWord(token.value) || sometimesKeywords.has(token.value))
|
|
467
|
-
return "Keyword";
|
|
468
|
-
if (token.value[0] && token.value[0] !== token.value[0].toLowerCase())
|
|
469
|
-
return "IdentifierCapitalized";
|
|
470
|
-
}
|
|
471
|
-
return token.type === "Punctuator" && BRACKET.test(token.value) ? "Bracket" : token.type === "Invalid" && (token.value === "@" || token.value === "#") ? "Punctuator" : token.type;
|
|
472
|
-
};
|
|
473
|
-
function getCallableType(token) {
|
|
474
|
-
if (token.type === "IdentifierName")
|
|
475
|
-
return "IdentifierCallable";
|
|
476
|
-
if (token.type === "PrivateIdentifier")
|
|
477
|
-
return "PrivateIdentifierCallable";
|
|
478
|
-
throw new Error("Not a callable token");
|
|
479
|
-
}
|
|
480
|
-
var colorize = (defs, type, value) => {
|
|
481
|
-
let colorize2 = defs[type];
|
|
482
|
-
return colorize2 ? colorize2(value) : value;
|
|
483
|
-
}, highlightTokens = (defs, text, jsx) => {
|
|
484
|
-
let highlighted = "", lastPotentialCallable = null, stackedHighlight = "";
|
|
485
|
-
for (let token of jsTokens(text, { jsx })) {
|
|
486
|
-
let type = getTokenType(token);
|
|
487
|
-
if (type === "IdentifierName" || type === "PrivateIdentifier") {
|
|
488
|
-
lastPotentialCallable && (highlighted += colorize(defs, getTokenType(lastPotentialCallable), lastPotentialCallable.value) + stackedHighlight, stackedHighlight = ""), lastPotentialCallable = token;
|
|
489
|
-
continue;
|
|
490
|
-
}
|
|
491
|
-
if (lastPotentialCallable && (token.type === "WhiteSpace" || token.type === "LineTerminatorSequence" || token.type === "Punctuator" && (token.value === "?." || token.value === "!"))) {
|
|
492
|
-
stackedHighlight += colorize(defs, type, token.value);
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (stackedHighlight && !lastPotentialCallable && (highlighted += stackedHighlight, stackedHighlight = ""), lastPotentialCallable) {
|
|
496
|
-
let type2 = token.type === "Punctuator" && token.value === "(" ? getCallableType(lastPotentialCallable) : getTokenType(lastPotentialCallable);
|
|
497
|
-
highlighted += colorize(defs, type2, lastPotentialCallable.value) + stackedHighlight, stackedHighlight = "", lastPotentialCallable = null;
|
|
498
|
-
}
|
|
499
|
-
highlighted += colorize(defs, type, token.value);
|
|
500
|
-
}
|
|
501
|
-
return highlighted;
|
|
502
|
-
};
|
|
503
|
-
function highlight$1(code, options = { jsx: false, colors: {} }) {
|
|
504
|
-
return code && highlightTokens(options.colors || {}, code, options.jsx);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
function getDefs(c) {
|
|
508
|
-
const Invalid = (text) => c.white(c.bgRed(c.bold(text)));
|
|
509
|
-
return {
|
|
510
|
-
Keyword: c.magenta,
|
|
511
|
-
IdentifierCapitalized: c.yellow,
|
|
512
|
-
Punctuator: c.yellow,
|
|
513
|
-
StringLiteral: c.green,
|
|
514
|
-
NoSubstitutionTemplate: c.green,
|
|
515
|
-
MultiLineComment: c.gray,
|
|
516
|
-
SingleLineComment: c.gray,
|
|
517
|
-
RegularExpressionLiteral: c.cyan,
|
|
518
|
-
NumericLiteral: c.blue,
|
|
519
|
-
TemplateHead: (text) => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)),
|
|
520
|
-
TemplateTail: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)),
|
|
521
|
-
TemplateMiddle: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)),
|
|
522
|
-
IdentifierCallable: c.blue,
|
|
523
|
-
PrivateIdentifierCallable: (text) => `#${c.blue(text.slice(1))}`,
|
|
524
|
-
Invalid,
|
|
525
|
-
JSXString: c.green,
|
|
526
|
-
JSXIdentifier: c.yellow,
|
|
527
|
-
JSXInvalid: Invalid,
|
|
528
|
-
JSXPunctuator: c.yellow
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
function highlight(code, options = { jsx: false }) {
|
|
532
|
-
return highlight$1(code, {
|
|
533
|
-
jsx: options.jsx,
|
|
534
|
-
colors: getDefs(options.colors || c)
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
export { highlight };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
|
|
2
|
-
/*
|
|
3
|
-
The MIT License (MIT)
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2014 Bob Lauer
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
const RealDate = Date;
|
|
26
|
-
let now = null;
|
|
27
|
-
class MockDate extends RealDate {
|
|
28
|
-
constructor(y, m, d, h, M, s, ms) {
|
|
29
|
-
super();
|
|
30
|
-
let date;
|
|
31
|
-
switch (arguments.length) {
|
|
32
|
-
case 0:
|
|
33
|
-
if (now !== null) date = new RealDate(now.valueOf());
|
|
34
|
-
else date = new RealDate();
|
|
35
|
-
break;
|
|
36
|
-
case 1:
|
|
37
|
-
date = new RealDate(y);
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
d = typeof d === "undefined" ? 1 : d;
|
|
41
|
-
h = h || 0;
|
|
42
|
-
M = M || 0;
|
|
43
|
-
s = s || 0;
|
|
44
|
-
ms = ms || 0;
|
|
45
|
-
date = new RealDate(y, m, d, h, M, s, ms);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
Object.setPrototypeOf(date, MockDate.prototype);
|
|
49
|
-
return date;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
MockDate.UTC = RealDate.UTC;
|
|
53
|
-
MockDate.now = function() {
|
|
54
|
-
return new MockDate().valueOf();
|
|
55
|
-
};
|
|
56
|
-
MockDate.parse = function(dateString) {
|
|
57
|
-
return RealDate.parse(dateString);
|
|
58
|
-
};
|
|
59
|
-
MockDate.toString = function() {
|
|
60
|
-
return RealDate.toString();
|
|
61
|
-
};
|
|
62
|
-
function mockDate(date) {
|
|
63
|
-
const dateObj = new RealDate(date.valueOf());
|
|
64
|
-
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
65
|
-
// @ts-expect-error global
|
|
66
|
-
globalThis.Date = MockDate;
|
|
67
|
-
now = dateObj.valueOf();
|
|
68
|
-
}
|
|
69
|
-
function resetDate() {
|
|
70
|
-
globalThis.Date = RealDate;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { RealDate as R, mockDate as m, resetDate as r };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { getSafeTimers } from '../@vitest/utils/timers.js';
|
|
2
|
-
import { c as createBirpc } from './index.Chj8NDwU.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
4
|
-
|
|
5
|
-
const { get } = Reflect;
|
|
6
|
-
function withSafeTimers(fn) {
|
|
7
|
-
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
8
|
-
const currentSetTimeout = globalThis.setTimeout;
|
|
9
|
-
const currentClearTimeout = globalThis.clearTimeout;
|
|
10
|
-
const currentSetImmediate = globalThis.setImmediate;
|
|
11
|
-
const currentClearImmediate = globalThis.clearImmediate;
|
|
12
|
-
const currentNextTick = globalThis.process?.nextTick;
|
|
13
|
-
try {
|
|
14
|
-
globalThis.setTimeout = setTimeout;
|
|
15
|
-
globalThis.clearTimeout = clearTimeout;
|
|
16
|
-
if (setImmediate) globalThis.setImmediate = setImmediate;
|
|
17
|
-
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
18
|
-
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
19
|
-
return fn();
|
|
20
|
-
} finally {
|
|
21
|
-
globalThis.setTimeout = currentSetTimeout;
|
|
22
|
-
globalThis.clearTimeout = currentClearTimeout;
|
|
23
|
-
globalThis.setImmediate = currentSetImmediate;
|
|
24
|
-
globalThis.clearImmediate = currentClearImmediate;
|
|
25
|
-
if (globalThis.process && nextTick) nextTick(() => {
|
|
26
|
-
globalThis.process.nextTick = currentNextTick;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const promises = /* @__PURE__ */ new Set();
|
|
31
|
-
async function rpcDone() {
|
|
32
|
-
if (!promises.size) return;
|
|
33
|
-
const awaitable = Array.from(promises);
|
|
34
|
-
return Promise.all(awaitable);
|
|
35
|
-
}
|
|
36
|
-
const onCancelCallbacks = [];
|
|
37
|
-
function onCancel(callback) {
|
|
38
|
-
onCancelCallbacks.push(callback);
|
|
39
|
-
}
|
|
40
|
-
function createRuntimeRpc(options) {
|
|
41
|
-
return createSafeRpc(createBirpc({ async onCancel(reason) {
|
|
42
|
-
await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
|
|
43
|
-
} }, {
|
|
44
|
-
eventNames: [
|
|
45
|
-
"onUserConsoleLog",
|
|
46
|
-
"onCollected",
|
|
47
|
-
"onCancel"
|
|
48
|
-
],
|
|
49
|
-
timeout: -1,
|
|
50
|
-
...options
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
function createSafeRpc(rpc) {
|
|
54
|
-
return new Proxy(rpc, { get(target, p, handler) {
|
|
55
|
-
// keep $rejectPendingCalls as sync function
|
|
56
|
-
if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
|
|
57
|
-
const sendCall = get(target, p, handler);
|
|
58
|
-
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
59
|
-
const result = sendCall(...args);
|
|
60
|
-
promises.add(result);
|
|
61
|
-
try {
|
|
62
|
-
return await result;
|
|
63
|
-
} finally {
|
|
64
|
-
promises.delete(result);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
safeSendCall.asEvent = sendCall.asEvent;
|
|
68
|
-
return safeSendCall;
|
|
69
|
-
} });
|
|
70
|
-
}
|
|
71
|
-
function rpc() {
|
|
72
|
-
const { rpc } = getWorkerState();
|
|
73
|
-
return rpc;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { rpcDone as a, createRuntimeRpc as c, onCancel as o, rpc as r };
|