goldstein 1.2.2 → 1.3.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,9 @@
1
+ 2022.06.22, v1.3.0
2
+
3
+ feature:
4
+ - goldstein: add support of safe await
5
+
6
+
1
7
  2022.06.22, v1.2.2
2
8
 
3
9
  fix:
package/README.md CHANGED
@@ -132,6 +132,19 @@ import tryCatch from 'try-catch';
132
132
  tryCatch(1, 2, 3);
133
133
  ```
134
134
 
135
+ and
136
+
137
+ ```gs
138
+ safe await hello(1, 2, 3);
139
+ ```
140
+
141
+ Is the same as:
142
+
143
+ ```js
144
+ import tryToCatch from 'try-catch';
145
+ await tryToCatch(1, 2, 3);
146
+ ```
147
+
135
148
  ## How to contribute?
136
149
 
137
150
  Clone the registry, create a new keyword with a prefix `keyword-`, then create directory `fixture` and put there two files with extensions `.js` and `.gs`. Half way done 🥳!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "1.2.2",
3
+ "version": "1.3.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() 🤷‍
@@ -30,19 +36,39 @@ export default function newSpeak(Parser) {
30
36
  this.next();
31
37
 
32
38
  const node = super.startNode();
33
- const callExpression = this.parseExpression();
39
+ const expression = this.parseExpression();
40
+
41
+ if (isCallExpression(expression))
42
+ node.expression = {
43
+ type: 'CallExpression',
44
+ callee: {
45
+ type: 'Identifier',
46
+ name: 'tryCatch',
47
+ },
48
+ arguments: [
49
+ expression.callee,
50
+ ...expression.arguments,
51
+ ],
52
+ };
53
+
54
+ else if (isAwaitExpression(expression))
55
+ node.expression = {
56
+ type: 'AwaitExpression',
57
+ argument: {
58
+ type: 'CallExpression',
59
+ callee: {
60
+ type: 'Identifier',
61
+ name: 'tryToCatch',
62
+ },
63
+ arguments: [
64
+ expression.argument.callee,
65
+ ...expression.argument.arguments,
66
+ ],
67
+ },
68
+ };
34
69
 
35
- node.expression = {
36
- type: 'CallExpression',
37
- callee: {
38
- type: 'Identifier',
39
- name: 'tryCatch',
40
- },
41
- arguments: [
42
- callExpression.callee,
43
- ...callExpression.arguments,
44
- ],
45
- };
70
+ else
71
+ this.raise(this.start, `After 'safe' only 'await' and 'function call' can come`);
46
72
 
47
73
  return super.finishNode(node, 'ExpressionStatement');
48
74
  }