clarity-pattern-parser 8.4.11 → 8.4.12
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/TODO.md +5 -1
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +11 -1
- package/src/grammar/Grammar.ts +6 -2
package/TODO.md
CHANGED
|
@@ -22,4 +22,8 @@ It will count the startPattern and only be done when its ends equal to end Patte
|
|
|
22
22
|
```ts
|
|
23
23
|
new Segments(segmentPattern);
|
|
24
24
|
|
|
25
|
-
```
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
NEVER BE TEMPTED TO PUT LOGIC IN SYNTAX. THIS IS MEANT TO BE DECLARATIVE AND COMPOSABLE. If you want a different behavior from a parse, then compose it.
|
package/package.json
CHANGED
|
@@ -401,16 +401,26 @@ describe("Grammar", () => {
|
|
|
401
401
|
test("Import Alias", async () => {
|
|
402
402
|
const expression = `
|
|
403
403
|
import { value as alias } from "resource1"
|
|
404
|
-
|
|
404
|
+
import { export-value } from "resource2" with params {
|
|
405
|
+
param = alias
|
|
406
|
+
}
|
|
407
|
+
name = export-value
|
|
405
408
|
`
|
|
406
409
|
|
|
407
410
|
const resource1 = `
|
|
408
411
|
value = "Value"
|
|
409
412
|
`;
|
|
410
413
|
|
|
414
|
+
const resource2 = `
|
|
415
|
+
use params {
|
|
416
|
+
param
|
|
417
|
+
}
|
|
418
|
+
export-value = param
|
|
419
|
+
`
|
|
411
420
|
|
|
412
421
|
const pathMap: Record<string, string> = {
|
|
413
422
|
"resource1": resource1,
|
|
423
|
+
"resource2": resource2
|
|
414
424
|
};
|
|
415
425
|
|
|
416
426
|
function resolveImport(resource: string) {
|
package/src/grammar/Grammar.ts
CHANGED
|
@@ -186,7 +186,11 @@ export class Grammar {
|
|
|
186
186
|
const importStatements = importStatement.findAll(n => n.name === "import-name" || n.name === "import-alias");
|
|
187
187
|
|
|
188
188
|
importStatements.forEach((node) => {
|
|
189
|
-
if (node.name === "import-name")
|
|
189
|
+
if (node.name === "import-name" && node.parent?.name === "import-alias"){
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (node.name === "import-name" && node.parent?.name !== "import-alias") {
|
|
190
194
|
const importName = node.value;
|
|
191
195
|
|
|
192
196
|
if (parseContext.importedPatternsByName.has(importName)) {
|
|
@@ -214,7 +218,7 @@ export class Grammar {
|
|
|
214
218
|
throw new Error(`Couldn't find pattern with name: ${importName}, from import: ${resource}.`);
|
|
215
219
|
}
|
|
216
220
|
|
|
217
|
-
parseContext.importedPatternsByName.set(alias, pattern);
|
|
221
|
+
parseContext.importedPatternsByName.set(alias, pattern.clone(alias));
|
|
218
222
|
}
|
|
219
223
|
});
|
|
220
224
|
|