goldstein 2.2.0 → 2.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.27, v2.3.0
2
+
3
+ feature:
4
+ - goldstein: add curry
5
+
6
+
1
7
  2022.06.27, v2.2.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -184,6 +184,19 @@ You can use [throw as expression](https://github.com/tc39/proposal-throw-express
184
184
  const a = () => throw 'hello';
185
185
  ```
186
186
 
187
+ ### Curry
188
+
189
+ Similar to [partial application](https://github.com/tc39/proposal-partial-application):
190
+
191
+ ```gs
192
+ const sum = a + b;
193
+ const inc = sum~(1);
194
+
195
+ inc(5);
196
+ // returns
197
+ 6
198
+ ```
199
+
187
200
  ## How to contribute?
188
201
 
189
202
  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.2.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "commitType": "colon",
6
6
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
@@ -8,6 +8,7 @@ import keywordTry from '../keyword-try/index.js';
8
8
  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
+ import keywordCurry from '../keyword-curry/index.js';
11
12
 
12
13
  export const compile = (source) => {
13
14
  const {parse} = extendParser([
@@ -16,6 +17,7 @@ export const compile = (source) => {
16
17
  keywordTry,
17
18
  keywordShould,
18
19
  keywordThrow,
20
+ keywordCurry,
19
21
  stringInterpolation,
20
22
  ]);
21
23
 
@@ -25,6 +27,7 @@ export const compile = (source) => {
25
27
  const {code} = putout(jsCode, {
26
28
  plugins: [
27
29
  'try-catch',
30
+ 'declare-undefined-variables',
28
31
  ],
29
32
  });
30
33
 
@@ -0,0 +1,32 @@
1
+ import {types} from 'putout';
2
+ import {tokTypes as tt} from '../operator/index.js';
3
+
4
+ const {Identifier} = types;
5
+
6
+ export default function keywordCurry(Parser) {
7
+ return class extends Parser {
8
+ parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit) {
9
+ const isTRA = this.eat(tt.prefix);
10
+
11
+ if (isTRA)
12
+ return this.parseCurry(base, startPos, startLoc);
13
+
14
+ return super.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained, forInit);
15
+ }
16
+ parseCurry(base, startPos, startLoc) {
17
+ const node = this.startNodeAt(startPos, startLoc);
18
+ const isParenL = this.eat(tt.parenL);
19
+
20
+ if (!isParenL)
21
+ this.raise(this.start, `After '~' should always go '(' when you use curry`);
22
+
23
+ node.callee = Identifier('currify');
24
+ node.arguments = [base, this.parseExpression()];
25
+
26
+ this.expect(tt.parenR);
27
+
28
+ return this.finishNode(node, 'CallExpression');
29
+ }
30
+ };
31
+ }
32
+
@@ -1,9 +1,13 @@
1
1
  import {template} from 'putout';
2
+ const isString = (a) => typeof a === 'string';
2
3
  const {assign} = Object;
3
4
 
4
5
  export default function stringInterpolation(Parser) {
5
6
  return class extends Parser {
6
7
  parseLiteral(value) {
8
+ if (!isString(value))
9
+ return super.parseLiteral(value);
10
+
7
11
  const chars = value.split('');
8
12
 
9
13
  let literalOpened = false;