Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 13, 2020
1 parent 3acae6a commit eba0adb
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 44 deletions.
2 changes: 1 addition & 1 deletion resources/build-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (require.main === module) {

const mjs = babelBuild(srcPath, { envName: 'mjs' });
fs.writeFileSync(destPath.replace(/\.js$/, '.mjs'), mjs);
} else if (filepath.endsWith('.d.ts') || filepath.endsWith('.json')) {
} else if (filepath.endsWith('.d.ts')) {
fs.copyFileSync(srcPath, destPath);
}
}
Expand Down
197 changes: 154 additions & 43 deletions src/language/experimentalOnlineParser/grammar.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
export type GraphQLGrammarType = {
[string]: GraphQLGrammarRule,
};
export type GraphQLGrammarType = {|
[name: string]: GraphQLGrammarRule,
|};
export type GraphQLGrammarRuleName = string;
export type GraphQLGrammarRuleConstraint =
| GraphQLGrammarTokenConstraint
| GraphQLGrammarOfTypeConstraint
| GraphQLGrammarListOfTypeConstraint
| GraphQLGrammarPeekConstraint;
export type GraphQLGrammarConstraintsSet = Array<GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint>;
export type GraphQLGrammarRule = GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint | GraphQLGrammarConstraintsSet;
export type GraphQLGrammarConstraintsSet = Array<
GraphQLGrammarRuleName | GraphQLGrammarRuleConstraint,
>;
export type GraphQLGrammarRule =
| GraphQLGrammarRuleName
| GraphQLGrammarRuleConstraint
| GraphQLGrammarConstraintsSet;
export interface GraphQLGrammarBaseRuleConstraint {
butNot?: ?GraphQLGrammarTokenConstraint | ?Array<GraphQLGrammarTokenConstraint>;
butNot?:
| ?GraphQLGrammarTokenConstraint
| ?Array<GraphQLGrammarTokenConstraint>;
optional?: boolean;
eatNextOnFail?: boolean;
}
export interface GraphQLGrammarTokenConstraint extends GraphQLGrammarBaseRuleConstraint {
export interface GraphQLGrammarTokenConstraint
extends GraphQLGrammarBaseRuleConstraint {
token:
| '!'
| '$'
Expand Down Expand Up @@ -42,14 +50,17 @@ export interface GraphQLGrammarTokenConstraint extends GraphQLGrammarBaseRuleCon
definitionName?: boolean;
typeName?: boolean;
}
export interface GraphQLGrammarOfTypeConstraint extends GraphQLGrammarBaseRuleConstraint {
export interface GraphQLGrammarOfTypeConstraint
extends GraphQLGrammarBaseRuleConstraint {
ofType: GraphQLGrammarRule;
tokenName?: string;
}
export interface GraphQLGrammarListOfTypeConstraint extends GraphQLGrammarBaseRuleConstraint {
export interface GraphQLGrammarListOfTypeConstraint
extends GraphQLGrammarBaseRuleConstraint {
listOfType: GraphQLGrammarRuleName;
}
export interface GraphQLGrammarPeekConstraint extends GraphQLGrammarBaseRuleConstraint {
export interface GraphQLGrammarPeekConstraint
extends GraphQLGrammarBaseRuleConstraint {
peek: Array<GraphQLGrammarPeekConstraintCondition>;
}
export interface GraphQLGrammarPeekConstraintCondition {
Expand All @@ -58,10 +69,10 @@ export interface GraphQLGrammarPeekConstraintCondition {
end?: boolean;
}

const grammar: GraphQLGrammarType = {
Name: ({ token: 'Name' }: GraphQLGrammarTokenConstraint),
String: ({ token: 'String' }: GraphQLGrammarTokenConstraint),
BlockString: ({ token: 'BlockString' }: GraphQLGrammarTokenConstraint),
const grammar: GraphQLGrammarType = ({
Name: { token: 'Name' },
String: { token: 'String' },
BlockString: { token: 'BlockString' },

Document: { listOfType: 'Definition' },
Definition: {
Expand All @@ -80,7 +91,16 @@ const grammar: GraphQLGrammarType = {
{
ifCondition: {
token: 'Name',
oneOf: ['schema', 'scalar', 'type', 'interface', 'union', 'enum', 'input', 'directive'],
oneOf: [
'schema',
'scalar',
'type',
'interface',
'union',
'enum',
'input',
'directive',
],
},
expect: 'TypeSystemDefinition',
},
Expand All @@ -103,7 +123,7 @@ const grammar: GraphQLGrammarType = {
],
},

OperationDefinition: ({
OperationDefinition: {
peek: [
{
ifCondition: { token: '{' },
Expand All @@ -128,7 +148,7 @@ const grammar: GraphQLGrammarType = {
],
},
],
}: GraphQLGrammarPeekConstraint),
},
OperationType: {
ofType: 'OperationTypeName',
},
Expand Down Expand Up @@ -165,9 +185,16 @@ const grammar: GraphQLGrammarType = {
],

Arguments: [{ token: '(' }, { listOfType: 'Argument' }, { token: ')' }],
Argument: [{ token: 'Name', tokenName: 'ArgumentName', definitionName: true }, { token: ':' }, 'Value'],
Argument: [
{ token: 'Name', tokenName: 'ArgumentName', definitionName: true },
{ token: ':' },
'Value',
],

Alias: [{ token: 'Name', tokenName: 'AliasName', definitionName: true }, { token: ':' }],
Alias: [
{ token: 'Name', tokenName: 'AliasName', definitionName: true },
{ token: ':' },
],

Fragment: [
{ token: '...' },
Expand Down Expand Up @@ -211,7 +238,10 @@ const grammar: GraphQLGrammarType = {
definitionName: true,
},

TypeCondition: [{ token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' }, 'TypeName'],
TypeCondition: [
{ token: 'Name', ofValue: 'on', tokenName: 'OnKeyword' },
'TypeName',
],

InlineFragment: [
{ ofType: 'TypeCondition', optional: true },
Expand Down Expand Up @@ -340,19 +370,44 @@ const grammar: GraphQLGrammarType = {
tokenName: 'EnumValue',
},

ListValue: [{ token: '[' }, { listOfType: 'Value', optional: true }, { token: ']' }],
ListValue: [
{ token: '[' },
{ listOfType: 'Value', optional: true },
{ token: ']' },
],

ConstListValue: [{ token: '[' }, { listOfType: 'ConstValue', optional: true }, { token: ']' }],
ConstListValue: [
{ token: '[' },
{ listOfType: 'ConstValue', optional: true },
{ token: ']' },
],

ObjectValue: [{ token: '{' }, { listOfType: 'ObjectField', optional: true }, { token: '}' }],
ObjectField: [{ token: 'Name', tokenName: 'ObjectFieldName' }, { token: ':' }, { ofType: 'ConstValue' }],
ObjectValue: [
{ token: '{' },
{ listOfType: 'ObjectField', optional: true },
{ token: '}' },
],
ObjectField: [
{ token: 'Name', tokenName: 'ObjectFieldName' },
{ token: ':' },
{ ofType: 'ConstValue' },
],

Variable: [
{ token: '$', tokenName: 'VariableName' },
{ token: 'Name', tokenName: 'VariableName' },
],
VariableDefinitions: [{ token: '(' }, { listOfType: 'VariableDefinition' }, { token: ')' }],
VariableDefinition: ['Variable', { token: ':' }, 'Type', { ofType: 'DefaultValue', optional: true }],
VariableDefinitions: [
{ token: '(' },
{ listOfType: 'VariableDefinition' },
{ token: ')' },
],
VariableDefinition: [
'Variable',
{ token: ':' },
'Type',
{ ofType: 'DefaultValue', optional: true },
],
DefaultValue: [{ token: '=' }, 'ConstValue'],

TypeName: { token: 'Name', tokenName: 'TypeName', typeName: true },
Expand All @@ -369,7 +424,12 @@ const grammar: GraphQLGrammarType = {
},
],
},
ListType: [{ token: '[' }, { listOfType: 'Type' }, { token: ']' }, { token: '!', optional: true }],
ListType: [
{ token: '[' },
{ listOfType: 'Type' },
{ token: ']' },
{ token: '!', optional: true },
],

Directives: { listOfType: 'Directive' },
Directive: [
Expand Down Expand Up @@ -524,14 +584,22 @@ const grammar: GraphQLGrammarType = {
expect: [
'Directives',
{
ofType: [{ token: '{' }, { listOfType: 'RootOperationTypeDefinition' }, { token: '}' }],
ofType: [
{ token: '{' },
{ listOfType: 'RootOperationTypeDefinition' },
{ token: '}' },
],
optional: true,
},
],
},
{
ifCondition: { token: '{' },
expect: [{ token: '{' }, { listOfType: 'RootOperationTypeDefinition' }, { token: '}' }],
expect: [
{ token: '{' },
{ listOfType: 'RootOperationTypeDefinition' },
{ token: '}' },
],
},
],
},
Expand Down Expand Up @@ -591,7 +659,11 @@ const grammar: GraphQLGrammarType = {
},
],
ImplementsAdditionalInterfaceName: [{ token: '&' }, 'TypeName'],
FieldsDefinition: [{ token: '{' }, { listOfType: 'FieldDefinition' }, { token: '}' }],
FieldsDefinition: [
{ token: '{' },
{ listOfType: 'FieldDefinition' },
{ token: '}' },
],
FieldDefinition: [
{ ofType: 'Description', optional: true },
{ token: 'Name', tokenName: 'AliasName', definitionName: true },
Expand All @@ -601,7 +673,11 @@ const grammar: GraphQLGrammarType = {
{ ofType: 'Directives', optional: true },
],

ArgumentsDefinition: [{ token: '(' }, { listOfType: 'InputValueDefinition' }, { token: ')' }],
ArgumentsDefinition: [
{ token: '(' },
{ listOfType: 'InputValueDefinition' },
{ token: ')' },
],
InputValueDefinition: [
{ ofType: 'Description', optional: true },
{ token: 'Name', tokenName: 'ArgumentName' },
Expand Down Expand Up @@ -633,7 +709,10 @@ const grammar: GraphQLGrammarType = {
peek: [
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
expect: [
'Directives',
{ ofType: 'FieldsDefinition', optional: true },
],
},
{
ifCondition: { token: '{' },
Expand All @@ -646,7 +725,10 @@ const grammar: GraphQLGrammarType = {
},
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
expect: [
'Directives',
{ ofType: 'FieldsDefinition', optional: true },
],
},
{
ifCondition: { token: '{' },
Expand Down Expand Up @@ -684,7 +766,10 @@ const grammar: GraphQLGrammarType = {
peek: [
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'FieldsDefinition', optional: true }],
expect: [
'Directives',
{ ofType: 'FieldsDefinition', optional: true },
],
},
{
ifCondition: { token: '{' },
Expand Down Expand Up @@ -734,7 +819,10 @@ const grammar: GraphQLGrammarType = {
peek: [
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'UnionMemberTypes', optional: true }],
expect: [
'Directives',
{ ofType: 'UnionMemberTypes', optional: true },
],
},
{
ifCondition: { token: '=' },
Expand All @@ -755,7 +843,11 @@ const grammar: GraphQLGrammarType = {
{ ofType: 'Directives', optional: true },
{ ofType: 'EnumValuesDefinition', optional: true },
],
EnumValuesDefinition: [{ token: '{' }, { listOfType: 'EnumValueDefinition' }, { token: '}' }],
EnumValuesDefinition: [
{ token: '{' },
{ listOfType: 'EnumValueDefinition' },
{ token: '}' },
],
EnumValueDefinition: [
{ ofType: 'Description', optional: true },
'EnumValue',
Expand All @@ -778,7 +870,10 @@ const grammar: GraphQLGrammarType = {
peek: [
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'EnumValuesDefinition', optional: true }],
expect: [
'Directives',
{ ofType: 'EnumValuesDefinition', optional: true },
],
},
{
ifCondition: { token: '{' },
Expand All @@ -799,7 +894,11 @@ const grammar: GraphQLGrammarType = {
{ ofType: 'Directives', optional: true },
{ ofType: 'InputFieldsDefinition', optional: true },
],
InputFieldsDefinition: [{ token: '{' }, { listOfType: 'InputValueDefinition' }, { token: '}' }],
InputFieldsDefinition: [
{ token: '{' },
{ listOfType: 'InputValueDefinition' },
{ token: '}' },
],

InputObjectTypeExtension: [
{
Expand All @@ -817,7 +916,10 @@ const grammar: GraphQLGrammarType = {
peek: [
{
ifCondition: { token: '@' },
expect: ['Directives', { ofType: 'InputFieldsDefinition', optional: true }],
expect: [
'Directives',
{ ofType: 'InputFieldsDefinition', optional: true },
],
},
{
ifCondition: { token: '{' },
Expand Down Expand Up @@ -863,10 +965,18 @@ const grammar: GraphQLGrammarType = {
},
ExecutableDirectiveLocation: {
token: 'Name',
oneOf: ['QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
oneOf: [
'QUERY',
'MUTATION',
'SUBSCRIPTION',
'FIELD',
'FRAGMENT_DEFINITION',
'FRAGMENT_SPREAD',
'INLINE_FRAGMENT',
],
tokenName: 'EnumValue',
},
TypeSystemDirectiveLocation: ({
TypeSystemDirectiveLocation: {
token: 'Name',
oneOf: [
'SCHEMA',
Expand All @@ -882,7 +992,8 @@ const grammar: GraphQLGrammarType = {
'INPUT_FIELD_DEFINITION',
],
tokenName: 'EnumValue',
}: GraphQLGrammarTokenConstraint),
};
},
// FIXME: enfource proper typing
}: any);

export default grammar;
Loading

0 comments on commit eba0adb

Please sign in to comment.