Skip to content

Commit 4bfd46e

Browse files
committed
Fix build
1 parent 3acae6a commit 4bfd46e

File tree

3 files changed

+156
-44
lines changed

3 files changed

+156
-44
lines changed

resources/build-npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (require.main === module) {
2626

2727
const mjs = babelBuild(srcPath, { envName: 'mjs' });
2828
fs.writeFileSync(destPath.replace(/\.js$/, '.mjs'), mjs);
29-
} else if (filepath.endsWith('.d.ts') || filepath.endsWith('.json')) {
29+
} else if (filepath.endsWith('.d.ts')) {
3030
fs.copyFileSync(srcPath, destPath);
3131
}
3232
}

src/language/experimentalOnlineParser/grammar.js

Lines changed: 154 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
export type GraphQLGrammarType = {
2-
[string]: GraphQLGrammarRule,
3-
};
1+
export type GraphQLGrammarType = {|
2+
[name: string]: GraphQLGrammarRule,
3+
|};
44
export type GraphQLGrammarRuleName = string;
55
export type GraphQLGrammarRuleConstraint =
66
| GraphQLGrammarTokenConstraint
77
| GraphQLGrammarOfTypeConstraint
88
| GraphQLGrammarListOfTypeConstraint
99
| GraphQLGrammarPeekConstraint;
10-
export type GraphQLGrammarConstraintsSet = Array<GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint>;
11-
export type GraphQLGrammarRule = GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint | GraphQLGrammarConstraintsSet;
10+
export type GraphQLGrammarConstraintsSet = Array<
11+
GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint,
12+
>;
13+
export type GraphQLGrammarRule =
14+
| GraphQLGrammarRuleName
15+
| GraphQLGrammarRuleConstraint
16+
| GraphQLGrammarConstraintsSet;
1217
export interface GraphQLGrammarBaseRuleConstraint {
13-
butNot?: ?GraphQLGrammarTokenConstraint | ?Array<GraphQLGrammarTokenConstraint>;
18+
butNot?:
19+
| ?GraphQLGrammarTokenConstraint
20+
| ?Array<GraphQLGrammarTokenConstraint>;
1421
optional?: boolean;
1522
eatNextOnFail?: boolean;
1623
}
17-
export interface GraphQLGrammarTokenConstraint extends GraphQLGrammarBaseRuleConstraint {
24+
export interface GraphQLGrammarTokenConstraint
25+
extends GraphQLGrammarBaseRuleConstraint {
1826
token:
1927
| '!'
2028
| '$'
@@ -42,14 +50,17 @@ export interface GraphQLGrammarTokenConstraint extends GraphQLGrammarBaseRuleCon
4250
definitionName?: boolean;
4351
typeName?: boolean;
4452
}
45-
export interface GraphQLGrammarOfTypeConstraint extends GraphQLGrammarBaseRuleConstraint {
53+
export interface GraphQLGrammarOfTypeConstraint
54+
extends GraphQLGrammarBaseRuleConstraint {
4655
ofType: GraphQLGrammarRule;
4756
tokenName?: string;
4857
}
49-
export interface GraphQLGrammarListOfTypeConstraint extends GraphQLGrammarBaseRuleConstraint {
58+
export interface GraphQLGrammarListOfTypeConstraint
59+
extends GraphQLGrammarBaseRuleConstraint {
5060
listOfType: GraphQLGrammarRuleName;
5161
}
52-
export interface GraphQLGrammarPeekConstraint extends GraphQLGrammarBaseRuleConstraint {
62+
export interface GraphQLGrammarPeekConstraint
63+
extends GraphQLGrammarBaseRuleConstraint {
5364
peek: Array<GraphQLGrammarPeekConstraintCondition>;
5465
}
5566
export interface GraphQLGrammarPeekConstraintCondition {
@@ -58,10 +69,10 @@ export interface GraphQLGrammarPeekConstraintCondition {
5869
end?: boolean;
5970
}
6071

61-
const grammar: GraphQLGrammarType = {
62-
Name: ({ token: 'Name' }: GraphQLGrammarTokenConstraint),
63-
String: ({ token: 'String' }: GraphQLGrammarTokenConstraint),
64-
BlockString: ({ token: 'BlockString' }: GraphQLGrammarTokenConstraint),
72+
const grammar: GraphQLGrammarType = ({
73+
Name: { token: 'Name' },
74+
String: { token: 'String' },
75+
BlockString: { token: 'BlockString' },
6576

6677
Document: { listOfType: 'Definition' },
6778
Definition: {
@@ -80,7 +91,16 @@ const grammar: GraphQLGrammarType = {
8091
{
8192
ifCondition: {
8293
token: 'Name',
83-
oneOf: ['schema', 'scalar', 'type', 'interface', 'union', 'enum', 'input', 'directive'],
94+
oneOf: [
95+
'schema',
96+
'scalar',
97+
'type',
98+
'interface',
99+
'union',
100+
'enum',
101+
'input',
102+
'directive',
103+
],
84104
},
85105
expect: 'TypeSystemDefinition',
86106
},
@@ -103,7 +123,7 @@ const grammar: GraphQLGrammarType = {
103123
],
104124
},
105125

106-
OperationDefinition: ({
126+
OperationDefinition: {
107127
peek: [
108128
{
109129
ifCondition: { token: '{' },
@@ -128,7 +148,7 @@ const grammar: GraphQLGrammarType = {
128148
],
129149
},
130150
],
131-
}: GraphQLGrammarPeekConstraint),
151+
},
132152
OperationType: {
133153
ofType: 'OperationTypeName',
134154
},
@@ -165,9 +185,16 @@ const grammar: GraphQLGrammarType = {
165185
],
166186

167187
Arguments: [{ token: '(' }, { listOfType: 'Argument' }, { token: ')' }],
168-
Argument: [{ token: 'Name', tokenName: 'ArgumentName', definitionName: true }, { token: ':' }, 'Value'],
188+
Argument: [
189+
{ token: 'Name', tokenName: 'ArgumentName', definitionName: true },
190+
{ token: ':' },
191+
'Value',
192+
],
169193

170-
Alias: [{ token: 'Name', tokenName: 'AliasName', definitionName: true }, { token: ':' }],
194+
Alias: [
195+
{ token: 'Name', tokenName: 'AliasName', definitionName: true },
196+
{ token: ':' },
197+
],
171198

172199
Fragment: [
173200
{ token: '...' },
@@ -211,7 +238,10 @@ const grammar: GraphQLGrammarType = {
211238
definitionName: true,
212239
},
213240

214-
TypeCondition: [{ token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' }, 'TypeName'],
241+
TypeCondition: [
242+
{ token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' },
243+
'TypeName',
244+
],
215245

216246
InlineFragment: [
217247
{ ofType: 'TypeCondition', optional: true },
@@ -340,19 +370,44 @@ const grammar: GraphQLGrammarType = {
340370
tokenName: 'EnumValue',
341371
},
342372

343-
ListValue: [{ token: '[' }, { listOfType: 'Value', optional: true }, { token: ']' }],
373+
ListValue: [
374+
{ token: '[' },
375+
{ listOfType: 'Value', optional: true },
376+
{ token: ']' },
377+
],
344378

345-
ConstListValue: [{ token: '[' }, { listOfType: 'ConstValue', optional: true }, { token: ']' }],
379+
ConstListValue: [
380+
{ token: '[' },
381+
{ listOfType: 'ConstValue', optional: true },
382+
{ token: ']' },
383+
],
346384

347-
ObjectValue: [{ token: '{' }, { listOfType: 'ObjectField', optional: true }, { token: '}' }],
348-
ObjectField: [{ token: 'Name', tokenName: 'ObjectFieldName' }, { token: ':' }, { ofType: 'ConstValue' }],
385+
ObjectValue: [
386+
{ token: '{' },
387+
{ listOfType: 'ObjectField', optional: true },
388+
{ token: '}' },
389+
],
390+
ObjectField: [
391+
{ token: 'Name', tokenName: 'ObjectFieldName' },
392+
{ token: ':' },
393+
{ ofType: 'ConstValue' },
394+
],
349395

350396
Variable: [
351397
{ token: '$', tokenName: 'VariableName' },
352398
{ token: 'Name', tokenName: 'VariableName' },
353399
],
354-
VariableDefinitions: [{ token: '(' }, { listOfType: 'VariableDefinition' }, { token: ')' }],
355-
VariableDefinition: ['Variable', { token: ':' }, 'Type', { ofType: 'DefaultValue', optional: true }],
400+
VariableDefinitions: [
401+
{ token: '(' },
402+
{ listOfType: 'VariableDefinition' },
403+
{ token: ')' },
404+
],
405+
VariableDefinition: [
406+
'Variable',
407+
{ token: ':' },
408+
'Type',
409+
{ ofType: 'DefaultValue', optional: true },
410+
],
356411
DefaultValue: [{ token: '=' }, 'ConstValue'],
357412

358413
TypeName: { token: 'Name', tokenName: 'TypeName', typeName: true },
@@ -369,7 +424,12 @@ const grammar: GraphQLGrammarType = {
369424
},
370425
],
371426
},
372-
ListType: [{ token: '[' }, { listOfType: 'Type' }, { token: ']' }, { token: '!', optional: true }],
427+
ListType: [
428+
{ token: '[' },
429+
{ listOfType: 'Type' },
430+
{ token: ']' },
431+
{ token: '!', optional: true },
432+
],
373433

374434
Directives: { listOfType: 'Directive' },
375435
Directive: [
@@ -524,14 +584,22 @@ const grammar: GraphQLGrammarType = {
524584
expect: [
525585
'Directives',
526586
{
527-
ofType: [{ token: '{' }, { listOfType: 'RootOperationTypeDefinition' }, { token: '}' }],
587+
ofType: [
588+
{ token: '{' },
589+
{ listOfType: 'RootOperationTypeDefinition' },
590+
{ token: '}' },
591+
],
528592
optional: true,
529593
},
530594
],
531595
},
532596
{
533597
ifCondition: { token: '{' },
534-
expect: [{ token: '{' }, { listOfType: 'RootOperationTypeDefinition' }, { token: '}' }],
598+
expect: [
599+
{ token: '{' },
600+
{ listOfType: 'RootOperationTypeDefinition' },
601+
{ token: '}' },
602+
],
535603
},
536604
],
537605
},
@@ -591,7 +659,11 @@ const grammar: GraphQLGrammarType = {
591659
},
592660
],
593661
ImplementsAdditionalInterfaceName: [{ token: '&' }, 'TypeName'],
594-
FieldsDefinition: [{ token: '{' }, { listOfType: 'FieldDefinition' }, { token: '}' }],
662+
FieldsDefinition: [
663+
{ token: '{' },
664+
{ listOfType: 'FieldDefinition' },
665+
{ token: '}' },
666+
],
595667
FieldDefinition: [
596668
{ ofType: 'Description', optional: true },
597669
{ token: 'Name', tokenName: 'AliasName', definitionName: true },
@@ -601,7 +673,11 @@ const grammar: GraphQLGrammarType = {
601673
{ ofType: 'Directives', optional: true },
602674
],
603675

604-
ArgumentsDefinition: [{ token: '(' }, { listOfType: 'InputValueDefinition' }, { token: ')' }],
676+
ArgumentsDefinition: [
677+
{ token: '(' },
678+
{ listOfType: 'InputValueDefinition' },
679+
{ token: ')' },
680+
],
605681
InputValueDefinition: [
606682
{ ofType: 'Description', optional: true },
607683
{ token: 'Name', tokenName: 'ArgumentName' },
@@ -633,7 +709,10 @@ const grammar: GraphQLGrammarType = {
633709
peek: [
634710
{
635711
ifCondition: { token: '@' },
636-
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
712+
expect: [
713+
'Directives',
714+
{ ofType: 'FieldsDefinition', optional: true },
715+
],
637716
},
638717
{
639718
ifCondition: { token: '{' },
@@ -646,7 +725,10 @@ const grammar: GraphQLGrammarType = {
646725
},
647726
{
648727
ifCondition: { token: '@' },
649-
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
728+
expect: [
729+
'Directives',
730+
{ ofType: 'FieldsDefinition', optional: true },
731+
],
650732
},
651733
{
652734
ifCondition: { token: '{' },
@@ -684,7 +766,10 @@ const grammar: GraphQLGrammarType = {
684766
peek: [
685767
{
686768
ifCondition: { token: '@' },
687-
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
769+
expect: [
770+
'Directives',
771+
{ ofType: 'FieldsDefinition', optional: true },
772+
],
688773
},
689774
{
690775
ifCondition: { token: '{' },
@@ -734,7 +819,10 @@ const grammar: GraphQLGrammarType = {
734819
peek: [
735820
{
736821
ifCondition: { token: '@' },
737-
expect: ['Directives', { ofType: 'UnionMemberTypes', optional: true }],
822+
expect: [
823+
'Directives',
824+
{ ofType: 'UnionMemberTypes', optional: true },
825+
],
738826
},
739827
{
740828
ifCondition: { token: '=' },
@@ -755,7 +843,11 @@ const grammar: GraphQLGrammarType = {
755843
{ ofType: 'Directives', optional: true },
756844
{ ofType: 'EnumValuesDefinition', optional: true },
757845
],
758-
EnumValuesDefinition: [{ token: '{' }, { listOfType: 'EnumValueDefinition' }, { token: '}' }],
846+
EnumValuesDefinition: [
847+
{ token: '{' },
848+
{ listOfType: 'EnumValueDefinition' },
849+
{ token: '}' },
850+
],
759851
EnumValueDefinition: [
760852
{ ofType: 'Description', optional: true },
761853
'EnumValue',
@@ -778,7 +870,10 @@ const grammar: GraphQLGrammarType = {
778870
peek: [
779871
{
780872
ifCondition: { token: '@' },
781-
expect: ['Directives', { ofType: 'EnumValuesDefinition', optional: true }],
873+
expect: [
874+
'Directives',
875+
{ ofType: 'EnumValuesDefinition', optional: true },
876+
],
782877
},
783878
{
784879
ifCondition: { token: '{' },
@@ -799,7 +894,11 @@ const grammar: GraphQLGrammarType = {
799894
{ ofType: 'Directives', optional: true },
800895
{ ofType: 'InputFieldsDefinition', optional: true },
801896
],
802-
InputFieldsDefinition: [{ token: '{' }, { listOfType: 'InputValueDefinition' }, { token: '}' }],
897+
InputFieldsDefinition: [
898+
{ token: '{' },
899+
{ listOfType: 'InputValueDefinition' },
900+
{ token: '}' },
901+
],
803902

804903
InputObjectTypeExtension: [
805904
{
@@ -817,7 +916,10 @@ const grammar: GraphQLGrammarType = {
817916
peek: [
818917
{
819918
ifCondition: { token: '@' },
820-
expect: ['Directives', { ofType: 'InputFieldsDefinition', optional: true }],
919+
expect: [
920+
'Directives',
921+
{ ofType: 'InputFieldsDefinition', optional: true },
922+
],
821923
},
822924
{
823925
ifCondition: { token: '{' },
@@ -863,10 +965,18 @@ const grammar: GraphQLGrammarType = {
863965
},
864966
ExecutableDirectiveLocation: {
865967
token: 'Name',
866-
oneOf: ['QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
968+
oneOf: [
969+
'QUERY',
970+
'MUTATION',
971+
'SUBSCRIPTION',
972+
'FIELD',
973+
'FRAGMENT_DEFINITION',
974+
'FRAGMENT_SPREAD',
975+
'INLINE_FRAGMENT',
976+
],
867977
tokenName: 'EnumValue',
868978
},
869-
TypeSystemDirectiveLocation: ({
979+
TypeSystemDirectiveLocation: {
870980
token: 'Name',
871981
oneOf: [
872982
'SCHEMA',
@@ -882,7 +992,8 @@ const grammar: GraphQLGrammarType = {
882992
'INPUT_FIELD_DEFINITION',
883993
],
884994
tokenName: 'EnumValue',
885-
}: GraphQLGrammarTokenConstraint),
886-
};
995+
},
996+
// FIXME: enfource proper typing
997+
}: any);
887998

888999
export default grammar;

0 commit comments

Comments
 (0)