Skip to content

Commit

Permalink
Register function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 4, 2019
1 parent b5a5c63 commit c2428b0
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>

switch (starttype) {
case tt._function:
return this.parseFunctionStatement(nany);
return this.parseFunctionStatement(
nany,
/* async */ false,
/* declarationPosition */ true,
);
case tt._class:
return this.parseClass(
nany,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function foo(): void;

export { foo };
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"type": "File",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 15
}
},
"program": {
"type": "Program",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 15
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "TSDeclareFunction",
"start": 0,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 29
}
},
"id": {
"type": "Identifier",
"start": 17,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 20
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": false,
"async": false,
"params": [],
"returnType": {
"type": "TSTypeAnnotation",
"start": 22,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 28
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 24,
"end": 28,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 28
}
}
}
},
"declare": true
},
{
"type": "ExportNamedDeclaration",
"start": 31,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 15
}
},
"specifiers": [
{
"type": "ExportSpecifier",
"start": 40,
"end": 43,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 12
}
},
"local": {
"type": "Identifier",
"start": 40,
"end": 43,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 12
},
"identifierName": "foo"
},
"name": "foo"
},
"exported": {
"type": "Identifier",
"start": 40,
"end": 43,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 12
},
"identifierName": "foo"
},
"name": "foo"
}
}
],
"source": null,
"declaration": null
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { foo };

declare function foo(): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
"type": "File",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 29
}
},
"program": {
"type": "Program",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 29
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start": 0,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 15
}
},
"specifiers": [
{
"type": "ExportSpecifier",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
}
},
"local": {
"type": "Identifier",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "foo"
},
"name": "foo"
},
"exported": {
"type": "Identifier",
"start": 9,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "foo"
},
"name": "foo"
}
}
],
"source": null,
"declaration": null
},
{
"type": "TSDeclareFunction",
"start": 17,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 29
}
},
"id": {
"type": "Identifier",
"start": 34,
"end": 37,
"loc": {
"start": {
"line": 3,
"column": 17
},
"end": {
"line": 3,
"column": 20
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": false,
"async": false,
"params": [],
"returnType": {
"type": "TSTypeAnnotation",
"start": 39,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 3,
"column": 28
}
},
"typeAnnotation": {
"type": "TSVoidKeyword",
"start": 41,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 24
},
"end": {
"line": 3,
"column": 28
}
}
}
},
"declare": true
}
],
"directives": []
}
}

0 comments on commit c2428b0

Please sign in to comment.