goldstein 5.5.2 → 5.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 CHANGED
@@ -1,3 +1,9 @@
1
+ 2024.05.08, v5.6.0
2
+
3
+ feature:
4
+ - 4be8b79 goldstein: keyword-fn: add constant
5
+ - f0b7d54 goldstein: keyword-fn: add ability to use "fn" as function name
6
+
1
7
  2024.05.08, v5.5.2
2
8
 
3
9
  fix:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "5.5.2",
3
+ "version": "5.6.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "JavaScript with no limits",
@@ -1,29 +1,46 @@
1
1
  import {addKeyword, TokenType} from '../operator/index.js';
2
+ import {tokTypes as tt} from 'acorn';
3
+
4
+ const KEYWORD_FN = 'fn';
2
5
 
3
6
  export default function fn(Parser) {
4
- Parser.acorn.keywordTypes.fn = new TokenType('fn', {
5
- keyword: 'fn',
7
+ const {keywordTypes} = Parser.acorn;
8
+
9
+ keywordTypes.fn = new TokenType(KEYWORD_FN, {
10
+ keyword: KEYWORD_FN,
6
11
  });
7
12
 
8
13
  return class extends Parser {
9
14
  parse() {
10
- this.keywords = addKeyword('fn', this.keywords);
15
+ this.keywords = addKeyword(KEYWORD_FN, this.keywords);
11
16
 
12
17
  return super.parse();
13
18
  }
14
19
 
15
20
  parseStatement(context, topLevel, exports) {
16
- if (this.type === Parser.acorn.keywordTypes.fn)
17
- this.type = Parser.acorn.keywordTypes.function;
21
+ const isParen = this.eat(tt.parenL);
22
+
23
+ if (!isParen && this.type === keywordTypes.fn)
24
+ this.type = keywordTypes.function;
18
25
 
19
26
  return super.parseStatement(context, topLevel, exports);
20
27
  }
21
28
 
22
29
  shouldParseExportStatement() {
23
- if (this.type === Parser.acorn.keywordTypes.fn)
30
+ if (this.type === keywordTypes.fn)
24
31
  return true;
25
32
 
26
33
  return super.shouldParseExportStatement();
27
34
  }
35
+
36
+ checkUnreserved(ref) {
37
+ const {name} = ref;
38
+
39
+ if (name === KEYWORD_FN)
40
+ return;
41
+
42
+ return super.checkUnreserved(ref);
43
+ }
28
44
  };
29
45
  }
46
+