@timvir/macro 0.2.38 → 0.2.39
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.md +4 -0
- package/index.js +10 -10
- package/knip.config.d.ts +5 -0
- package/knip.config.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { join, dirname } = require("path");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const crypto = require("crypto");
|
|
1
|
+
const { join, dirname } = require("node:path");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const crypto = require("node:crypto");
|
|
4
4
|
const { createMacro } = require("babel-plugin-macros");
|
|
5
5
|
const { parse } = require("@babel/parser");
|
|
6
6
|
const generate = require("@babel/generator");
|
|
@@ -12,7 +12,7 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
12
12
|
const t = babel.types;
|
|
13
13
|
|
|
14
14
|
if (references.Sample) {
|
|
15
|
-
references.Sample
|
|
15
|
+
for (const referencePath of references.Sample) {
|
|
16
16
|
const { parent, parentPath } = referencePath;
|
|
17
17
|
|
|
18
18
|
if (parent.type === "JSXOpeningElement") {
|
|
@@ -40,7 +40,7 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
40
40
|
* Genrate a unique name that will be used to hold the reference
|
|
41
41
|
* to the sample component.
|
|
42
42
|
*/
|
|
43
|
-
const name = `C${genName(filename, component, variant,
|
|
43
|
+
const name = `C${genName(filename, component, variant, `${counter}`)}`;
|
|
44
44
|
counter = counter + 1;
|
|
45
45
|
|
|
46
46
|
state.file.path.node.body.unshift(
|
|
@@ -61,7 +61,7 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
61
61
|
if (fs.existsSync(module)) {
|
|
62
62
|
return fs.readFileSync(module, "utf8");
|
|
63
63
|
} else {
|
|
64
|
-
return fs.readFileSync(module
|
|
64
|
+
return fs.readFileSync(`${module}.tsx`, "utf8");
|
|
65
65
|
}
|
|
66
66
|
})();
|
|
67
67
|
|
|
@@ -79,11 +79,11 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
throw new Error(`Unhandled type: ${parent.type}`);
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
if (references.sampleCode) {
|
|
86
|
-
references.sampleCode
|
|
86
|
+
for (const referencePath of references.sampleCode) {
|
|
87
87
|
const callExpression = referencePath.parent;
|
|
88
88
|
const {
|
|
89
89
|
variant,
|
|
@@ -97,7 +97,7 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
97
97
|
if (fs.existsSync(module)) {
|
|
98
98
|
return fs.readFileSync(module, "utf8");
|
|
99
99
|
} else {
|
|
100
|
-
return fs.readFileSync(module
|
|
100
|
+
return fs.readFileSync(`${module}.tsx`, "utf8");
|
|
101
101
|
}
|
|
102
102
|
})();
|
|
103
103
|
|
|
@@ -136,7 +136,7 @@ module.exports = createMacro(({ references, babel, state }) => {
|
|
|
136
136
|
}[as]();
|
|
137
137
|
|
|
138
138
|
referencePath.parentPath.parentPath.replaceWith(t.stringLiteral(string));
|
|
139
|
-
}
|
|
139
|
+
}
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
|
package/knip.config.d.ts
ADDED
package/knip.config.ts
ADDED