From 412da2fa15e518806ee7426ea1c41374d1225f35 Mon Sep 17 00:00:00 2001 From: Jan Melcher Date: Thu, 12 Sep 2024 17:44:37 +0200 Subject: [PATCH] fix: be more liberal with spaces in module expressions --- .../modules-validator.spec.ts | 44 +++++++++++++++++++ .../modules/expression-parser.ts | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/spec/schema/ast-validation-modules/modules-validator.spec.ts b/spec/schema/ast-validation-modules/modules-validator.spec.ts index 0025b781..4f0f3638 100644 --- a/spec/schema/ast-validation-modules/modules-validator.spec.ts +++ b/spec/schema/ast-validation-modules/modules-validator.spec.ts @@ -349,6 +349,50 @@ describe('modules validator', () => { ); }); + it('accepts an expression that starts with spaces', () => { + assertValidatorAcceptsAndDoesNotWarn( + ` + type Foo @rootEntity @modules(in: [" module1"]) { + foo: String @modules(all: true) + } + `, + { withModuleDefinitions: true }, + ); + }); + + it('accepts an expression that ends in a tab', () => { + assertValidatorAcceptsAndDoesNotWarn( + ` + type Foo @rootEntity @modules(in: ["module1 & module2\t"]) { + foo: String @modules(all: true) + } + `, + { withModuleDefinitions: true }, + ); + }); + + it('accepts an expression that ends in a space', () => { + assertValidatorAcceptsAndDoesNotWarn( + ` + type Foo @rootEntity @modules(in: ["module1 & module2 "]) { + foo: String @modules(all: true) + } + `, + { withModuleDefinitions: true }, + ); + }); + + it('accepts an and combination of two modules with multiple space characters', () => { + assertValidatorAcceptsAndDoesNotWarn( + ` + type Foo @rootEntity @modules(in: ["module1 &\tmodule2"]) { + foo: String @modules(all: true) + } + `, + { withModuleDefinitions: true }, + ); + }); + it('accepts an and combination of three modules', () => { assertValidatorAcceptsAndDoesNotWarn( ` diff --git a/src/model/implementation/modules/expression-parser.ts b/src/model/implementation/modules/expression-parser.ts index 5f70315d..377cfcc8 100644 --- a/src/model/implementation/modules/expression-parser.ts +++ b/src/model/implementation/modules/expression-parser.ts @@ -90,7 +90,7 @@ export function parseModuleSpecificationExpression( if (char === '&') { // expecting next module state = ParserState.EXPECT_IDENTIFIER; - } else if (isEOF) { + } else if (isEOF || isWhitespace) { // do nothing } else { return {