Throw a syntax error for a declare function with a body (#12054)
This commit is contained in:
1
packages/babel-parser/test/fixtures/typescript/declare/function/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/declare/function/input.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare function foo() {}
|
||||
35
packages/babel-parser/test/fixtures/typescript/declare/function/output.json
vendored
Normal file
35
packages/babel-parser/test/fixtures/typescript/declare/function/output.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
|
||||
"errors": [
|
||||
"SyntaxError: An implementation cannot be declared in ambient contexts. (1:0)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TSDeclareFunction",
|
||||
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
|
||||
"declare": true,
|
||||
"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": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":23,"end":25,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":25}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/declare/module/input.ts
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/declare/module/input.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare module m {
|
||||
function foo() {}
|
||||
}
|
||||
50
packages/babel-parser/test/fixtures/typescript/declare/module/output.json
vendored
Normal file
50
packages/babel-parser/test/fixtures/typescript/declare/module/output.json
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: An implementation cannot be declared in ambient contexts. (2:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TSModuleDeclaration",
|
||||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"m"},
|
||||
"name": "m"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSModuleBlock",
|
||||
"start":17,"end":40,"loc":{"start":{"line":1,"column":17},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":21,"end":38,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":30,"end":33,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":36,"end":38,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":19}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"declare": true
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/declare/namespace/input.ts
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/declare/namespace/input.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare namespace n {
|
||||
function foo() {}
|
||||
}
|
||||
50
packages/babel-parser/test/fixtures/typescript/declare/namespace/output.json
vendored
Normal file
50
packages/babel-parser/test/fixtures/typescript/declare/namespace/output.json
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: An implementation cannot be declared in ambient contexts. (2:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "TSModuleDeclaration",
|
||||
"start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"n"},
|
||||
"name": "n"
|
||||
},
|
||||
"body": {
|
||||
"type": "TSModuleBlock",
|
||||
"start":20,"end":43,"loc":{"start":{"line":1,"column":20},"end":{"line":3,"column":1}},
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":24,"end":41,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":33,"end":36,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"foo"},
|
||||
"name": "foo"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":39,"end":41,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":19}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"declare": true
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user