vba-interpreter 0.0.0-stage → 0.1.0
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 +202 -0
- package/README.md +96 -2
- package/dist/contract-CBGNXslV.d.ts +226 -0
- package/dist/exec/index.d.ts +12 -0
- package/dist/exec/index.js +1 -0
- package/dist/exec-DYWJe-eU.js +306 -0
- package/dist/exec-DYWJe-eU.js.map +1 -0
- package/dist/index-DnrotnmB.d.ts +2015 -0
- package/dist/index-DtaSNo0V.d.ts +111 -0
- package/dist/index-DyoT9JOJ.d.ts +4 -0
- package/dist/index-gM7FYTaq.d.ts +1353 -0
- package/dist/index-zKYgEJdV.d.ts +900 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +3 -0
- package/dist/interp/index.d.ts +10 -0
- package/dist/interp/index.js +1 -0
- package/dist/interp-ChrsgBCf.js +3433 -0
- package/dist/interp-ChrsgBCf.js.map +1 -0
- package/dist/lang/index.d.ts +10 -0
- package/dist/lang/index.js +1 -0
- package/dist/lang-Bo63dJb9.js +4740 -0
- package/dist/lang-Bo63dJb9.js.map +1 -0
- package/dist/runtime/index.d.ts +33 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime-C8-PPxmH.js +8284 -0
- package/dist/runtime-C8-PPxmH.js.map +1 -0
- package/dist/semantic/index.d.ts +12 -0
- package/dist/semantic/index.js +1 -0
- package/dist/semantic-CAVxm72C.js +2877 -0
- package/dist/semantic-CAVxm72C.js.map +1 -0
- package/package.json +91 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025-present pptx-viewer contributors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vba-interpreter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/vba-interpreter)
|
|
4
|
+
[](https://github.com/ChristopherVR/vba-interpreter/actions/workflows/ci.yml)
|
|
5
|
+
[](https://christophervr.github.io/vba-interpreter/)
|
|
6
|
+
|
|
7
|
+
Read, check and run VBA macros in JavaScript, without Office and without giving them access to
|
|
8
|
+
the machine.
|
|
9
|
+
|
|
10
|
+
**[Documentation](https://christophervr.github.io/vba-interpreter/)** | [Your first macro](https://christophervr.github.io/vba-interpreter/guide/getting-started) |
|
|
11
|
+
[Playground](https://christophervr.github.io/vba-interpreter/playground) | [API reference](https://christophervr.github.io/vba-interpreter/api/)
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install vba-interpreter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Node 22 or later, Bun and modern browsers. ESM, no dependencies, TypeScript types included.
|
|
20
|
+
|
|
21
|
+
## 30-second example
|
|
22
|
+
|
|
23
|
+
A macro that talks to an object you write in TypeScript, with its `Debug.Print` output collected:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createInterpreter } from 'vba-interpreter';
|
|
27
|
+
import { hostClass, toStr, vStr, type Value } from 'vba-interpreter/runtime';
|
|
28
|
+
|
|
29
|
+
// A tiny host object: `Greeter.Name` is a read/write property.
|
|
30
|
+
const makeGreeter = hostClass<{ name: string }>({
|
|
31
|
+
name: 'Greeter',
|
|
32
|
+
members: {
|
|
33
|
+
Name: {
|
|
34
|
+
get: (state) => vStr(state.name),
|
|
35
|
+
let: (state, _args, value: Value) => {
|
|
36
|
+
state.name = toStr(value);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const output: string[] = [];
|
|
43
|
+
const program = createInterpreter({
|
|
44
|
+
modules: [
|
|
45
|
+
{
|
|
46
|
+
name: 'Module1',
|
|
47
|
+
kind: 'standard',
|
|
48
|
+
source: [
|
|
49
|
+
'Sub Hello()',
|
|
50
|
+
' Greeter.Name = "VBA"',
|
|
51
|
+
' Debug.Print "Hello, " & Greeter.Name; 6 * 7',
|
|
52
|
+
'End Sub',
|
|
53
|
+
].join('\r\n'),
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
globals: { Greeter: makeGreeter({ name: '' }) },
|
|
57
|
+
session: { debug: { print: (line) => output.push(line) } },
|
|
58
|
+
limits: { maxMillis: 2_000 },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = await program.run('Hello');
|
|
62
|
+
console.log(result.status, output);
|
|
63
|
+
program.dispose();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
completed ["Hello, VBA 42 "]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## What you can do
|
|
71
|
+
|
|
72
|
+
| You want to | You use |
|
|
73
|
+
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
74
|
+
| Check a document's macros before trusting it | `listProcedures` flags code that runs on open, like `Auto_Open` ([guide](https://christophervr.github.io/vba-interpreter/guide/security#before-you-run-anything)) |
|
|
75
|
+
| Run macros against your own objects | `createInterpreter` with host objects such as `Range` ([guide](https://christophervr.github.io/vba-interpreter/guide/host-objects)) |
|
|
76
|
+
| Contain untrusted code | Step, time, memory and depth limits, cancelling, no file or network access ([guide](https://christophervr.github.io/vba-interpreter/guide/security)) |
|
|
77
|
+
|
|
78
|
+
There is no `eval` or `new Function` anywhere: source is parsed and interpreted. Sizes are capped
|
|
79
|
+
per value (one string, one array), not in total, so run untrusted macros in a Worker you can
|
|
80
|
+
terminate. Calls that would
|
|
81
|
+
leave the sandbox (`Shell`, `CreateObject`, `Declare`, file I/O) raise the error a VBA user
|
|
82
|
+
would recognise.
|
|
83
|
+
|
|
84
|
+
## Compatibility
|
|
85
|
+
|
|
86
|
+
The interpreter gives exactly the output Excel gave on **183 of 183** macros of its conformance corpus, captured
|
|
87
|
+
from real Excel through its documented COM automation. The [compatibility page](https://christophervr.github.io/vba-interpreter/guide/compatibility)
|
|
88
|
+
lists what is supported, the known gaps and what is refused.
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
Issues and pull requests are welcome; see the [contributing guide](https://christophervr.github.io/vba-interpreter/contributing). Every code
|
|
93
|
+
example on the documentation site is a tested file in `docs/examples`.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[Apache-2.0](LICENSE)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { F as ModuleKind, O as VbaDiagnostic, a as ProcedureInfo } from "./index-gM7FYTaq.js";
|
|
2
|
+
import { $a as DebugSink, Yo as Value, hc as VbaLimits, io as VbaUi, js as Ref, sc as VbaLocale, ys as VbaObject } from "./index-DnrotnmB.js";
|
|
3
|
+
/** One module of a project, as source text (a decompressed module stream or an exported file). */
|
|
4
|
+
interface VbaSourceModule {
|
|
5
|
+
/** The module name (`Module1`, `ThisWorkbook`, `Class1`); `VB_Name` in the source is ignored. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/** Standard, class or document module (form modules run as class code). */
|
|
8
|
+
readonly kind: ModuleKind;
|
|
9
|
+
/** The module's source text, with or without its `Attribute` lines. */
|
|
10
|
+
readonly source: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The session a run uses: everything outside the program that VBA's library reads. Missing fields
|
|
14
|
+
* take safe defaults: no UI (MsgBox and InputBox raise error 445), Debug.Print discarded, en-US,
|
|
15
|
+
* the real clock, no environment variables, project name "VBAProject".
|
|
16
|
+
*/
|
|
17
|
+
interface VbaSessionOptions {
|
|
18
|
+
/** Shows `MsgBox` and `InputBox`; without it both raise error 445. */
|
|
19
|
+
readonly ui: VbaUi;
|
|
20
|
+
/** Receives `Debug.Print` lines and failed `Debug.Assert`s. */
|
|
21
|
+
readonly debug: DebugSink;
|
|
22
|
+
/** Regional settings for conversions, `Format`, dates and `Option Compare Text`. */
|
|
23
|
+
readonly locale: VbaLocale;
|
|
24
|
+
/** The current instant, read by `Now`, `Date`, `Time` and `Timer`. */
|
|
25
|
+
readonly clock: () => Date;
|
|
26
|
+
/** Answers `Environ(name)`; undefined reads as an empty string. */
|
|
27
|
+
readonly environ: (name: string) => string | undefined;
|
|
28
|
+
/** The project name, the default `Err.Source`. */
|
|
29
|
+
readonly projectName: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Execution bounds on top of the runtime's allocation limits. Every run (and every host callback,
|
|
33
|
+
* see `VbaProgram`) gets the whole budget. `maxCallDepth` (error 28 beyond it) defaults to 1000
|
|
34
|
+
* here, under the runtime's 2000: an interpreter frame takes several JavaScript frames, and Node's
|
|
35
|
+
* default stack holds about 900 of them. An executor also reports a JavaScript stack overflow as
|
|
36
|
+
* error 28, so a deep recursion on a small stack ends the same way, only earlier.
|
|
37
|
+
*/
|
|
38
|
+
interface VbaExecLimits extends VbaLimits {
|
|
39
|
+
/** Most statements (and loop iterations) one run may execute. */
|
|
40
|
+
readonly maxSteps: number;
|
|
41
|
+
/**
|
|
42
|
+
* Wall-clock budget of one run, in milliseconds. Checked every few milliseconds and after
|
|
43
|
+
* every big runtime operation, so a run overshoots it by about one operation at most.
|
|
44
|
+
*/
|
|
45
|
+
readonly maxMillis: number;
|
|
46
|
+
}
|
|
47
|
+
/** The default limits: the runtime's `DEFAULT_LIMITS`, 50 million steps and 30 seconds. */
|
|
48
|
+
declare const DEFAULT_EXEC_LIMITS: VbaExecLimits;
|
|
49
|
+
/** Everything a `CompileVba` needs: the source, the host's objects, the session and limits. */
|
|
50
|
+
interface VbaProgramOptions {
|
|
51
|
+
/** The project's modules, as source text. */
|
|
52
|
+
readonly modules: readonly VbaSourceModule[];
|
|
53
|
+
/** Host objects by name (`Application`, `ThisWorkbook`, `Sheet1`): readable from every module. */
|
|
54
|
+
readonly globals?: Readonly<Record<string, VbaObject>>;
|
|
55
|
+
/**
|
|
56
|
+
* An object whose members resolve as unqualified names (Excel's `Range("A1")`, `Cells`,
|
|
57
|
+
* `ActiveSheet`). Names declared in the project or VBA's library come first; an undeclared name
|
|
58
|
+
* is looked up on this object at run time (error 438 there means an undeclared variable).
|
|
59
|
+
*/
|
|
60
|
+
readonly globalObject?: VbaObject;
|
|
61
|
+
/**
|
|
62
|
+
* Document module name -> the host object it extends (`ThisWorkbook` -> the Workbook). In that
|
|
63
|
+
* module `Me` is the host object and its members resolve as unqualified names before the
|
|
64
|
+
* `globalObject`'s, and its public procedures are reachable as `ThisWorkbook.Foo`.
|
|
65
|
+
*/
|
|
66
|
+
readonly documentObjects?: Readonly<Record<string, VbaObject>>;
|
|
67
|
+
/** The UI, debug sink, locale, clock and environment; missing fields take safe defaults. */
|
|
68
|
+
readonly session?: Partial<VbaSessionOptions>;
|
|
69
|
+
/** Overrides of `DEFAULT_EXEC_LIMITS`. */
|
|
70
|
+
readonly limits?: Partial<VbaExecLimits>;
|
|
71
|
+
/** `#Const` values for conditional compilation, merged over the lang defaults. */
|
|
72
|
+
readonly constants?: Readonly<Record<string, number | string | boolean>>;
|
|
73
|
+
/**
|
|
74
|
+
* Cancels every run of the program: a running macro stops with status `cancel`. A loop that
|
|
75
|
+
* never waits on its host sees the signal only when it yields (`yieldMillis`); use
|
|
76
|
+
* `isCancelled` to stop it at once from another thread.
|
|
77
|
+
*/
|
|
78
|
+
readonly signal?: AbortSignal;
|
|
79
|
+
/**
|
|
80
|
+
* Read synchronously every few milliseconds while a run computes: return true to cancel it.
|
|
81
|
+
* For a host whose controller is on another thread (`() => Atomics.load(flags, 0) !== 0`).
|
|
82
|
+
* The hard stop for a runaway macro is still the host's `Worker.terminate()`.
|
|
83
|
+
*/
|
|
84
|
+
readonly isCancelled?: () => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* A run that computes this long without waiting yields to the event loop once (so timers,
|
|
87
|
+
* messages and an AbortSignal of the same thread are seen). 0 never yields. Default 100.
|
|
88
|
+
*/
|
|
89
|
+
readonly yieldMillis?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A compile error or warning, with the module it was found in. `code` is a parser code
|
|
93
|
+
* (`VbaDiagnostic['code']`) or a binder code (`SemanticDiagnosticCode` of vba-interpreter/semantic).
|
|
94
|
+
*/
|
|
95
|
+
interface VbaProgramDiagnostic extends Omit<VbaDiagnostic, 'code'> {
|
|
96
|
+
/** The parser or binder code, for example `variable-not-defined`. */
|
|
97
|
+
readonly code: string;
|
|
98
|
+
/** The name of the module the diagnostic was found in. */
|
|
99
|
+
readonly module: string;
|
|
100
|
+
}
|
|
101
|
+
/** A procedure of the project, as the Macros dialog and `run` see it. */
|
|
102
|
+
interface VbaProcedure extends ProcedureInfo {
|
|
103
|
+
/** The name of the module that declares the procedure. */
|
|
104
|
+
readonly module: string;
|
|
105
|
+
/** The kind of that module. */
|
|
106
|
+
readonly moduleKind: ModuleKind;
|
|
107
|
+
/**
|
|
108
|
+
* False when the procedure's module, or a module whose procedures it calls, has compile
|
|
109
|
+
* errors: running it gives status `compile` (VBA compiles a module when it is first used).
|
|
110
|
+
*/
|
|
111
|
+
readonly canRun: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** One procedure an error passed through, innermost first. */
|
|
114
|
+
interface VbaStackFrame {
|
|
115
|
+
/** The module of the procedure. */
|
|
116
|
+
readonly module: string;
|
|
117
|
+
/** The procedure's name. */
|
|
118
|
+
readonly procedure: string;
|
|
119
|
+
/** 1-based source line and column of the statement running in that procedure. */
|
|
120
|
+
readonly line: number;
|
|
121
|
+
/** 1-based source column of that statement. */
|
|
122
|
+
readonly column: number;
|
|
123
|
+
}
|
|
124
|
+
/** An error that ended a run: a compile error or an unhandled run-time error. */
|
|
125
|
+
interface VbaRunError {
|
|
126
|
+
/** The VBA error number (`Err.Number`); 0 for a compile error, which has none. */
|
|
127
|
+
readonly number: number;
|
|
128
|
+
/** `Err.Description`, or the compile error's message. */
|
|
129
|
+
readonly description: string;
|
|
130
|
+
/** `Err.Source`. */
|
|
131
|
+
readonly source?: string;
|
|
132
|
+
/** Where the error was raised (the innermost entry of `stack`), when known. */
|
|
133
|
+
readonly module?: string;
|
|
134
|
+
/** The procedure where the error was raised, when known. */
|
|
135
|
+
readonly procedure?: string;
|
|
136
|
+
/** The 1-based source line where the error was raised, when known. */
|
|
137
|
+
readonly line?: number;
|
|
138
|
+
/** The 1-based source column where the error was raised, when known. */
|
|
139
|
+
readonly column?: number;
|
|
140
|
+
/** The procedures the error left, innermost first, at most 64 (empty for a compile error). */
|
|
141
|
+
readonly stack?: readonly VbaStackFrame[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* How a run ended:
|
|
145
|
+
* - `completed`: the procedure returned;
|
|
146
|
+
* - `end`: an `End` statement (every module variable is reset);
|
|
147
|
+
* - `stop`: a `Stop` statement (there is no debugger, so the run halts);
|
|
148
|
+
* - `compile`: the procedure cannot run because of a compile error (`error`);
|
|
149
|
+
* - `runtime`: an unhandled run-time error (`error`), including error 28 at the call depth limit;
|
|
150
|
+
* - `limit`: the step or time budget ran out (`message`);
|
|
151
|
+
* - `cancel`: the signal or `isCancelled` stopped it (`message`).
|
|
152
|
+
*/
|
|
153
|
+
type VbaRunStatus = 'completed' | 'end' | 'stop' | 'compile' | 'runtime' | 'limit' | 'cancel';
|
|
154
|
+
/** How a `run`, `fireEvent` or host callback ended. */
|
|
155
|
+
interface VbaRunResult {
|
|
156
|
+
/** How the run ended. */
|
|
157
|
+
readonly status: VbaRunStatus;
|
|
158
|
+
/** True for `completed`, `end` and `stop`. */
|
|
159
|
+
readonly ok: boolean;
|
|
160
|
+
/** A Function's or Property Get's result (`completed` only; absent for a Sub). */
|
|
161
|
+
readonly value?: Value;
|
|
162
|
+
/** For `compile` and `runtime`. */
|
|
163
|
+
readonly error?: VbaRunError;
|
|
164
|
+
/** For `limit` and `cancel`: what ran out or who cancelled. */
|
|
165
|
+
readonly message?: string;
|
|
166
|
+
/** Statements executed, for diagnostics and benchmarks. */
|
|
167
|
+
readonly steps?: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* What a host receives when it calls a member of an object the program made (a class instance it
|
|
171
|
+
* kept, a WithEvents handler it fired) outside a run and the call fails: an Error whose `result`
|
|
172
|
+
* says how. Inside a run, the program's own errors reach the host as `VbaRuntimeError`s.
|
|
173
|
+
*/
|
|
174
|
+
interface VbaCallbackError extends Error {
|
|
175
|
+
/** How the failed callback ended. */
|
|
176
|
+
readonly result: VbaRunResult;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A compiled VBA project, ready to run its procedures and event handlers. Module variables live
|
|
180
|
+
* as long as the program, so successive runs share them. Not here yet: an Immediate-window
|
|
181
|
+
* `evaluate`/`execute` of a statement typed against the running project (it needs a binder for
|
|
182
|
+
* one statement in a chosen scope); hosts run a generated module instead.
|
|
183
|
+
*/
|
|
184
|
+
interface VbaProgram {
|
|
185
|
+
/** Compile errors in VBA's wording. A module with errors (or that uses one) cannot run. */
|
|
186
|
+
readonly diagnostics: readonly VbaProgramDiagnostic[];
|
|
187
|
+
/** True while a run or a host callback is in progress. */
|
|
188
|
+
readonly isRunning: boolean;
|
|
189
|
+
/** Every procedure of every module; filter on `isMacro` for the Macros dialog. */
|
|
190
|
+
procedures(): VbaProcedure[];
|
|
191
|
+
/**
|
|
192
|
+
* Runs a procedure: `Module1.Foo` or an unambiguous `Foo` (`Sheet1.Foo` for a document
|
|
193
|
+
* module). Arguments are passed ByVal. Module variables keep their values between runs, as in
|
|
194
|
+
* VBA, until `End`, `reset` or `dispose`.
|
|
195
|
+
*
|
|
196
|
+
* Runs, events and host callbacks are serialised: one waits for the one in progress. A call
|
|
197
|
+
* made while a run computes (synchronously, from a host member the macro called, as
|
|
198
|
+
* `Application.Run` or an event the host raises at once) runs inside that run instead.
|
|
199
|
+
*
|
|
200
|
+
* Objects the program made (class instances, WithEvents handlers) can be called by the host
|
|
201
|
+
* at any time through the host object protocol, under the same rule: inside the computing
|
|
202
|
+
* run, else as a run of its own with the same limits, cancel and queue, whose failure reaches
|
|
203
|
+
* the host as a `VbaCallbackError`. While a run waits on its host (a member returned a
|
|
204
|
+
* Promise), every call into the program queues behind it: a host member that must call back
|
|
205
|
+
* into the program does so before it returns its Promise, or does not wait for the callback.
|
|
206
|
+
*/
|
|
207
|
+
run(name: string, args?: readonly Value[]): Promise<VbaRunResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Runs a document module's event handler: `fireEvent('ThisWorkbook', 'Open', [])` runs
|
|
210
|
+
* `Workbook_Open` (the prefix is the host object's `typeName()`). `args` are references, so a
|
|
211
|
+
* handler can set `Cancel = True` (`refsOf` makes them). A missing handler is not an error.
|
|
212
|
+
*/
|
|
213
|
+
fireEvent(objectName: string, event: string, args: readonly Ref[]): Promise<VbaRunResult>;
|
|
214
|
+
/**
|
|
215
|
+
* The VBE's Reset: module variables and Static locals back to their initial values, default
|
|
216
|
+
* instances dropped, WithEvents disconnected. Waits for the run in progress.
|
|
217
|
+
*/
|
|
218
|
+
reset(): Promise<void>;
|
|
219
|
+
/** Resets and disconnects everything. Later calls fail with error 51. */
|
|
220
|
+
dispose(): void;
|
|
221
|
+
}
|
|
222
|
+
/** Builds a runnable program from source modules (the interpreter's `createInterpreter`). */
|
|
223
|
+
type CompileVba = (options: VbaProgramOptions) => VbaProgram;
|
|
224
|
+
/** References for `fireEvent`: read `refs[i].get()` after the handler to see what it set. */
|
|
225
|
+
declare function refsOf(values: readonly Value[]): Ref[];
|
|
226
|
+
export { VbaProcedure as a, VbaProgramOptions as c, VbaRunStatus as d, VbaSessionOptions as f, refsOf as h, VbaExecLimits as i, VbaRunError as l, VbaStackFrame as m, DEFAULT_EXEC_LIMITS as n, VbaProgram as o, VbaSourceModule as p, VbaCallbackError as r, VbaProgramDiagnostic as s, CompileVba as t, VbaRunResult as u };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `import { ... } from 'vba-interpreter/exec'`
|
|
3
|
+
*
|
|
4
|
+
* The executor contract shared by the interpreter and the VBA-to-JavaScript compiler, with the
|
|
5
|
+
* pieces both use: the limit guard, the mapping of a run's ending to its result, the compile gate
|
|
6
|
+
* and the normalisation of host scopes.
|
|
7
|
+
*
|
|
8
|
+
* @module exec
|
|
9
|
+
*/
|
|
10
|
+
import { a as VbaProcedure, c as VbaProgramOptions, d as VbaRunStatus, f as VbaSessionOptions, h as refsOf, i as VbaExecLimits, l as VbaRunError, m as VbaStackFrame, n as DEFAULT_EXEC_LIMITS, o as VbaProgram, p as VbaSourceModule, r as VbaCallbackError, s as VbaProgramDiagnostic, t as CompileVba, u as VbaRunResult } from "../contract-CBGNXslV.js";
|
|
11
|
+
import { a as compileFailure, c as notRun, d as LimitGuard, f as normalizeDocumentObjects, i as VbaStop, l as outcomeOf, n as VbaCallbackFailure, o as completed, p as CompileGate, r as VbaCompileError, s as isTrappable, t as RunFacts, u as CancelSources } from "../index-DtaSNo0V.js";
|
|
12
|
+
export { type CancelSources, CompileGate, CompileVba, DEFAULT_EXEC_LIMITS, LimitGuard, type RunFacts, VbaCallbackError, VbaCallbackFailure, VbaCompileError, VbaExecLimits, VbaProcedure, VbaProgram, VbaProgramDiagnostic, VbaProgramOptions, VbaRunError, VbaRunResult, VbaRunStatus, VbaSessionOptions, VbaSourceModule, VbaStackFrame, VbaStop, compileFailure, completed, isTrappable, normalizeDocumentObjects, notRun, outcomeOf, refsOf };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { d as CompileGate, f as DEFAULT_EXEC_LIMITS, l as LimitGuard, t as VbaCallbackFailure, n as VbaCompileError, r as VbaStop, i as compileFailure, a as completed, o as isTrappable, u as normalizeDocumentObjects, s as notRun, c as outcomeOf, p as refsOf } from "../exec-DYWJe-eU.js";
|