goldstein 1.2.1 → 1.4.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 +18 -0
- package/README.md +15 -2
- package/bin/gs.js +4 -2
- package/package.json +3 -2
- package/packages/keyword-safe/index.js +45 -13
package/ChangeLog
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
2022.06.22, v1.4.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- goldstein: keyword safe: add support of VariableDeclaration
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2022.06.22, v1.3.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- goldstein: add support of safe await
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2022.06.22, v1.2.2
|
|
14
|
+
|
|
15
|
+
fix:
|
|
16
|
+
- goldstein: cli: add mainFields
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
2022.06.22, v1.2.1
|
|
2
20
|
|
|
3
21
|
fix:
|
package/README.md
CHANGED
|
@@ -122,14 +122,27 @@ function hello() {
|
|
|
122
122
|
Applies [`tryCatch`](https://github.com/coderaiser/try-catch):
|
|
123
123
|
|
|
124
124
|
```gs
|
|
125
|
-
safe hello(1, 2, 3);
|
|
125
|
+
const [error, result] = safe hello(1, 2, 3);
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
Is the same as:
|
|
129
129
|
|
|
130
130
|
```js
|
|
131
131
|
import tryCatch from 'try-catch';
|
|
132
|
-
tryCatch(1, 2, 3);
|
|
132
|
+
const [error, result] = tryCatch(1, 2, 3);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
and
|
|
136
|
+
|
|
137
|
+
```gs
|
|
138
|
+
const [error, result] = safe await hello(1, 2, 3);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Is the same as:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import tryToCatch from 'try-catch';
|
|
145
|
+
const [error, result] = await tryToCatch(1, 2, 3);
|
|
133
146
|
```
|
|
134
147
|
|
|
135
148
|
## How to contribute?
|
package/bin/gs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import esbuild from 'esbuild';
|
|
3
3
|
import {
|
|
4
4
|
readFileSync,
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
} from 'fs';
|
|
8
8
|
import {compile} from '../packages/goldstein/index.js';
|
|
9
9
|
|
|
10
|
+
const [arg] = process.argv.slice(2);
|
|
11
|
+
|
|
10
12
|
if (!arg) {
|
|
11
13
|
console.log('gs <filename>');
|
|
12
14
|
process.exit();
|
|
@@ -25,7 +27,7 @@ esbuild.buildSync({
|
|
|
25
27
|
bundle: true,
|
|
26
28
|
write: true,
|
|
27
29
|
outfile,
|
|
28
|
-
|
|
30
|
+
mainFields: ['main'],
|
|
29
31
|
});
|
|
30
32
|
|
|
31
33
|
unlinkSync(compiledName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"commitType": "colon",
|
|
6
6
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"acorn": "^8.7.1",
|
|
30
30
|
"esbuild": "^0.14.47",
|
|
31
|
-
"putout": "^26.17.0"
|
|
31
|
+
"putout": "^26.17.0",
|
|
32
|
+
"try-catch": "^3.0.1"
|
|
32
33
|
},
|
|
33
34
|
"license": "MIT",
|
|
34
35
|
"devDependencies": {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import {types} from 'putout';
|
|
1
2
|
import {
|
|
2
3
|
addKeyword,
|
|
3
4
|
TokenType,
|
|
4
5
|
} from '../operator/index.js';
|
|
5
6
|
|
|
7
|
+
const {
|
|
8
|
+
isCallExpression,
|
|
9
|
+
isAwaitExpression,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
6
12
|
// why not 'try'?
|
|
7
13
|
// because acorn internals should be copied, and added tests.
|
|
8
14
|
// there is no such thing as this.previous(), only this.next() 🤷
|
|
@@ -25,24 +31,50 @@ export default function newSpeak(Parser) {
|
|
|
25
31
|
|
|
26
32
|
return super.parseStatement(context, topLevel, exports);
|
|
27
33
|
}
|
|
34
|
+
parseExprAtom(refDestructuringErrors, forInit) {
|
|
35
|
+
if (this.type === keywordTypes.safe)
|
|
36
|
+
return this.parseSafe();
|
|
37
|
+
|
|
38
|
+
return super.parseExprAtom(refDestructuringErrors, forInit);
|
|
39
|
+
}
|
|
28
40
|
|
|
29
41
|
parseSafe() {
|
|
30
42
|
this.next();
|
|
31
43
|
|
|
32
44
|
const node = super.startNode();
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const expression = this.parseExpression();
|
|
46
|
+
|
|
47
|
+
if (isCallExpression(expression))
|
|
48
|
+
node.expression = {
|
|
49
|
+
type: 'CallExpression',
|
|
50
|
+
callee: {
|
|
51
|
+
type: 'Identifier',
|
|
52
|
+
name: 'tryCatch',
|
|
53
|
+
},
|
|
54
|
+
arguments: [
|
|
55
|
+
expression.callee,
|
|
56
|
+
...expression.arguments,
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
else if (isAwaitExpression(expression))
|
|
61
|
+
node.expression = {
|
|
62
|
+
type: 'AwaitExpression',
|
|
63
|
+
argument: {
|
|
64
|
+
type: 'CallExpression',
|
|
65
|
+
callee: {
|
|
66
|
+
type: 'Identifier',
|
|
67
|
+
name: 'tryToCatch',
|
|
68
|
+
},
|
|
69
|
+
arguments: [
|
|
70
|
+
expression.argument.callee,
|
|
71
|
+
...expression.argument.arguments,
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
else
|
|
77
|
+
this.raise(this.start, `After 'safe' only 'await' and 'function call' can come`);
|
|
46
78
|
|
|
47
79
|
return super.finishNode(node, 'ExpressionStatement');
|
|
48
80
|
}
|