@malloydata/malloy 0.0.117-dev240110184814 → 0.0.117-dev240111173451
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/dist/tags.d.ts +1 -1
- package/dist/tags.js +28 -12
- package/package.json +1 -1
package/dist/tags.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class Tag implements TagInterface {
|
|
|
42
42
|
static ids: Map<Tag, number>;
|
|
43
43
|
static nextTagId: number;
|
|
44
44
|
static id(t: Tag): number;
|
|
45
|
-
peek(): string;
|
|
45
|
+
peek(indent?: number): string;
|
|
46
46
|
/**
|
|
47
47
|
* Parse a line of Malloy tag language into a Tag which can be queried
|
|
48
48
|
* @param source -- The source line to be parsed. If the string starts with #, then it skips
|
package/dist/tags.js
CHANGED
|
@@ -60,22 +60,32 @@ class Tag {
|
|
|
60
60
|
}
|
|
61
61
|
return thisTagId;
|
|
62
62
|
}
|
|
63
|
-
peek() {
|
|
63
|
+
peek(indent = 0) {
|
|
64
|
+
const spaces = ' '.repeat(indent);
|
|
64
65
|
let str = `#${Tag.id(this)}`;
|
|
66
|
+
if (this.properties === undefined &&
|
|
67
|
+
this.eq &&
|
|
68
|
+
typeof this.eq === 'string') {
|
|
69
|
+
return str + `=${this.eq}`;
|
|
70
|
+
}
|
|
71
|
+
str += ' {';
|
|
65
72
|
if (this.eq) {
|
|
66
73
|
if (typeof this.eq === 'string') {
|
|
67
|
-
str +=
|
|
74
|
+
str += `\n${spaces} =: ${this.eq}`;
|
|
68
75
|
}
|
|
69
76
|
else {
|
|
70
|
-
str +=
|
|
77
|
+
str += `\n${spaces} =: [\n${spaces} ${this.eq
|
|
78
|
+
.map(el => new Tag(el).peek(indent + 4))
|
|
79
|
+
.join(`\n${spaces} `)}\n${spaces} ]`;
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
if (this.properties) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
83
|
+
for (const k in this.properties) {
|
|
84
|
+
const val = new Tag(this.properties[k]);
|
|
85
|
+
str += `\n${spaces} ${k}: ${val.peek(indent + 2)}`;
|
|
86
|
+
}
|
|
78
87
|
}
|
|
88
|
+
str += `\n${spaces}}`;
|
|
79
89
|
return str;
|
|
80
90
|
}
|
|
81
91
|
/**
|
|
@@ -283,7 +293,9 @@ function getBuildOn(ctx) {
|
|
|
283
293
|
* so that the caller can delete the tag with delete parent.tagName
|
|
284
294
|
* or assign to it with parent[tagName] = new_value
|
|
285
295
|
*/
|
|
286
|
-
function
|
|
296
|
+
function buildAccessPath(buildOn, path) {
|
|
297
|
+
var _a;
|
|
298
|
+
var _b;
|
|
287
299
|
let parentPropertyObject = buildOn.getProperties();
|
|
288
300
|
for (const p of path.slice(0, path.length - 1)) {
|
|
289
301
|
let next;
|
|
@@ -292,6 +304,10 @@ function pathToAccess(buildOn, path) {
|
|
|
292
304
|
parentPropertyObject[p] = next;
|
|
293
305
|
}
|
|
294
306
|
else {
|
|
307
|
+
// The access that we are performing requires that `.properties` be the
|
|
308
|
+
// same JS object (not equal, but identical), and `Tag.tagFrom` only copies
|
|
309
|
+
// the exact object in if it is actually present.
|
|
310
|
+
(_a = (_b = parentPropertyObject[p]).properties) !== null && _a !== void 0 ? _a : (_b.properties = {});
|
|
295
311
|
next = Tag.tagFrom(parentPropertyObject[p]);
|
|
296
312
|
}
|
|
297
313
|
parentPropertyObject = next.getProperties();
|
|
@@ -410,7 +426,7 @@ class TaglineParser extends tree_1.AbstractParseTreeVisitor {
|
|
|
410
426
|
visitTagEq(ctx) {
|
|
411
427
|
const buildOn = getBuildOn(ctx);
|
|
412
428
|
const name = this.getPropName(ctx.propName());
|
|
413
|
-
const [writeKey, writeInto] =
|
|
429
|
+
const [writeKey, writeInto] = buildAccessPath(buildOn, name);
|
|
414
430
|
const eq = this.visit(ctx.eqValue());
|
|
415
431
|
const propCx = ctx.properties();
|
|
416
432
|
if (propCx) {
|
|
@@ -433,7 +449,7 @@ class TaglineParser extends tree_1.AbstractParseTreeVisitor {
|
|
|
433
449
|
visitTagReplaceProperties(ctx) {
|
|
434
450
|
const buildOn = getBuildOn(ctx);
|
|
435
451
|
const name = this.getPropName(ctx.propName());
|
|
436
|
-
const [writeKey, writeInto] =
|
|
452
|
+
const [writeKey, writeInto] = buildAccessPath(buildOn, name);
|
|
437
453
|
const propCx = ctx.properties();
|
|
438
454
|
const props = this.visitProperties(propCx);
|
|
439
455
|
if (ctx.DOTTY() === undefined) {
|
|
@@ -449,7 +465,7 @@ class TaglineParser extends tree_1.AbstractParseTreeVisitor {
|
|
|
449
465
|
visitTagUpdateProperties(ctx) {
|
|
450
466
|
const buildOn = getBuildOn(ctx);
|
|
451
467
|
const name = this.getPropName(ctx.propName());
|
|
452
|
-
const [writeKey, writeInto] =
|
|
468
|
+
const [writeKey, writeInto] = buildAccessPath(buildOn, name);
|
|
453
469
|
const propCx = ctx.properties();
|
|
454
470
|
propCx['buildOn'] = Tag.tagFrom(writeInto[writeKey]);
|
|
455
471
|
const props = this.visitProperties(propCx);
|
|
@@ -461,7 +477,7 @@ class TaglineParser extends tree_1.AbstractParseTreeVisitor {
|
|
|
461
477
|
visitTagDef(ctx) {
|
|
462
478
|
const buildOn = getBuildOn(ctx);
|
|
463
479
|
const path = this.getPropName(ctx.propName());
|
|
464
|
-
const [writeKey, writeInto] =
|
|
480
|
+
const [writeKey, writeInto] = buildAccessPath(buildOn, path);
|
|
465
481
|
if (ctx.MINUS()) {
|
|
466
482
|
delete writeInto[writeKey];
|
|
467
483
|
}
|