goldstein 4.5.0 → 4.6.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/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2023.10.03, v4.6.0
2
+
3
+ feature:
4
+ - 04ca141 goldstein: export print, convert
5
+
1
6
  2023.10.03, v4.5.0
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -143,7 +143,7 @@ function hello() {
143
143
 
144
144
  You can declare variables with [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare).
145
145
 
146
- ### `parse(source)`
146
+ ### `parse(source, {type, keywords})`
147
147
 
148
148
  When you need to get **JavaScript** Babel AST use `parse`:
149
149
 
@@ -163,6 +163,46 @@ parse(`
163
163
  // returns Babel AST
164
164
  ```
165
165
 
166
+ You can parse to **ESTree**:
167
+ ```
168
+ const options = {
169
+ type: 'estree',
170
+ };
171
+
172
+ parse(`
173
+ fn hello() {
174
+ guard text !== "world" else {
175
+ return ""
176
+ }
177
+
178
+ return "Hello " + text
179
+ `, options);
180
+ ```
181
+
182
+ ### `print(ast)`
183
+
184
+ You can make any modifications to **Goldstein AST** and then `print` back to **Goldstein**:
185
+
186
+ ```
187
+ import {parse, print} from 'goldstein';
188
+
189
+ const ast = parse(`const t = try f('hello')`);
190
+ const source = print(ast);
191
+ ```
192
+
193
+ ### `convert(source)`
194
+
195
+ You can even convert **JavaScript** to **Goldstein** with:
196
+
197
+ ```
198
+ import {convert} from 'goldstein';
199
+
200
+ const ast = convert(`const t = tryCatch(f, 'hello');`;
201
+
202
+ // returns
203
+ `const t = try f('hello')`)
204
+ ```
205
+
166
206
  ## Keywords
167
207
 
168
208
  **Goldstein** is absolutely compatible with JavaScript, and it has extensions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "JavaScript with no limits",
@@ -7,6 +7,7 @@ import {parse} from './parser.js';
7
7
 
8
8
  export * from './parser.js';
9
9
  export {print} from '../printer/index.js';
10
+ export {convert} from '../convert/index.js';
10
11
  export const compile = (source, options = {}) => {
11
12
  const ast = parse(source, options);
12
13
 
@@ -1,5 +1,4 @@
1
1
  import estreeToBabel from 'estree-to-babel';
2
-
3
2
  import {extendParser} from '../parser/index.js';
4
3
  import keywordFn from '../keyword-fn/index.js';
5
4
  import keywordGuard from '../keyword-guard/index.js';