goldstein 2.1.0 → 2.2.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.27, v2.2.0
2
+
3
+ feature:
4
+ - goldstein: add support of throw expressions
5
+
6
+
1
7
  2022.06.25, v2.1.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -176,6 +176,14 @@ if a > 3 {
176
176
  }
177
177
  ```
178
178
 
179
+ ### `throw expression`
180
+
181
+ You can use [throw as expression](https://github.com/tc39/proposal-throw-expressions), just like that:
182
+
183
+ ```js
184
+ const a = () => throw 'hello';
185
+ ```
186
+
179
187
  ## How to contribute?
180
188
 
181
189
  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": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "commitType": "colon",
6
6
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
@@ -6,6 +6,7 @@ import keywordFn from '../keyword-fn/index.js';
6
6
  import keywordGuard from '../keyword-guard/index.js';
7
7
  import keywordTry from '../keyword-try/index.js';
8
8
  import keywordShould from '../keyword-should/index.js';
9
+ import keywordThrow from '../keyword-throw/index.js';
9
10
  import stringInterpolation from '../string-interpolation/index.js';
10
11
 
11
12
  export const compile = (source) => {
@@ -14,6 +15,7 @@ export const compile = (source) => {
14
15
  keywordGuard,
15
16
  keywordTry,
16
17
  keywordShould,
18
+ keywordThrow,
17
19
  stringInterpolation,
18
20
  ]);
19
21
 
@@ -0,0 +1,30 @@
1
+ const {assign} = Object;
2
+
3
+ export default function keywordThrow(Parser) {
4
+ const {keywordTypes} = Parser.acorn;
5
+
6
+ return class extends Parser {
7
+ parseExprAtom(refDestructuringErrors, forInit) {
8
+ if (this.type === keywordTypes.throw) {
9
+ return this.parseThrowExpression();
10
+ }
11
+
12
+ return super.parseExprAtom(refDestructuringErrors, forInit);
13
+ }
14
+
15
+ parseThrowExpression() {
16
+ this.next();
17
+
18
+ const node = super.startNode();
19
+ const expression = this.parseExpression();
20
+
21
+ assign(node, {
22
+ operator: 'throw',
23
+ argument: expression,
24
+ });
25
+
26
+ return super.finishNode(node, 'UnaryExpression');
27
+ }
28
+ };
29
+ }
30
+