Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename assertsModifier to asserts #10613

Merged
merged 1 commit into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-generator/src/generators/typescript.js
Expand Up @@ -197,7 +197,7 @@ export function TSTypeReference(node) {
}

export function TSTypePredicate(node) {
if (node.assertsModifier) {
if (node.asserts) {
this.word("asserts");
this.space();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -904,24 +904,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const t: N.TsTypeAnnotation = this.startNode();
this.expect(returnToken);

const assertsModifier = this.tsTryParse(
this.tsParseTypePredicateAssertsModifier.bind(this),
const asserts = this.tsTryParse(
this.tsParseTypePredicateAsserts.bind(this),
);

const typePredicateVariable =
this.tsIsIdentifier() &&
this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this));

if (!typePredicateVariable) {
if (!assertsModifier) {
if (!asserts) {
// : type
return this.tsParseTypeAnnotation(/* eatColon */ false, t);
}

// : asserts foo
const node = this.startNodeAtNode(t);
node.parameterName = this.parseIdentifier();
node.assertsModifier = assertsModifier;
node.asserts = asserts;
t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
return this.finishNode(t, "TSTypeAnnotation");
}
Expand All @@ -931,7 +931,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const node = this.startNodeAtNode(t);
node.parameterName = typePredicateVariable;
node.typeAnnotation = type;
node.assertsModifier = assertsModifier;
node.asserts = asserts;
t.typeAnnotation = this.finishNode(node, "TSTypePredicate");
return this.finishNode(t, "TSTypeAnnotation");
});
Expand Down Expand Up @@ -959,7 +959,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

tsParseTypePredicateAssertsModifier(): boolean {
tsParseTypePredicateAsserts(): boolean {
if (!this.tsIsIdentifier()) {
return false;
}
Expand Down
Expand Up @@ -164,7 +164,7 @@
}
}
},
"assertsModifier": true
"asserts": true
}
},
"id": null,
Expand Down Expand Up @@ -346,7 +346,7 @@
},
"name": "value"
},
"assertsModifier": true
"asserts": true
}
},
"id": null,
Expand Down Expand Up @@ -607,4 +607,4 @@
],
"directives": []
}
}
}
Expand Up @@ -156,12 +156,12 @@
},
"name": "value"
},
"assertsModifier": true
"asserts": true
}
},
"declare": true
}
],
"directives": []
}
}
}
Expand Up @@ -186,12 +186,12 @@
}
}
},
"assertsModifier": true
"asserts": true
}
},
"declare": true
}
],
"directives": []
}
}
}
Expand Up @@ -186,7 +186,7 @@
}
}
},
"assertsModifier": true
"asserts": true
}
},
"body": {
Expand Down Expand Up @@ -334,7 +334,7 @@
},
"name": "value"
},
"assertsModifier": true
"asserts": true
}
},
"body": {
Expand Down Expand Up @@ -505,4 +505,4 @@
],
"directives": []
}
}
}
4 changes: 2 additions & 2 deletions packages/babel-types/src/definitions/typescript.js
Expand Up @@ -175,11 +175,11 @@ defineType("TSTypeReference", {

defineType("TSTypePredicate", {
aliases: ["TSType"],
visitor: ["parameterName", "typeAnnotation", "assertsModifier"],
visitor: ["parameterName", "typeAnnotation", "asserts"],
fields: {
parameterName: validateType(["Identifier", "TSThisType"]),
typeAnnotation: validateOptionalType("TSTypeAnnotation"),
assertsModifier: validate(bool),
asserts: validate(bool),
},
});

Expand Down