goldstein 5.19.2 → 5.20.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,8 @@
1
+ 2024.12.12, v5.20.0
2
+
3
+ feature:
4
+ - 01d6d6f goldstein: keyword-export-no-const: add
5
+
1
6
  2024.12.12, v5.19.2
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -513,6 +513,19 @@ The same as:
513
513
  const a = require('a');
514
514
  ```
515
515
 
516
+ ### Export without `const`
517
+
518
+ ```gs
519
+ export x = () => {};
520
+ ```
521
+
522
+ The same as:
523
+
524
+ ```js
525
+ export const x = () => {};
526
+ ```
527
+
528
+
516
529
  ## How to contribute?
517
530
 
518
531
  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": "5.19.2",
3
+ "version": "5.20.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "JavaScript with no limits",
@@ -20,6 +20,7 @@ import keywordUselessSemicolon from '../keyword-useless-semicolon/index.js';
20
20
  import keywordAssignFrom from '../keyword-assign-from/index.js';
21
21
  import internalParseMaybeAssign from '../internal-parse-maybe-assign/index.js';
22
22
  import operatorSafeAssignment from '../operator-safe-assignment/index.js';
23
+ import keywordExportNoConst from '../keyword-export-no-const/index.js';
23
24
 
24
25
  const {values} = Object;
25
26
 
@@ -41,6 +42,7 @@ const defaultKeywords = {
41
42
  keywordUselessComma,
42
43
  keywordUselessSemicolon,
43
44
  keywordAssignFrom,
45
+ keywordExportNoConst,
44
46
  operatorSafeAssignment,
45
47
  };
46
48
 
@@ -0,0 +1,88 @@
1
+ import {types} from 'putout';
2
+ import {tokTypes as tt} from '../operator/index.js';
3
+
4
+ const {
5
+ VariableDeclaration,
6
+ VariableDeclarator,
7
+ } = types;
8
+
9
+ export default function keywordExportNoConst(Parser) {
10
+ return class extends Parser {
11
+ shouldParseExportStatement() {
12
+ if (!this.type.keyword)
13
+ return true;
14
+
15
+ return super.shouldParseExportStatement();
16
+ }
17
+
18
+ parseExport(node, exports) {
19
+ this.next();
20
+
21
+ /* c8 ignore start */
22
+ // export * from '...'
23
+ if (this.eat(tt.star))
24
+ return this.parseExportAllDeclaration(node, exports);
25
+ /* c8 ignore end */
26
+
27
+ /* c8 ignore start */
28
+ if (this.eat(tt._default)) {
29
+ // export default ...
30
+ this.checkExport(exports, 'default', this.lastTokStart);
31
+ node.declaration = this.parseExportDefaultDeclaration();
32
+
33
+ return this.finishNode(node, 'ExportDefaultDeclaration');
34
+ }
35
+
36
+ /* c8 ignore end */
37
+ // export var|const|let|function|class ...
38
+ if (this.shouldParseExportStatement()) {
39
+ node.declaration = this.parseExportDeclaration(node);
40
+
41
+ if (node.declaration.type === 'VariableDeclaration')
42
+ this.checkVariableExport(exports, node.declaration.declarations);
43
+
44
+ if (node.declaration.type === 'ExpressionStatement')
45
+ node.declaration = VariableDeclaration('const', [
46
+ VariableDeclarator(node.declaration.expression.left, node.declaration.expression.right),
47
+ ]);
48
+ else
49
+ this.checkExport(exports, node.declaration.id, node.declaration.id.start);
50
+
51
+ node.specifiers = [];
52
+ node.source = null;
53
+ } else {
54
+ // export { x, y as z } [from '...']
55
+ node.declaration = null;
56
+ node.specifiers = this.parseExportSpecifiers(exports);
57
+
58
+ if (this.eatContextual('from')) {
59
+ if (this.type !== tt.string)
60
+ this.unexpected();
61
+
62
+ node.source = this.parseExprAtom();
63
+
64
+ if (this.options.ecmaVersion >= 16)
65
+ node.attributes = this.parseWithClause();
66
+ } else {
67
+ for (let i = 0, list = node.specifiers; i < list.length; ++i) {
68
+ // check for keywords used as local names
69
+ const spec = list[i];
70
+
71
+ this.checkUnreserved(spec.local);
72
+ // check if export is defined
73
+ this.checkLocalExport(spec.local);
74
+
75
+ if (spec.local.type === 'Literal')
76
+ this.raise(spec.local.start, 'A string literal cannot be used as an exported binding without `from`.');
77
+ }
78
+
79
+ node.source = null;
80
+ }
81
+
82
+ this.semicolon();
83
+ }
84
+
85
+ return this.finishNode(node, 'ExportNamedDeclaration');
86
+ }
87
+ };
88
+ }