goldstein 1.3.0 → 1.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 +18 -0
- package/README.md +15 -5
- package/package.json +1 -1
- package/packages/keyword-guard/index.js +6 -2
- package/packages/keyword-if/index.js +27 -0
- package/packages/keyword-safe/index.js +6 -0
package/ChangeLog
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
2022.06.22, v1.6.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- goldstein: guard keyword: add ability to omit parens
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2022.06.22, v1.5.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- goldstein: keyword if: add ability to omit parens
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2022.06.22, v1.4.0
|
|
14
|
+
|
|
15
|
+
feature:
|
|
16
|
+
- goldstein: keyword safe: add support of VariableDeclaration
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
2022.06.22, v1.3.0
|
|
2
20
|
|
|
3
21
|
feature:
|
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ Applies not to `IfCondition`:
|
|
|
97
97
|
|
|
98
98
|
```gs
|
|
99
99
|
fn hello() {
|
|
100
|
-
guard
|
|
100
|
+
guard text !== "world" else {
|
|
101
101
|
return ""
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -122,27 +122,37 @@ 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
133
|
```
|
|
134
134
|
|
|
135
135
|
and
|
|
136
136
|
|
|
137
137
|
```gs
|
|
138
|
-
safe await hello(1, 2, 3);
|
|
138
|
+
const [error, result] = safe await hello(1, 2, 3);
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
Is the same as:
|
|
142
142
|
|
|
143
143
|
```js
|
|
144
144
|
import tryToCatch from 'try-catch';
|
|
145
|
-
await tryToCatch(1, 2, 3);
|
|
145
|
+
const [error, result] = await tryToCatch(1, 2, 3);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `if`
|
|
149
|
+
|
|
150
|
+
You can omit parens. But you must use braces in this case.
|
|
151
|
+
|
|
152
|
+
```gs
|
|
153
|
+
if a > 3 {
|
|
154
|
+
hello();
|
|
155
|
+
}
|
|
146
156
|
```
|
|
147
157
|
|
|
148
158
|
## How to contribute?
|
package/package.json
CHANGED
|
@@ -33,7 +33,7 @@ export default function newSpeak(Parser) {
|
|
|
33
33
|
} = tokTypes;
|
|
34
34
|
|
|
35
35
|
const node = super.startNode();
|
|
36
|
-
super.
|
|
36
|
+
const isParenL = super.eat(parenL);
|
|
37
37
|
|
|
38
38
|
node.test = {
|
|
39
39
|
type: 'UnaryExpression',
|
|
@@ -42,7 +42,11 @@ export default function newSpeak(Parser) {
|
|
|
42
42
|
argument: super.parseExpression(),
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
super.
|
|
45
|
+
const isParenR = super.eat(parenR);
|
|
46
|
+
|
|
47
|
+
if (isParenL !== isParenR)
|
|
48
|
+
this.raise(this.start, `Use both parens ('(', ')') or none`);
|
|
49
|
+
|
|
46
50
|
super.expect(_else);
|
|
47
51
|
|
|
48
52
|
node.consequent = this.parseStatement();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tokTypes as tt,
|
|
3
|
+
} from '../operator/index.js';
|
|
4
|
+
|
|
5
|
+
export default function fn(Parser) {
|
|
6
|
+
return class extends Parser {
|
|
7
|
+
parseIfStatement(node) {
|
|
8
|
+
this.next();
|
|
9
|
+
|
|
10
|
+
const isParenL = this.eat(tt.parenL);
|
|
11
|
+
node.test = this.parseExpression();
|
|
12
|
+
const isParenR = this.eat(tt.parenR);
|
|
13
|
+
|
|
14
|
+
if (!isParenL && !isParenR && this.type !== tt.braceL)
|
|
15
|
+
this.raise(this.start, `Use braces ('{', '}') when omit parens ('(', ')')`);
|
|
16
|
+
|
|
17
|
+
if (isParenL !== isParenR)
|
|
18
|
+
this.raise(this.start, `Use both parens ('(', ')') or none`);
|
|
19
|
+
|
|
20
|
+
node.consequent = this.parseStatement('if');
|
|
21
|
+
node.alternate = this.eat(tt._else) ? this.parseStatement('if') : null;
|
|
22
|
+
|
|
23
|
+
return this.finishNode(node, 'IfStatement');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -31,6 +31,12 @@ export default function newSpeak(Parser) {
|
|
|
31
31
|
|
|
32
32
|
return super.parseStatement(context, topLevel, exports);
|
|
33
33
|
}
|
|
34
|
+
parseExprAtom(refDestructuringErrors, forInit) {
|
|
35
|
+
if (this.type === keywordTypes.safe)
|
|
36
|
+
return this.parseSafe();
|
|
37
|
+
|
|
38
|
+
return super.parseExprAtom(refDestructuringErrors, forInit);
|
|
39
|
+
}
|
|
34
40
|
|
|
35
41
|
parseSafe() {
|
|
36
42
|
this.next();
|