Skip to content

Commit

Permalink
Print ObjectTypeInternalSlot with both flow/babel parsers (#4869)
Browse files Browse the repository at this point in the history
* Print ObjectTypeInternalSlot with both flow/babel parsers

* chore: update to flow-parser@0.78.0

* test: update snapshot
  • Loading branch information
existentialism authored and suchipi committed Aug 8, 2018
1 parent 418a04b commit 1391891
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
"esutils": "2.0.2",
"find-parent-dir": "0.3.0",
"find-project-root": "1.1.1",
"flow-parser": "0.75.0",
"flow-parser": "0.78.0",
"get-stream": "3.0.0",
"globby": "6.1.0",
"graphql": "0.13.2",
Expand Down
20 changes: 17 additions & 3 deletions src/language-js/printer-estree.js
Expand Up @@ -1086,6 +1086,18 @@ function printPathNoParens(path, options, print, args) {
parts.push(path.call(print, "body"));

return concat(parts);

case "ObjectTypeInternalSlot":
return concat([
n.static ? "static " : "",
"[[",
path.call(print, "id"),
"]]",
printOptionalToken(path),
n.method ? "" : ": ",
path.call(print, "value")
]);

case "ObjectExpression":
case "ObjectPattern":
case "ObjectTypeAnnotation":
Expand Down Expand Up @@ -1140,7 +1152,7 @@ function printPathNoParens(path, options, print, args) {
}

if (isTypeAnnotation) {
fields.push("indexers", "callProperties");
fields.push("indexers", "callProperties", "internalSlots");
}
fields.push(propertiesField);

Expand Down Expand Up @@ -2414,7 +2426,8 @@ function printPathNoParens(path, options, print, args) {
let isArrowFunctionTypeAnnotation =
n.type === "TSFunctionType" ||
!(
(parent.type === "ObjectTypeProperty" &&
((parent.type === "ObjectTypeProperty" ||
parent.type === "ObjectTypeInternalSlot") &&
!getFlowVariance(parent) &&
!parent.optional &&
options.locStart(parent) === options.locStart(n)) ||
Expand Down Expand Up @@ -5553,7 +5566,8 @@ function isMemberExpressionChain(node) {
// type T = { method(): void };
function isObjectTypePropertyAFunction(node, options) {
return (
node.type === "ObjectTypeProperty" &&
(node.type === "ObjectTypeProperty" ||
node.type === "ObjectTypeInternalSlot") &&
node.value.type === "FunctionTypeAnnotation" &&
!node.static &&
!isFunctionNotation(node, options)
Expand Down
20 changes: 20 additions & 0 deletions tests/flow_internal_slot/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`internal_slot.js - flow-verify 1`] = `
declare class C { static [[foo]]: T }
declare class C { [[foo]]: T }
interface T { [[foo]]: X }
interface T { [[foo]](): X }
type T = { [[foo]]: X }
type T = { [[foo]](): X }
type T = { [[foo]]?: X }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare class C { static [[foo]]: T }
declare class C { [[foo]]: T }
interface T { [[foo]]: X }
interface T { [[foo]](): X }
type T = { [[foo]]: X };
type T = { [[foo]](): X };
type T = { [[foo]]?: X };
`;
7 changes: 7 additions & 0 deletions tests/flow_internal_slot/internal_slot.js
@@ -0,0 +1,7 @@
declare class C { static [[foo]]: T }
declare class C { [[foo]]: T }
interface T { [[foo]]: X }
interface T { [[foo]](): X }
type T = { [[foo]]: X }
type T = { [[foo]](): X }
type T = { [[foo]]?: X }
1 change: 1 addition & 0 deletions tests/flow_internal_slot/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["flow", "babylon"]);
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -2377,9 +2377,9 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"

flow-parser@0.75.0:
version "0.75.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.75.0.tgz#9a1891c48051c73017b6b5cc07b3681fda3fdfb0"
flow-parser@0.78.0:
version "0.78.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.78.0.tgz#4ec829a97fa68cff6e97691dfff7b6ddebbc187c"

for-in@^1.0.1, for-in@^1.0.2:
version "1.0.2"
Expand Down

0 comments on commit 1391891

Please sign in to comment.