redput 1.0.3 → 1.1.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
+ 2023.08.14, v1.1.0
2
+
3
+ feature:
4
+ - 3d1eed2 get-report: commonjs
5
+ - 543a0a8 redput: get-report: add support of StringLiteral
6
+
1
7
  2023.08.14, v1.0.3
2
8
 
3
9
  feature:
@@ -1,30 +1,56 @@
1
- import {operator} from 'putout';
1
+ import {
2
+ operator,
3
+ types,
4
+ } from 'putout';
2
5
 
6
+ const {isStringLiteral} = types;
3
7
  const {getTemplateValues} = operator;
8
+
4
9
  const REPORT = 'export const report = () => __a';
10
+ const REPORT_COMMONJS = 'module.exports.report = () => __a';
5
11
  const ASSIGN = 'export const report = __a';
6
12
 
13
+ const templates = [
14
+ REPORT,
15
+ REPORT_COMMONJS,
16
+ ASSIGN,
17
+ ];
18
+
7
19
  export const report = ({value}) => value;
8
20
  export const fix = () => {};
9
- export const traverse = ({push}) => ({
10
- [REPORT](path) {
11
- const {__a} = getTemplateValues(path, REPORT);
12
-
13
- push({
14
- path,
15
- value: __a.quasis[0].value.cooked,
16
- });
17
-
18
- path.stop();
19
- },
20
- [ASSIGN](path) {
21
- const {__a} = getTemplateValues(path, ASSIGN);
22
-
23
- push({
24
- path,
25
- value: __a.quasis[0].value.cooked,
21
+ export const traverse = ({push}) => {
22
+ const pushValue = process(push);
23
+ const visitors = {};
24
+
25
+ for (const template of templates) {
26
+ visitors[template] = process({
27
+ push,
28
+ template,
26
29
  });
27
-
28
- path.stop();
29
- },
30
- });
30
+ }
31
+
32
+ return visitors;
33
+ };
34
+
35
+ const process = ({push, template}) => (path) => {
36
+ const {__a} = getTemplateValues(path, template);
37
+
38
+ if (!__a)
39
+ return;
40
+
41
+ const value = parseValue(__a);
42
+
43
+ push({
44
+ path,
45
+ value,
46
+ });
47
+
48
+ path.stop();
49
+ }
50
+
51
+ function parseValue(a) {
52
+ if (isStringLiteral(a))
53
+ return a.value;
54
+
55
+ return a.quasis[0].value.cooked;
56
+ }
package/lib/redput.js CHANGED
@@ -26,7 +26,7 @@ export const redput = async (link, {token}) => {
26
26
  const [comment, ...lines] = raw.split('\n');
27
27
  const name = comment.replace(/\/\/\s+?/, '');
28
28
 
29
- if (name.includes(':'))
29
+ if (name.includes(':') || name.includes('{'))
30
30
  return [
31
31
  Error(`Bad name: ${name}`),
32
32
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {