goldstein 2.3.0 → 2.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 +7 -0
- package/README.md +20 -2
- package/package.json +1 -1
- package/packages/goldstein/index.js +2 -0
- package/packages/keyword-freeze/index.js +59 -0
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -166,6 +166,24 @@ try hello();
|
|
|
166
166
|
|
|
167
167
|
> ☝️ *Warning: this feature can be helpful but also dangerous especially if you're debugging your application. In fact, this is made to be used as an optional function call (ex. should load content, but not necessary and knowing this feature is optional), if you call a function in this way while debugging, no error will be printed and the application will continue run as nothing happened.*
|
|
168
168
|
|
|
169
|
+
### `freeze`
|
|
170
|
+
|
|
171
|
+
You can use `freeze` instead of `Object.freeze()` like that:
|
|
172
|
+
|
|
173
|
+
```gs
|
|
174
|
+
freeze {
|
|
175
|
+
'example': true
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Is the same as:
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
Object.freeze({
|
|
183
|
+
example: true,
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
169
187
|
### `if`
|
|
170
188
|
|
|
171
189
|
You can omit parens. But you must use braces in this case.
|
|
@@ -184,12 +202,12 @@ You can use [throw as expression](https://github.com/tc39/proposal-throw-express
|
|
|
184
202
|
const a = () => throw 'hello';
|
|
185
203
|
```
|
|
186
204
|
|
|
187
|
-
### Curry
|
|
205
|
+
### `Curry`
|
|
188
206
|
|
|
189
207
|
Similar to [partial application](https://github.com/tc39/proposal-partial-application):
|
|
190
208
|
|
|
191
209
|
```gs
|
|
192
|
-
const sum = a + b;
|
|
210
|
+
const sum = (a, b) => a + b;
|
|
193
211
|
const inc = sum~(1);
|
|
194
212
|
|
|
195
213
|
inc(5);
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import keywordShould from '../keyword-should/index.js';
|
|
|
9
9
|
import keywordThrow from '../keyword-throw/index.js';
|
|
10
10
|
import stringInterpolation from '../string-interpolation/index.js';
|
|
11
11
|
import keywordCurry from '../keyword-curry/index.js';
|
|
12
|
+
import keywordFreeze from '../keyword-freeze/index.js';
|
|
12
13
|
|
|
13
14
|
export const compile = (source) => {
|
|
14
15
|
const {parse} = extendParser([
|
|
@@ -18,6 +19,7 @@ export const compile = (source) => {
|
|
|
18
19
|
keywordShould,
|
|
19
20
|
keywordThrow,
|
|
20
21
|
keywordCurry,
|
|
22
|
+
keywordFreeze,
|
|
21
23
|
stringInterpolation,
|
|
22
24
|
]);
|
|
23
25
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {types} from 'putout';
|
|
2
|
+
import {
|
|
3
|
+
addKeyword,
|
|
4
|
+
TokenType,
|
|
5
|
+
} from '../operator/index.js';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
isObjectExpression,
|
|
9
|
+
isArrayExpression,
|
|
10
|
+
} = types;
|
|
11
|
+
|
|
12
|
+
export default function keywordFreeze(Parser) {
|
|
13
|
+
const {keywordTypes} = Parser.acorn;
|
|
14
|
+
keywordTypes.freeze = new TokenType('freeze', {
|
|
15
|
+
keyword: 'freeze',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return class extends Parser {
|
|
19
|
+
parse() {
|
|
20
|
+
this.keywords = addKeyword('freeze', this.keywords);
|
|
21
|
+
return super.parse();
|
|
22
|
+
}
|
|
23
|
+
parseStatement(context, topLevel, exports) {
|
|
24
|
+
if (this.type === keywordTypes.freeze) {
|
|
25
|
+
return this.parseFreeze();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return super.parseStatement(context, topLevel, exports);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
parseFreeze() {
|
|
32
|
+
this.next();
|
|
33
|
+
|
|
34
|
+
const node = super.startNode();
|
|
35
|
+
const expression = this.parseExpression();
|
|
36
|
+
|
|
37
|
+
if (isObjectExpression(expression) || isArrayExpression(expression))
|
|
38
|
+
node.expression = {
|
|
39
|
+
type: 'ExpressionStatement',
|
|
40
|
+
expression: {
|
|
41
|
+
type: 'CallExpression',
|
|
42
|
+
callee: {
|
|
43
|
+
type: 'Identifier',
|
|
44
|
+
name: 'freeze',
|
|
45
|
+
},
|
|
46
|
+
arguments: [
|
|
47
|
+
expression,
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
else
|
|
53
|
+
this.raise(this.start, `After 'freeze' only objects and arrays can come`);
|
|
54
|
+
|
|
55
|
+
return super.finishNode(node, 'ExpressionStatement');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|