goldstein 3.0.0 → 3.2.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 +11 -0
- package/README.md +68 -4
- package/build/parser.cjs +5492 -0
- package/package.json +9 -4
- package/packages/goldstein/index.js +11 -32
- package/packages/goldstein/parser.js +33 -0
- package/packages/keyword-arrow/index.js +43 -0
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.04.18, v3.2.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 76a336d golstein: add support of CommonJS
|
|
5
|
+
|
|
6
|
+
2023.04.18, v3.1.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 4236346 goldstein: add ability to use arrow in FunctionDeclaration
|
|
10
|
+
- 8e2197f goldstein: add ability tot pass keywords and 🐊Putout optionts
|
|
11
|
+
|
|
1
12
|
2023.04.02, v3.0.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/README.md
CHANGED
|
@@ -36,10 +36,10 @@ export fn hello() {
|
|
|
36
36
|
$ gs 1.gs
|
|
37
37
|
$ cat 1.js
|
|
38
38
|
function hello() {
|
|
39
|
-
|
|
39
|
+
return "world";
|
|
40
40
|
}
|
|
41
41
|
export {
|
|
42
|
-
|
|
42
|
+
hello,
|
|
43
43
|
};
|
|
44
44
|
```
|
|
45
45
|
|
|
@@ -99,9 +99,56 @@ function hello() {
|
|
|
99
99
|
`;
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
By default, all keywords mentioned in the next section used, but you can limit the list setting with `keywords` option.
|
|
103
|
+
You can add any keywords, and even create your own:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
import {
|
|
107
|
+
compile,
|
|
108
|
+
keywords,
|
|
109
|
+
} from 'goldstein';
|
|
110
|
+
|
|
111
|
+
const source = `
|
|
112
|
+
fn hello() {
|
|
113
|
+
return id('hello');
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
|
|
117
|
+
const {keywordFn} = keywords;
|
|
118
|
+
|
|
119
|
+
compile(source, {
|
|
120
|
+
keywords: [
|
|
121
|
+
keywordFn,
|
|
122
|
+
function id(Parser) {
|
|
123
|
+
const {keywordTypes} = Parser.acorn;
|
|
124
|
+
return class extends Parser {
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
rules: {
|
|
129
|
+
declare: ['on', {
|
|
130
|
+
declarations: {
|
|
131
|
+
id: 'const id = (a) => a',
|
|
132
|
+
},
|
|
133
|
+
}],
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// returns
|
|
138
|
+
`
|
|
139
|
+
const id = (a) => a;
|
|
140
|
+
|
|
141
|
+
function hello() {
|
|
142
|
+
return id('hello');
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
You can declare variables with [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare).
|
|
148
|
+
|
|
102
149
|
### `parse(source)`
|
|
103
150
|
|
|
104
|
-
When you need to get **JavaScript**
|
|
151
|
+
When you need to get **JavaScript** Babel AST use `parse`:
|
|
105
152
|
|
|
106
153
|
```js
|
|
107
154
|
import {parse} from 'goldstein';
|
|
@@ -115,7 +162,8 @@ parse(`
|
|
|
115
162
|
return "Hello " + text
|
|
116
163
|
}
|
|
117
164
|
`);
|
|
118
|
-
|
|
165
|
+
|
|
166
|
+
// returns Babel AST
|
|
119
167
|
```
|
|
120
168
|
|
|
121
169
|
## Keywords
|
|
@@ -282,6 +330,22 @@ Will be converted to:
|
|
|
282
330
|
import hello from './hello.js';
|
|
283
331
|
```
|
|
284
332
|
|
|
333
|
+
### `FunctionDeclaration` with `Arrow`
|
|
334
|
+
|
|
335
|
+
If you mistakenly put `=>` in function declaration:
|
|
336
|
+
|
|
337
|
+
```gs
|
|
338
|
+
function hello() => {
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
That absolutely fine, it will be converted to:
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
function hello() {
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
285
349
|
## How to contribute?
|
|
286
350
|
|
|
287
351
|
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 🥳!
|