Skip to content

Commit

Permalink
rename assertsModifier to asserts (#10613)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorn0 authored and JLHwung committed Oct 29, 2019
1 parent 3a5e8a8 commit 63f9a3c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
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

0 comments on commit 63f9a3c

Please sign in to comment.