goldstein 1.0.0 → 1.2.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 +23 -0
- package/README.md +69 -12
- package/bin/gs.js +33 -0
- package/package.json +8 -2
- package/packages/goldstein/index.js +14 -3
- package/packages/keyword-fn/index.js +7 -0
- package/packages/keyword-safe/index.js +51 -0
- package/packages/parser/index.js +1 -0
package/ChangeLog
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
2022.06.22, v1.2.2
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- goldstein: cli: add mainFields
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
2022.06.22, v1.2.1
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- package: repository url
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2022.06.22, v1.2.0
|
|
14
|
+
|
|
15
|
+
feature:
|
|
16
|
+
- goldstein: add CLI
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
2022.06.21, v1.1.0
|
|
20
|
+
|
|
21
|
+
feature:
|
|
22
|
+
- goldstein: add keyword-safe
|
|
23
|
+
|
package/README.md
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
# Goldstein
|
|
1
|
+
# Goldstein [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
|
|
2
|
+
|
|
3
|
+
[NPMURL]: https://npmjs.org/package/goldstein "npm"
|
|
4
|
+
[NPMIMGURL]: https://img.shields.io/npm/v/goldstein.svg?style=flat
|
|
5
|
+
[BuildStatusURL]: https://github.com/coderaiser/goldstein/actions?query=workflow%3A%22Node+CI%22 "Build Status"
|
|
6
|
+
[BuildStatusIMGURL]: https://github.com/coderaiser/goldstein/workflows/Node%20CI/badge.svg
|
|
7
|
+
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
|
8
|
+
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
|
9
|
+
[CoverageURL]: https://coveralls.io/github/coderaiser/goldstein?branch=master
|
|
10
|
+
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/goldstein/badge.svg?branch=master&service=github
|
|
11
|
+
|
|
12
|
+
> *"You haven't a real appreciation of Newspeak, Winston," he said almost sadly. "Even when you write it you're still thinking in Oldspeak. I've read some of those pieces that you write in The Times occasionally. They're good enough, but they're translations. In your heart you'd prefer to stick to Oldspeak, with all its vagueness and its useless shades of meaning. You don't grasp the beauty of the destruction of words. Do you know that Newspeak is the only language in the world whose vocabulary gets smaller every year?"*
|
|
13
|
+
>
|
|
14
|
+
> *(c) “1984”, George Orwell*
|
|
2
15
|
|
|
3
16
|
JavaScript with no limits.
|
|
4
17
|
|
|
5
|
-
Language ruled by the users, create an issue with ideas of a new language construction and what is look like in JavaScript, and most likely we implement it :).
|
|
6
|
-
|
|
7
|
-
> *"You haven't a real appreciation of Newspeak, Winston,' he said almost sadly. 'Even when you write it you're still thinking in Oldspeak. I've read some of those pieces that you write in The Times occasionally. They're good enough, but they're translations. In your heart you'd prefer to stick to Oldspeak, with all its vagueness and its useless shades of meaning. You don't grasp the beauty of the destruction of words. Do you know that Newspeak is the only language in the world whose vocabulary gets smaller every year?"*
|
|
8
|
-
>
|
|
9
|
-
> *(c) “1984”, George Orwell*
|
|
18
|
+
Language ruled by the users, [create an issue](https://github.com/coderaiser/goldstein/issues/new/choose) with ideas of a new language construction and what is look like in JavaScript, and most likely we implement it :).
|
|
10
19
|
|
|
11
20
|
## Install
|
|
12
21
|
|
|
13
22
|
```
|
|
14
|
-
npm i goldstein
|
|
23
|
+
npm i goldstein -g
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## CLI
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
$ cat > 1.gs
|
|
30
|
+
export fn hello() {
|
|
31
|
+
return 'world';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
$ gs 1.gs
|
|
35
|
+
$ cat 1.js
|
|
36
|
+
// ~1.js
|
|
37
|
+
function hello() {
|
|
38
|
+
return "world";
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
hello
|
|
42
|
+
};
|
|
15
43
|
```
|
|
16
44
|
|
|
17
45
|
## API
|
|
@@ -24,7 +52,7 @@ compile(`
|
|
|
24
52
|
guard (text !== "world") else {
|
|
25
53
|
return ""
|
|
26
54
|
}
|
|
27
|
-
|
|
55
|
+
|
|
28
56
|
return "Hello " + text
|
|
29
57
|
}
|
|
30
58
|
`);
|
|
@@ -34,10 +62,10 @@ function hello() {
|
|
|
34
62
|
if (!(text !== 'world')) {
|
|
35
63
|
return '';
|
|
36
64
|
}
|
|
37
|
-
|
|
65
|
+
|
|
38
66
|
return 'Hello ' + text;
|
|
39
67
|
}
|
|
40
|
-
|
|
68
|
+
`;
|
|
41
69
|
```
|
|
42
70
|
|
|
43
71
|
## Keywords
|
|
@@ -84,11 +112,40 @@ function hello() {
|
|
|
84
112
|
if (!(text !== 'world')) {
|
|
85
113
|
return '';
|
|
86
114
|
}
|
|
87
|
-
|
|
115
|
+
|
|
88
116
|
return 'Hello ' + text;
|
|
89
117
|
}
|
|
90
118
|
```
|
|
91
119
|
|
|
120
|
+
### `safe`
|
|
121
|
+
|
|
122
|
+
Applies [`tryCatch`](https://github.com/coderaiser/try-catch):
|
|
123
|
+
|
|
124
|
+
```gs
|
|
125
|
+
safe hello(1, 2, 3);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Is the same as:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import tryCatch from 'try-catch';
|
|
132
|
+
tryCatch(1, 2, 3);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## How to contribute?
|
|
136
|
+
|
|
137
|
+
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 🥳!
|
|
138
|
+
|
|
139
|
+
Then goes test and implementation in `index.js` and `index.spec.js` accordingly. Use scripts:
|
|
140
|
+
|
|
141
|
+
- `npm test`
|
|
142
|
+
- `UPDATE=1 npm test` - update `fixtures`;
|
|
143
|
+
- `AST=1 npm test` - log `AST`;
|
|
144
|
+
- `npm run coverage`;
|
|
145
|
+
- `npm run fix:lint`;
|
|
146
|
+
|
|
147
|
+
Update docs and make PR, that's it!
|
|
148
|
+
|
|
92
149
|
## License
|
|
93
150
|
|
|
94
|
-
MIT
|
|
151
|
+
MIT
|
package/bin/gs.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import esbuild from 'esbuild';
|
|
3
|
+
import {
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
unlinkSync,
|
|
7
|
+
} from 'fs';
|
|
8
|
+
import {compile} from '../packages/goldstein/index.js';
|
|
9
|
+
|
|
10
|
+
const [arg] = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
if (!arg) {
|
|
13
|
+
console.log('gs <filename>');
|
|
14
|
+
process.exit();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const source = readFileSync(arg, 'utf8');
|
|
18
|
+
const compiled = compile(source);
|
|
19
|
+
const compiledName = `~${arg.replace(/\.gs$/, '.js')}`;
|
|
20
|
+
|
|
21
|
+
writeFileSync(compiledName, compiled);
|
|
22
|
+
|
|
23
|
+
const outfile = compiledName.replace('~', '');
|
|
24
|
+
|
|
25
|
+
esbuild.buildSync({
|
|
26
|
+
entryPoints: [compiledName],
|
|
27
|
+
bundle: true,
|
|
28
|
+
write: true,
|
|
29
|
+
outfile,
|
|
30
|
+
mainFields: ['main'],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
unlinkSync(compiledName);
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goldstein",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"commitType": "colon",
|
|
5
6
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
7
|
"description": "JavaScript with no limits",
|
|
7
8
|
"main": "./packages/goldstein/index.js",
|
|
9
|
+
"bin": {
|
|
10
|
+
"gs": "bin/gs.js"
|
|
11
|
+
},
|
|
8
12
|
"exports": "./packages/goldstein/index.js",
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
11
|
-
"url": "git://github.com/coderaiser/
|
|
15
|
+
"url": "git://github.com/coderaiser/goldstein.git"
|
|
12
16
|
},
|
|
13
17
|
"keywords": [
|
|
14
18
|
"JavaScript",
|
|
@@ -23,6 +27,7 @@
|
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"acorn": "^8.7.1",
|
|
30
|
+
"esbuild": "^0.14.47",
|
|
26
31
|
"putout": "^26.17.0"
|
|
27
32
|
},
|
|
28
33
|
"license": "MIT",
|
|
@@ -37,6 +42,7 @@
|
|
|
37
42
|
"eslint-plugin-putout": "^15.1.1",
|
|
38
43
|
"madrun": "^9.0.0",
|
|
39
44
|
"mock-require": "^3.0.3",
|
|
45
|
+
"montag": "^1.2.1",
|
|
40
46
|
"nodemon": "^2.0.2",
|
|
41
47
|
"runsome": "^1.0.0",
|
|
42
48
|
"supertape": "^7.0.0",
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import putout, {
|
|
2
|
+
print,
|
|
3
|
+
} from 'putout';
|
|
4
|
+
import {extendParser} from '../parser/index.js';
|
|
2
5
|
import keywordFn from '../keyword-fn/index.js';
|
|
3
6
|
import keywordGuard from '../keyword-guard/index.js';
|
|
4
|
-
import
|
|
7
|
+
import keywordSafe from '../keyword-safe/index.js';
|
|
5
8
|
|
|
6
9
|
export const compile = (source) => {
|
|
7
10
|
const {parse} = extendParser([
|
|
8
11
|
keywordFn,
|
|
9
12
|
keywordGuard,
|
|
13
|
+
keywordSafe,
|
|
10
14
|
]);
|
|
11
15
|
|
|
12
16
|
const ast = parse(source);
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
const jsCode = print(ast);
|
|
19
|
+
const {code} = putout(jsCode, {
|
|
20
|
+
plugins: [
|
|
21
|
+
'try-catch',
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return code;
|
|
15
26
|
};
|
|
@@ -21,6 +21,13 @@ export default function fn(Parser) {
|
|
|
21
21
|
|
|
22
22
|
return super.parseStatement(context, topLevel, exports);
|
|
23
23
|
}
|
|
24
|
+
shouldParseExportStatement() {
|
|
25
|
+
if (this.type === Parser.acorn.keywordTypes.fn) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return super.shouldParseExportStatement();
|
|
30
|
+
}
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addKeyword,
|
|
3
|
+
TokenType,
|
|
4
|
+
} from '../operator/index.js';
|
|
5
|
+
|
|
6
|
+
// why not 'try'?
|
|
7
|
+
// because acorn internals should be copied, and added tests.
|
|
8
|
+
// there is no such thing as this.previous(), only this.next() 🤷
|
|
9
|
+
|
|
10
|
+
export default function newSpeak(Parser) {
|
|
11
|
+
const {keywordTypes} = Parser.acorn;
|
|
12
|
+
keywordTypes.safe = new TokenType('safe', {
|
|
13
|
+
keyword: 'safe',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return class extends Parser {
|
|
17
|
+
parse() {
|
|
18
|
+
this.keywords = addKeyword('safe', this.keywords);
|
|
19
|
+
|
|
20
|
+
return super.parse();
|
|
21
|
+
}
|
|
22
|
+
parseStatement(context, topLevel, exports) {
|
|
23
|
+
if (this.type === keywordTypes.safe)
|
|
24
|
+
return this.parseSafe();
|
|
25
|
+
|
|
26
|
+
return super.parseStatement(context, topLevel, exports);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
parseSafe() {
|
|
30
|
+
this.next();
|
|
31
|
+
|
|
32
|
+
const node = super.startNode();
|
|
33
|
+
const callExpression = this.parseExpression();
|
|
34
|
+
|
|
35
|
+
node.expression = {
|
|
36
|
+
type: 'CallExpression',
|
|
37
|
+
callee: {
|
|
38
|
+
type: 'Identifier',
|
|
39
|
+
name: 'tryCatch',
|
|
40
|
+
},
|
|
41
|
+
arguments: [
|
|
42
|
+
callExpression.callee,
|
|
43
|
+
...callExpression.arguments,
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return super.finishNode(node, 'ExpressionStatement');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|