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