From 65ca968f8b350778c6b1d1de6ec1dfa113a30167 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Thu, 26 Apr 2018 10:08:18 -0500 Subject: [PATCH] Allow static? as identifier in ObjectTypeProperty --- packages/babylon/src/plugins/flow.js | 5 +- .../identifier-named-static-optional/input.js | 1 + .../output.json | 142 ++++++++++++++++++ .../function-param-reserved/output.json | 33 ++++ scripts/tests/flow/flow_tests_whitelist.txt | 1 - 5 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/input.js create mode 100644 packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/output.json create mode 100644 packages/babylon/test/fixtures/flow/type-annotations/function-param-reserved/output.json diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index 2e54cb4fdb..88fa2df1a1 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -668,10 +668,13 @@ export default (superClass: Class): Class => while (!this.match(endDelim)) { let isStatic = false; const node = this.startNode(); + const lookahead = this.lookahead(); + if ( allowStatic && this.isContextual("static") && - this.lookahead().type !== tt.colon + // static is a valid identifier name + (lookahead.type !== tt.colon && lookahead.type !== tt.question) ) { this.next(); isStatic = true; diff --git a/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/input.js b/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/input.js new file mode 100644 index 0000000000..6cd2e96dda --- /dev/null +++ b/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/input.js @@ -0,0 +1 @@ +interface B { static?: number } diff --git a/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/output.json b/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/output.json new file mode 100644 index 0000000000..036b95cb86 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-optional/output.json @@ -0,0 +1,142 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "sourceType": "module", + "body": [ + { + "type": "InterfaceDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "B" + }, + "name": "B" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 14, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "key": { + "type": "Identifier", + "start": 14, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "static" + }, + "name": "static" + }, + "static": false, + "kind": "init", + "method": false, + "value": { + "type": "NumberTypeAnnotation", + "start": 23, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "variance": null, + "optional": true + } + ], + "indexers": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/type-annotations/function-param-reserved/output.json b/packages/babylon/test/fixtures/flow/type-annotations/function-param-reserved/output.json new file mode 100644 index 0000000000..016fc254c0 --- /dev/null +++ b/packages/babylon/test/fixtures/flow/type-annotations/function-param-reserved/output.json @@ -0,0 +1,33 @@ +{ + "type": "File", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "sourceType": "module", + "body": [], + "directives": [] + } +} \ No newline at end of file diff --git a/scripts/tests/flow/flow_tests_whitelist.txt b/scripts/tests/flow/flow_tests_whitelist.txt index b10179760f..dbf6781ff4 100644 --- a/scripts/tests/flow/flow_tests_whitelist.txt +++ b/scripts/tests/flow/flow_tests_whitelist.txt @@ -37,4 +37,3 @@ types/parameter_defaults/migrated_0031.js types/parameter_defaults/migrated_0032.js types/typecasts_invalid/migrated_0001.js class_method_kinds/polymorphic_getter.js -types/interfaces/prop_named_static.js