Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows the interface to be used as an Identifier for flow plugin #12254

Merged
merged 2 commits into from Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -13,7 +13,7 @@ import type { Pos, Position } from "../util/location";
import type State from "../tokenizer/state";
import { types as tc } from "../tokenizer/context";
import * as charCodes from "charcodes";
import { isIteratorStart } from "../util/identifier";
import { isIteratorStart, isKeyword } from "../util/identifier";
import {
type BindingTypes,
BIND_NONE,
Expand Down Expand Up @@ -1730,10 +1730,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// interfaces and enums
parseStatement(context: ?string, topLevel?: boolean): N.Statement {
// strict mode handling of `interface` since it's a reserved word
const lookahead = this.lookahead();
if (
this.state.strict &&
this.match(tt.name) &&
this.state.value === "interface"
this.state.value === "interface" &&
(lookahead.type === tt.name || isKeyword(lookahead.value))
existentialism marked this conversation as resolved.
Show resolved Hide resolved
) {
const node = this.startNode();
this.next();
Expand Down
@@ -0,0 +1 @@
interface = "foo";
@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:0)"
],
"program": {
"type": "Program",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"expression": {
"type": "AssignmentExpression",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
"operator": "=",
"left": {
"type": "Identifier",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9},"identifierName":"interface"},
"name": "interface"
},
"right": {
"type": "StringLiteral",
"start":12,"end":17,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":17}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
interface + 3;
@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:0)"
],
"program": {
"type": "Program",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"expression": {
"type": "BinaryExpression",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"left": {
"type": "Identifier",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9},"identifierName":"interface"},
"name": "interface"
},
"operator": "+",
"right": {
"type": "NumericLiteral",
"start":12,"end":13,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":13}},
"extra": {
"rawValue": 3,
"raw": "3"
},
"value": 3
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
interface();
@@ -0,0 +1,30 @@
{
"type": "File",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:0)"
],
"program": {
"type": "Program",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"expression": {
"type": "CallExpression",
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
"callee": {
"type": "Identifier",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9},"identifierName":"interface"},
"name": "interface"
},
"arguments": []
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
class interface {}
@@ -0,0 +1,31 @@
{
"type": "File",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:6)"
],
"program": {
"type": "Program",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"id": {
"type": "Identifier",
"start":6,"end":15,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":15},"identifierName":"interface"},
"name": "interface"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}},
"body": []
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
interface ? true : false;
@@ -0,0 +1,39 @@
{
"type": "File",
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (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": "ExpressionStatement",
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}},
"expression": {
"type": "ConditionalExpression",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"test": {
"type": "Identifier",
"start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9},"identifierName":"interface"},
"name": "interface"
},
"consequent": {
"type": "BooleanLiteral",
"start":12,"end":16,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":16}},
"value": true
},
"alternate": {
"type": "BooleanLiteral",
"start":19,"end":24,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":24}},
"value": false
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
function interface() {}
@@ -0,0 +1,34 @@
{
"type": "File",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:9)"
],
"program": {
"type": "Program",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "FunctionDeclaration",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}},
"id": {
"type": "Identifier",
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18},"identifierName":"interface"},
"name": "interface"
},
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":21,"end":23,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":23}},
"body": [],
"directives": []
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
import interface from "foo";
@@ -0,0 +1,41 @@
{
"type": "File",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:7)"
],
"program": {
"type": "Program",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start":7,"end":16,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":16}},
"local": {
"type": "Identifier",
"start":7,"end":16,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":16},"identifierName":"interface"},
"name": "interface"
}
}
],
"importKind": "value",
"source": {
"type": "StringLiteral",
"start":22,"end":27,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":27}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
}
}
],
"directives": []
}
}
@@ -0,0 +1,2 @@
foo.interface;
interface.foo;
@@ -0,0 +1,54 @@
{
"type": "File",
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":14}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (2:0)"
],
"program": {
"type": "Program",
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":14}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"expression": {
"type": "MemberExpression",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"object": {
"type": "Identifier",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"},
"name": "foo"
},
"computed": false,
"property": {
"type": "Identifier",
"start":4,"end":13,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":13},"identifierName":"interface"},
"name": "interface"
}
}
},
{
"type": "ExpressionStatement",
"start":15,"end":29,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":14}},
"expression": {
"type": "MemberExpression",
"start":15,"end":28,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
"object": {
"type": "Identifier",
"start":15,"end":24,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":9},"identifierName":"interface"},
"name": "interface"
},
"computed": false,
"property": {
"type": "Identifier",
"start":25,"end":28,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":13},"identifierName":"foo"},
"name": "foo"
}
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
new interface();
@@ -0,0 +1,31 @@
{
"type": "File",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"errors": [
"SyntaxError: Unexpected reserved word 'interface' (1:4)"
],
"program": {
"type": "Program",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"expression": {
"type": "NewExpression",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"callee": {
"type": "Identifier",
"start":4,"end":13,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":13},"identifierName":"interface"},
"name": "interface"
},
"typeArguments": null,
"arguments": []
}
}
],
"directives": []
}
}