fix: disallow expression after binding identifier of (#11355)
This commit is contained in:
parent
d18d465cf3
commit
fba64d439d
@ -3456,4 +3456,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
});
|
||||
return this.finishNode(node, "EnumDeclaration");
|
||||
}
|
||||
|
||||
updateContext(prevType: TokenType): void {
|
||||
if (
|
||||
this.match(tt.name) &&
|
||||
this.state.value === "of" &&
|
||||
prevType === tt.name &&
|
||||
this.input.slice(this.state.lastTokStart, this.state.lastTokEnd) ===
|
||||
"interface"
|
||||
) {
|
||||
this.state.exprAllowed = false;
|
||||
} else {
|
||||
super.updateContext(prevType);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -59,7 +59,10 @@ tt.name.updateContext = function(prevType) {
|
||||
let allowed = false;
|
||||
if (prevType !== tt.dot) {
|
||||
if (
|
||||
(this.state.value === "of" && !this.state.exprAllowed) ||
|
||||
(this.state.value === "of" &&
|
||||
!this.state.exprAllowed &&
|
||||
prevType !== tt._function &&
|
||||
prevType !== tt._class) ||
|
||||
(this.state.value === "yield" && this.prodParam.hasYield)
|
||||
) {
|
||||
allowed = true;
|
||||
|
||||
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
class of<T> {}
|
||||
|
||||
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx",
|
||||
"flow"
|
||||
]
|
||||
}
|
||||
40
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/output.json
vendored
Normal file
40
packages/babel-parser/test/fixtures/flow/regression/issue-10675-class/output.json
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":6,"end":8,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":8},"identifierName":"of"},
|
||||
"name": "of"
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}},
|
||||
"params": [
|
||||
{
|
||||
"type": "TypeParameter",
|
||||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10}},
|
||||
"name": "T",
|
||||
"variance": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start":12,"end":14,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":14}},
|
||||
"body": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
function of<T>() {}
|
||||
|
||||
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx",
|
||||
"flow"
|
||||
]
|
||||
}
|
||||
43
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/output.json
vendored
Normal file
43
packages/babel-parser/test/fixtures/flow/regression/issue-10675-function/output.json
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "FunctionDeclaration",
|
||||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":11,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":11},"identifierName":"of"},
|
||||
"name": "of"
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}},
|
||||
"params": [
|
||||
{
|
||||
"type": "TypeParameter",
|
||||
"start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}},
|
||||
"name": "T",
|
||||
"variance": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":17,"end":19,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":19}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
interface of<T> {}
|
||||
|
||||
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/options.json
vendored
Normal file
7
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": [
|
||||
"jsx",
|
||||
"flow"
|
||||
]
|
||||
}
|
||||
46
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/output.json
vendored
Normal file
46
packages/babel-parser/test/fixtures/flow/regression/issue-10675-interface/output.json
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "InterfaceDeclaration",
|
||||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start":10,"end":12,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":12},"identifierName":"of"},
|
||||
"name": "of"
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}},
|
||||
"params": [
|
||||
{
|
||||
"type": "TypeParameter",
|
||||
"start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}},
|
||||
"name": "T",
|
||||
"variance": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"extends": [],
|
||||
"implements": [],
|
||||
"mixins": [],
|
||||
"body": {
|
||||
"type": "ObjectTypeAnnotation",
|
||||
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}},
|
||||
"callProperties": [],
|
||||
"properties": [],
|
||||
"indexers": [],
|
||||
"internalSlots": [],
|
||||
"exact": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user