goldstein 4.0.0 → 4.0.2
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 +10 -0
- package/README.md +2 -2
- package/bin/gs.js +1 -0
- package/build/parser.cjs +8 -2
- package/package.json +5 -2
- package/packages/goldstein/index.js +9 -6
- package/packages/parser/index.js +6 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ When you need to compile **Goldstein** to **JavaScript** use:
|
|
|
78
78
|
```js
|
|
79
79
|
import {compile} from 'goldstein';
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
compile(`
|
|
82
82
|
fn hello() {
|
|
83
83
|
guard text !== "world" else {
|
|
84
84
|
return ""
|
|
@@ -117,7 +117,7 @@ const source = `
|
|
|
117
117
|
|
|
118
118
|
const {keywordFn} = keywords;
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
compile(source, {
|
|
121
121
|
keywords: [
|
|
122
122
|
keywordFn,
|
|
123
123
|
function id(Parser) {
|
package/bin/gs.js
CHANGED
package/build/parser.cjs
CHANGED
|
@@ -5365,17 +5365,23 @@ var extendParser = (keywords3) => {
|
|
|
5365
5365
|
};
|
|
5366
5366
|
};
|
|
5367
5367
|
var createParse = (parser) => (source) => {
|
|
5368
|
+
const comments = [];
|
|
5368
5369
|
const options = {
|
|
5369
5370
|
ecmaVersion: "latest",
|
|
5370
5371
|
sourceType: "module",
|
|
5371
5372
|
locations: true,
|
|
5372
|
-
comment: true
|
|
5373
|
+
comment: true,
|
|
5374
|
+
ranges: true,
|
|
5375
|
+
onComment: (a) => {
|
|
5376
|
+
comments.push(a);
|
|
5377
|
+
}
|
|
5373
5378
|
};
|
|
5374
5379
|
const result = parser.parse(source, options);
|
|
5375
5380
|
const tokens = Array.from(parser.tokenizer(source, options));
|
|
5376
5381
|
return {
|
|
5377
5382
|
...result,
|
|
5378
|
-
tokens
|
|
5383
|
+
tokens,
|
|
5384
|
+
comments
|
|
5379
5385
|
};
|
|
5380
5386
|
};
|
|
5381
5387
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "JavaScript with no limits",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"wisdom": "madrun wisdom"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@putout/plugin-declare": "^2.0.1",
|
|
33
|
+
"@putout/plugin-logical-expressions": "^4.0.0",
|
|
34
|
+
"@putout/plugin-try-catch": "^3.0.0",
|
|
32
35
|
"@putout/printer": "^3.6.0",
|
|
33
36
|
"acorn": "^8.7.1",
|
|
34
37
|
"esbuild": "^0.19.2",
|
|
@@ -43,7 +46,7 @@
|
|
|
43
46
|
"c8": "^8.0.0",
|
|
44
47
|
"check-dts": "^0.7.1",
|
|
45
48
|
"escover": "^3.4.0",
|
|
46
|
-
"eslint": "^8.
|
|
49
|
+
"eslint": "^8.48.0",
|
|
47
50
|
"eslint-plugin-n": "^16.0.1",
|
|
48
51
|
"eslint-plugin-putout": "^19.0.3",
|
|
49
52
|
"madrun": "^9.0.0",
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {transform} from 'putout';
|
|
2
2
|
import {print} from '@putout/printer';
|
|
3
3
|
import {parse} from './parser.js';
|
|
4
4
|
import estreeToBabel from 'estree-to-babel';
|
|
5
|
+
import tryCatchPlugin from '@putout/plugin-try-catch';
|
|
6
|
+
import declarePlugin from '@putout/plugin-declare';
|
|
7
|
+
import logicalExpressionsPlugin from '@putout/plugin-logical-expressions';
|
|
5
8
|
|
|
6
9
|
export * from './parser.js';
|
|
7
|
-
export const compile =
|
|
10
|
+
export const compile = (source, options = {}) => {
|
|
8
11
|
const ast = estreeToBabel(parse(source, options));
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
transform(ast, source, {
|
|
11
14
|
rules: {
|
|
12
15
|
...options.rules,
|
|
13
16
|
},
|
|
14
17
|
plugins: [
|
|
15
|
-
'try-catch',
|
|
16
|
-
'declare',
|
|
17
|
-
'logical-expressions',
|
|
18
|
+
['try-catch', tryCatchPlugin],
|
|
19
|
+
['declare', declarePlugin],
|
|
20
|
+
['logical-expressions', logicalExpressionsPlugin],
|
|
18
21
|
],
|
|
19
22
|
});
|
|
20
23
|
|
package/packages/parser/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import {Parser} from 'acorn';
|
|
|
2
2
|
|
|
3
3
|
export const extendParser = (keywords) => {
|
|
4
4
|
const parser = Parser.extend(...keywords);
|
|
5
|
-
|
|
6
5
|
const parse = createParse(parser);
|
|
7
6
|
|
|
8
7
|
return {
|
|
@@ -11,11 +10,16 @@ export const extendParser = (keywords) => {
|
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
const createParse = (parser) => (source) => {
|
|
13
|
+
const comments = [];
|
|
14
14
|
const options = {
|
|
15
15
|
ecmaVersion: 'latest',
|
|
16
16
|
sourceType: 'module',
|
|
17
17
|
locations: true,
|
|
18
18
|
comment: true,
|
|
19
|
+
ranges: true,
|
|
20
|
+
onComment: (a) => {
|
|
21
|
+
comments.push(a);
|
|
22
|
+
},
|
|
19
23
|
};
|
|
20
24
|
|
|
21
25
|
const result = parser.parse(source, options);
|
|
@@ -24,5 +28,6 @@ const createParse = (parser) => (source) => {
|
|
|
24
28
|
return {
|
|
25
29
|
...result,
|
|
26
30
|
tokens,
|
|
31
|
+
comments,
|
|
27
32
|
};
|
|
28
33
|
};
|