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 +5 -0
- package/README.md +41 -1
- package/package.json +1 -1
- package/packages/goldstein/index.js +1 -0
- package/packages/goldstein/parser.js +0 -1
package/ChangeLog
CHANGED
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