Syntax for snapshot assertions
This commit is contained in:
parent
b935608e53
commit
7dd2effe96
|
@ -52,6 +52,10 @@ export function FieldDeclarationStatement(node) {
|
||||||
export function AssertionEndpointStatement(node) {
|
export function AssertionEndpointStatement(node) {
|
||||||
this.word("assert");
|
this.word("assert");
|
||||||
this.space();
|
this.space();
|
||||||
|
if (!node.isDynamic) {
|
||||||
|
this.word(":snapshot");
|
||||||
|
this.space();
|
||||||
|
}
|
||||||
this.print(node.template, node);
|
this.print(node.template, node);
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
this.space();
|
this.space();
|
||||||
|
|
|
@ -94,6 +94,7 @@ export default class SyndicateParser extends _original_Parser {
|
||||||
if (this.isContextual("assert")) {
|
if (this.isContextual("assert")) {
|
||||||
this.next();
|
this.next();
|
||||||
const node = this.startNode();
|
const node = this.startNode();
|
||||||
|
node.isDynamic = this.parseMaybeSnapshot();
|
||||||
node.template = this.parseExpression();
|
node.template = this.parseExpression();
|
||||||
if (this.eatContextual("when")) {
|
if (this.eatContextual("when")) {
|
||||||
this.expect(tt.parenL);
|
this.expect(tt.parenL);
|
||||||
|
|
|
@ -335,17 +335,19 @@ export default declare((api, options) => {
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
path.replaceWith(template(`DATASPACE._currentFacet.addEndpoint(function () {
|
path.replaceWith(template(`DATASPACE._currentFacet.addEndpoint(function () {
|
||||||
return (TEST) ? [TEMPLATE, null] : [void 0, null];
|
return (TEST) ? [TEMPLATE, null] : [void 0, null];
|
||||||
});`)({
|
}, ISDYNAMIC);`)({
|
||||||
DATASPACE: state.DataspaceID,
|
DATASPACE: state.DataspaceID,
|
||||||
TEST: node.test,
|
TEST: node.test,
|
||||||
TEMPLATE: node.template,
|
TEMPLATE: node.template,
|
||||||
|
ISDYNAMIC: t.booleanLiteral(node.isDynamic),
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
path.replaceWith(template(`DATASPACE._currentFacet.addEndpoint(function () {
|
path.replaceWith(template(`DATASPACE._currentFacet.addEndpoint(function () {
|
||||||
return [TEMPLATE, null];
|
return [TEMPLATE, null];
|
||||||
});`)({
|
}, ISDYNAMIC);`)({
|
||||||
DATASPACE: state.DataspaceID,
|
DATASPACE: state.DataspaceID,
|
||||||
TEMPLATE: node.template,
|
TEMPLATE: node.template,
|
||||||
|
ISDYNAMIC: t.booleanLiteral(node.isDynamic),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,10 +61,13 @@ defineType("FieldDeclarationStatement", {
|
||||||
});
|
});
|
||||||
|
|
||||||
defineType("AssertionEndpointStatement", {
|
defineType("AssertionEndpointStatement", {
|
||||||
builder: ["template", "test"],
|
builder: ["isDynamic", "template", "test"],
|
||||||
visitor: ["template", "test"],
|
visitor: ["isDynamic", "template", "test"],
|
||||||
aliases: ["Statement"],
|
aliases: ["Statement"],
|
||||||
fields: {
|
fields: {
|
||||||
|
isDynamic: {
|
||||||
|
validate: assertOneOf(true, false),
|
||||||
|
},
|
||||||
template: {
|
template: {
|
||||||
validate: assertNodeType("Expression"),
|
validate: assertNodeType("Expression"),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue