Skip to content

Commit

Permalink
fix(babel-parser): Allow line break before assert return type (#13771)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorTour committed Sep 16, 2021
1 parent 8fb5042 commit da79c90
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1316,11 +1316,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

tsParseTypePredicateAsserts(): boolean {
if (
!this.match(tt.name) ||
this.state.value !== "asserts" ||
this.hasPrecedingLineBreak()
) {
if (!this.match(tt.name) || this.state.value !== "asserts") {
return false;
}
const containsEsc = this.state.containsEsc;
Expand Down
@@ -0,0 +1,2 @@
function assert(condition: any):
asserts condition {}
@@ -0,0 +1,184 @@
{
"type": "File",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
},
"program": {
"type": "Program",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "assert"
},
"name": "assert"
},
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 16,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 30
},
"identifierName": "condition"
},
"name": "condition",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 25,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 30
}
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 27
},
"end": {
"line": 1,
"column": 30
}
}
}
}
}
],
"returnType": {
"type": "TSTypeAnnotation",
"start": 31,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 2,
"column": 17
}
},
"typeAnnotation": {
"type": "TSTypePredicate",
"start": 33,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 17
}
},
"parameterName": {
"type": "Identifier",
"start": 41,
"end": 50,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 17
},
"identifierName": "condition"
},
"name": "condition"
},
"asserts": true,
"typeAnnotation": null
}
},
"body": {
"type": "BlockStatement",
"start": 51,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 20
}
},
"body": [],
"directives": []
}
}
],
"directives": []
}
}

0 comments on commit da79c90

Please sign in to comment.