@isograph/babel-plugin 0.0.0-main-ee768a61 → 0.0.0-main-d64c2813
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/BabelPluginIsograph.js +2 -2
- package/README.md +1 -1
- package/compileTag.js +22 -16
- package/package.json +1 -1
package/BabelPluginIsograph.js
CHANGED
@@ -16,7 +16,7 @@ if (result) {
|
|
16
16
|
IsographConfig = result.config;
|
17
17
|
} else {
|
18
18
|
throw new Error(
|
19
|
-
"No config found. Do you have a isograph.config.json file somewhere?"
|
19
|
+
"No config found. Do you have a isograph.config.json file somewhere?",
|
20
20
|
);
|
21
21
|
}
|
22
22
|
|
@@ -25,7 +25,7 @@ module.exports = function BabelPluginIsograph(context) {
|
|
25
25
|
if (!t) {
|
26
26
|
throw new Error(
|
27
27
|
'BabelPluginIsograph: Expected plugin context to include "types", but got:' +
|
28
|
-
String(context)
|
28
|
+
String(context),
|
29
29
|
);
|
30
30
|
}
|
31
31
|
|
package/README.md
CHANGED
@@ -20,7 +20,7 @@ module.exports = {
|
|
20
20
|
|
21
21
|
## What does it do?
|
22
22
|
|
23
|
-
This package changes calls to `
|
23
|
+
This package changes calls to `iso` entrypoint to `require` calls for the generated artifact. For example, `` iso`entrypoint Query.HomePage` `` might get replaced with `require("../__isograph/Query/HomePage/entrypoint.isograph.ts")`.
|
24
24
|
|
25
25
|
## Requirements
|
26
26
|
|
package/compileTag.js
CHANGED
@@ -6,26 +6,30 @@ function compileTag(t, path, config) {
|
|
6
6
|
const tag = path.get("tag");
|
7
7
|
|
8
8
|
if (tag.isIdentifier({ name: "iso" })) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
const { keyword, type, field } = getTypeAndField(path);
|
10
|
+
if (keyword === "entrypoint") {
|
11
|
+
// This throws if the tag is invalid
|
12
|
+
compileImportStatement(t, path, type, field, "entrypoint", config);
|
13
|
+
} else if (keyword === "field") {
|
14
|
+
// No-op
|
15
|
+
return false;
|
16
|
+
} else {
|
17
|
+
throw new Error(
|
18
|
+
"Invalid iso tag usage. Expected 'entrypoint' or 'field'."
|
19
|
+
);
|
20
|
+
}
|
13
21
|
}
|
14
22
|
|
15
23
|
return false;
|
16
24
|
}
|
17
25
|
|
18
|
-
const typeAndFieldRegex = new RegExp(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
const { type, field } = getTypeAndField(path);
|
23
|
-
compileImportStatement(t, path, type, field, "entrypoint", config);
|
24
|
-
}
|
26
|
+
const typeAndFieldRegex = new RegExp(
|
27
|
+
"\\s*(entrypoint|field)\\s*([^\\.\\s]+)\\.([^\\s\\(]+)",
|
28
|
+
"m"
|
29
|
+
);
|
25
30
|
|
26
31
|
function getTypeAndField(path) {
|
27
32
|
const quasis = path.node.quasi.quasis;
|
28
|
-
|
29
33
|
if (quasis.length !== 1) {
|
30
34
|
throw new Error(
|
31
35
|
"BabelPluginIsograph: Substitutions are not allowed in iso fragments."
|
@@ -34,15 +38,17 @@ function getTypeAndField(path) {
|
|
34
38
|
|
35
39
|
const content = path.node.quasi.quasis[0].value.raw;
|
36
40
|
const typeAndField = typeAndFieldRegex.exec(content);
|
37
|
-
const type = typeAndField[1];
|
38
|
-
const field = typeAndField[2];
|
39
41
|
|
40
|
-
|
42
|
+
const keyword = typeAndField[1];
|
43
|
+
const type = typeAndField[2];
|
44
|
+
const field = typeAndField[3];
|
45
|
+
|
46
|
+
if (keyword == null || type == null || field == null) {
|
41
47
|
throw new Error(
|
42
48
|
"Malformed iso literal. I hope the iso compiler failed to accept this literal!"
|
43
49
|
);
|
44
50
|
}
|
45
|
-
return { type, field };
|
51
|
+
return { keyword, type, field };
|
46
52
|
}
|
47
53
|
|
48
54
|
function compileImportStatement(t, path, type, field, artifactType, config) {
|