goldstein 4.5.0 → 4.7.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,14 @@
1
+ 2023.10.04, v4.7.0
2
+
3
+ feature:
4
+ - 136f4a9 goldstein: convert: rm useless import of try-catch
5
+ - fcb8679 package: estree-to-babel v8.0.0
6
+
7
+ 2023.10.03, v4.6.0
8
+
9
+ feature:
10
+ - 04ca141 goldstein: export print, convert
11
+
1
12
  2023.10.03, v4.5.0
2
13
 
3
14
  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,47 @@ parse(`
163
163
  // returns Babel AST
164
164
  ```
165
165
 
166
+ You can parse to **ESTree**:
167
+
168
+ ```
169
+ const options = {
170
+ type: 'estree',
171
+ };
172
+
173
+ parse(`
174
+ fn hello() {
175
+ guard text !== "world" else {
176
+ return ""
177
+ }
178
+
179
+ return "Hello " + text
180
+ `, options);
181
+ ```
182
+
183
+ ### `print(ast)`
184
+
185
+ You can make any modifications to **Goldstein AST** and then `print` back to **Goldstein**:
186
+
187
+ ```
188
+ import {parse, print} from 'goldstein';
189
+
190
+ const ast = parse(`const t = try f('hello')`);
191
+ const source = print(ast);
192
+ ```
193
+
194
+ ### `convert(source)`
195
+
196
+ You can even convert **JavaScript** to **Goldstein** with:
197
+
198
+ ```
199
+ import {convert} from 'goldstein';
200
+
201
+ const ast = convert(`const t = tryCatch(f, 'hello');`;
202
+
203
+ // returns
204
+ `const t = try f('hello')`)
205
+ ```
206
+
166
207
  ## Keywords
167
208
 
168
209
  **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.7.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "JavaScript with no limits",
@@ -36,13 +36,14 @@
36
36
  "acorn": "^8.7.1",
37
37
  "esbuild": "^0.19.2",
38
38
  "esbuild-node-builtins": "^0.1.0",
39
- "estree-to-babel": "^7.0.0",
39
+ "estree-to-babel": "^8.0.0",
40
40
  "putout": "^32.0.1",
41
41
  "try-catch": "^3.0.1"
42
42
  },
43
43
  "license": "MIT",
44
44
  "devDependencies": {
45
45
  "@cloudcmd/stub": "^4.0.1",
46
+ "@putout/test": "^7.1.0",
46
47
  "c8": "^8.0.0",
47
48
  "check-dts": "^0.7.1",
48
49
  "escover": "^3.4.0",
@@ -1,6 +1,7 @@
1
1
  import estreeToBabel from 'estree-to-babel';
2
2
  import {transform} from 'putout';
3
3
  import {print} from '../printer/index.js';
4
+ import * as removeImportTry from './remove-import-try/index.js';
4
5
  import * as applyTry from './apply-try/index.js';
5
6
  import {
6
7
  fixEmpty,
@@ -13,6 +14,7 @@ export const convert = (source) => {
13
14
  transform(ast, source, {
14
15
  plugins: [
15
16
  ['apply-try', applyTry],
17
+ ['remove-import-try', removeImportTry],
16
18
  ],
17
19
  });
18
20
 
@@ -0,0 +1,7 @@
1
+ export const report = () => `Remove import of 'tryCatch/tryToCatch'`;
2
+ export const replace = () => ({
3
+ 'import tryCatch from "try-catch"': '',
4
+ 'import tryToCatch from "try-to-catch"': '',
5
+ 'const tryCatch = require("try-catch")': '',
6
+ 'const tryToCatch = require("try-to-catch")': '',
7
+ });
@@ -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';