vsn 1.0.1 → 1.0.2
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/index.cjs +100 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +100 -10
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +5 -5
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -183,6 +183,9 @@ declare class AssignmentNode extends BaseNode {
|
|
|
183
183
|
constructor(target: AssignmentTarget, value: ExpressionNode, operator?: "=" | "+=" | "-=" | "*=" | "/=");
|
|
184
184
|
evaluate(context: ExecutionContext): Promise<any>;
|
|
185
185
|
private applyCompoundAssignment;
|
|
186
|
+
private resolveAssignmentTarget;
|
|
187
|
+
private resolveIndexPath;
|
|
188
|
+
private resolveTargetPath;
|
|
186
189
|
private assignTarget;
|
|
187
190
|
}
|
|
188
191
|
declare class ReturnNode extends BaseNode {
|
|
@@ -254,7 +257,7 @@ declare class DeclarationNode extends BaseNode {
|
|
|
254
257
|
}
|
|
255
258
|
type ExpressionNode = IdentifierExpression | LiteralExpression | TemplateExpression | UnaryExpression | BinaryExpression | MemberExpression | CallExpression | ArrayExpression | ObjectExpression | IndexExpression | FunctionExpression | AwaitExpression | TernaryExpression | DirectiveExpression | QueryExpression;
|
|
256
259
|
type DeclarationTarget = IdentifierExpression | DirectiveExpression;
|
|
257
|
-
type AssignmentTarget = IdentifierExpression | DirectiveExpression | ArrayPattern | ObjectPattern;
|
|
260
|
+
type AssignmentTarget = IdentifierExpression | MemberExpression | IndexExpression | DirectiveExpression | ArrayPattern | ObjectPattern;
|
|
258
261
|
type FunctionParam = {
|
|
259
262
|
name: string;
|
|
260
263
|
defaultValue?: ExpressionNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,9 @@ declare class AssignmentNode extends BaseNode {
|
|
|
183
183
|
constructor(target: AssignmentTarget, value: ExpressionNode, operator?: "=" | "+=" | "-=" | "*=" | "/=");
|
|
184
184
|
evaluate(context: ExecutionContext): Promise<any>;
|
|
185
185
|
private applyCompoundAssignment;
|
|
186
|
+
private resolveAssignmentTarget;
|
|
187
|
+
private resolveIndexPath;
|
|
188
|
+
private resolveTargetPath;
|
|
186
189
|
private assignTarget;
|
|
187
190
|
}
|
|
188
191
|
declare class ReturnNode extends BaseNode {
|
|
@@ -254,7 +257,7 @@ declare class DeclarationNode extends BaseNode {
|
|
|
254
257
|
}
|
|
255
258
|
type ExpressionNode = IdentifierExpression | LiteralExpression | TemplateExpression | UnaryExpression | BinaryExpression | MemberExpression | CallExpression | ArrayExpression | ObjectExpression | IndexExpression | FunctionExpression | AwaitExpression | TernaryExpression | DirectiveExpression | QueryExpression;
|
|
256
259
|
type DeclarationTarget = IdentifierExpression | DirectiveExpression;
|
|
257
|
-
type AssignmentTarget = IdentifierExpression | DirectiveExpression | ArrayPattern | ObjectPattern;
|
|
260
|
+
type AssignmentTarget = IdentifierExpression | MemberExpression | IndexExpression | DirectiveExpression | ArrayPattern | ObjectPattern;
|
|
258
261
|
type FunctionParam = {
|
|
259
262
|
name: string;
|
|
260
263
|
defaultValue?: ExpressionNode;
|
package/dist/index.js
CHANGED
|
@@ -518,27 +518,32 @@ var AssignmentNode = class extends BaseNode {
|
|
|
518
518
|
}
|
|
519
519
|
const value = await this.value.evaluate(context);
|
|
520
520
|
if (this.operator !== "=") {
|
|
521
|
-
return this.applyCompoundAssignment(context, value);
|
|
521
|
+
return await this.applyCompoundAssignment(context, value);
|
|
522
522
|
}
|
|
523
523
|
if (this.target instanceof IdentifierExpression && this.target.name.startsWith("root.") && context.rootScope) {
|
|
524
524
|
const path = this.target.name.slice("root.".length);
|
|
525
|
-
context.rootScope.setPath?.(
|
|
525
|
+
context.rootScope.setPath?.(path, value);
|
|
526
526
|
return value;
|
|
527
527
|
}
|
|
528
|
+
if (this.target instanceof MemberExpression || this.target instanceof IndexExpression) {
|
|
529
|
+
const resolved = await this.resolveAssignmentTarget(context);
|
|
530
|
+
if (resolved?.scope?.setPath) {
|
|
531
|
+
resolved.scope.setPath(resolved.path, value);
|
|
532
|
+
return value;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
528
535
|
this.assignTarget(context, this.target, value);
|
|
529
536
|
return value;
|
|
530
537
|
}
|
|
531
|
-
applyCompoundAssignment(context, value) {
|
|
538
|
+
async applyCompoundAssignment(context, value) {
|
|
532
539
|
if (!context.scope || !context.scope.setPath) {
|
|
533
540
|
return void 0;
|
|
534
541
|
}
|
|
535
|
-
|
|
536
|
-
|
|
542
|
+
const resolved = await this.resolveAssignmentTarget(context);
|
|
543
|
+
if (!resolved) {
|
|
544
|
+
throw new Error("Compound assignment requires a simple identifier or member path");
|
|
537
545
|
}
|
|
538
|
-
const
|
|
539
|
-
const scope = isRoot && context.rootScope ? context.rootScope : context.scope;
|
|
540
|
-
const rawPath = isRoot ? this.target.name.slice("root.".length) : this.target.name;
|
|
541
|
-
const path = isRoot ? `self.${rawPath}` : rawPath;
|
|
546
|
+
const { scope, path } = resolved;
|
|
542
547
|
const current = scope?.getPath ? scope.getPath(path) : void 0;
|
|
543
548
|
let result;
|
|
544
549
|
if (this.operator === "+=") {
|
|
@@ -553,6 +558,65 @@ var AssignmentNode = class extends BaseNode {
|
|
|
553
558
|
scope?.setPath?.(path, result);
|
|
554
559
|
return result;
|
|
555
560
|
}
|
|
561
|
+
async resolveAssignmentTarget(context) {
|
|
562
|
+
if (this.target instanceof IdentifierExpression) {
|
|
563
|
+
const isRoot = this.target.name.startsWith("root.");
|
|
564
|
+
const rawPath = isRoot ? this.target.name.slice("root.".length) : this.target.name;
|
|
565
|
+
if (isRoot) {
|
|
566
|
+
return { scope: context.scope, path: `root.${rawPath}` };
|
|
567
|
+
}
|
|
568
|
+
return { scope: context.scope, path: rawPath };
|
|
569
|
+
}
|
|
570
|
+
if (this.target instanceof MemberExpression) {
|
|
571
|
+
const resolvedPath = this.target.getIdentifierPath();
|
|
572
|
+
if (!resolvedPath) {
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
const path = resolvedPath.path;
|
|
576
|
+
const isRoot = path.startsWith("root.");
|
|
577
|
+
const rawPath = isRoot ? path.slice("root.".length) : path;
|
|
578
|
+
if (isRoot) {
|
|
579
|
+
return { scope: context.scope, path: `root.${rawPath}` };
|
|
580
|
+
}
|
|
581
|
+
return { scope: context.scope, path: rawPath };
|
|
582
|
+
}
|
|
583
|
+
if (this.target instanceof IndexExpression) {
|
|
584
|
+
const path = await this.resolveIndexPath(context, this.target);
|
|
585
|
+
if (!path) {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
const isRoot = path.startsWith("root.");
|
|
589
|
+
const rawPath = isRoot ? path.slice("root.".length) : path;
|
|
590
|
+
if (isRoot) {
|
|
591
|
+
return { scope: context.scope, path: `root.${rawPath}` };
|
|
592
|
+
}
|
|
593
|
+
return { scope: context.scope, path: rawPath };
|
|
594
|
+
}
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
async resolveIndexPath(context, expr) {
|
|
598
|
+
const base = await this.resolveTargetPath(context, expr.target);
|
|
599
|
+
if (!base) {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
const indexValue = await expr.index.evaluate(context);
|
|
603
|
+
if (indexValue == null) {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
return `${base}.${indexValue}`;
|
|
607
|
+
}
|
|
608
|
+
async resolveTargetPath(context, target) {
|
|
609
|
+
if (target instanceof IdentifierExpression) {
|
|
610
|
+
return target.name;
|
|
611
|
+
}
|
|
612
|
+
if (target instanceof MemberExpression) {
|
|
613
|
+
return target.getIdentifierPath()?.path ?? null;
|
|
614
|
+
}
|
|
615
|
+
if (target instanceof IndexExpression) {
|
|
616
|
+
return this.resolveIndexPath(context, target);
|
|
617
|
+
}
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
556
620
|
assignTarget(context, target, value) {
|
|
557
621
|
if (!context.scope || !context.scope.setPath) {
|
|
558
622
|
return;
|
|
@@ -2279,7 +2343,14 @@ ${caret}`;
|
|
|
2279
2343
|
return this.parseObjectPattern();
|
|
2280
2344
|
}
|
|
2281
2345
|
if (token.type === "Identifier" /* Identifier */) {
|
|
2282
|
-
|
|
2346
|
+
const expr = this.parseCallExpression();
|
|
2347
|
+
if (expr instanceof CallExpression) {
|
|
2348
|
+
throw new Error("Invalid assignment target CallExpression");
|
|
2349
|
+
}
|
|
2350
|
+
if (expr instanceof IdentifierExpression || expr instanceof MemberExpression || expr instanceof IndexExpression) {
|
|
2351
|
+
return expr;
|
|
2352
|
+
}
|
|
2353
|
+
throw new Error("Invalid assignment target");
|
|
2283
2354
|
}
|
|
2284
2355
|
throw new Error(`Invalid assignment target ${token.type}`);
|
|
2285
2356
|
}
|
|
@@ -2558,6 +2629,25 @@ ${caret}`;
|
|
|
2558
2629
|
while (this.stream.peekNonWhitespace(index)?.type === "Dot" /* Dot */ && this.stream.peekNonWhitespace(index + 1)?.type === "Identifier" /* Identifier */) {
|
|
2559
2630
|
index += 2;
|
|
2560
2631
|
}
|
|
2632
|
+
while (this.stream.peekNonWhitespace(index)?.type === "LBracket" /* LBracket */) {
|
|
2633
|
+
let depth = 0;
|
|
2634
|
+
while (true) {
|
|
2635
|
+
const token = this.stream.peekNonWhitespace(index);
|
|
2636
|
+
if (!token) {
|
|
2637
|
+
return false;
|
|
2638
|
+
}
|
|
2639
|
+
if (token.type === "LBracket" /* LBracket */) {
|
|
2640
|
+
depth += 1;
|
|
2641
|
+
} else if (token.type === "RBracket" /* RBracket */) {
|
|
2642
|
+
depth -= 1;
|
|
2643
|
+
if (depth === 0) {
|
|
2644
|
+
index += 1;
|
|
2645
|
+
break;
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
index += 1;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2561
2651
|
return this.isAssignmentOperatorStart(index);
|
|
2562
2652
|
}
|
|
2563
2653
|
if (first.type === "At" /* At */ || first.type === "Dollar" /* Dollar */) {
|