@@ -137,12 +137,21 @@ function parseDirectiveKeyStatically(
137137 }
138138 }
139139
140- const [ nameOrArgument , ...modifiers ] = text
140+ if ( directiveKey . name != null && text [ i ] === "[" ) {
141+ // Dynamic argument.
142+ const len = text . slice ( i ) . lastIndexOf ( "]" )
143+ if ( len !== - 1 ) {
144+ directiveKey . argument = createIdentifier ( i , i + len + 1 )
145+ i = i + len + 1 + ( text [ i + len + 1 ] === "." ? 1 : 0 )
146+ }
147+ }
148+
149+ const modifiers = text
141150 . slice ( i )
142151 . split ( "." )
143152 . map ( modifierName => {
144153 const modifier = createIdentifier ( i , i + modifierName . length )
145- if ( modifierName === "" ) {
154+ if ( modifierName === "" && i < text . length ) {
146155 insertError (
147156 document ,
148157 new ParseError (
@@ -159,9 +168,9 @@ function parseDirectiveKeyStatically(
159168 } )
160169
161170 if ( directiveKey . name == null ) {
162- directiveKey . name = nameOrArgument
163- } else if ( nameOrArgument . name !== "" ) {
164- directiveKey . argument = nameOrArgument
171+ directiveKey . name = modifiers . shift ( ) !
172+ } else if ( directiveKey . argument == null && modifiers [ 0 ] . name !== "" ) {
173+ directiveKey . argument = modifiers . shift ( ) || null
165174 }
166175 directiveKey . modifiers = modifiers . filter ( isNotEmptyModifier )
167176
@@ -655,19 +664,23 @@ export function convertToDirective(
655664 if (
656665 argument &&
657666 argument . type === "VIdentifier" &&
658- argument . name . startsWith ( "[" ) &&
659- invalidDynamicArgumentNextChar . test ( code [ argument . range [ 1 ] ] )
667+ argument . name . startsWith ( "[" )
660668 ) {
661- insertError (
662- document ,
663- new ParseError (
664- "Dynamic argument cannot contain spaces, '=', '/', or '>'." ,
665- undefined ,
666- argument . range [ 1 ] ,
667- argument . loc . end . line ,
668- argument . loc . end . column ,
669- ) ,
670- )
669+ const nextChar = code [ argument . range [ 1 ] ]
670+ if ( nextChar == null || invalidDynamicArgumentNextChar . test ( nextChar ) ) {
671+ const char =
672+ nextChar == null ? "EOF" : JSON . stringify ( nextChar ) . slice ( 1 , - 1 )
673+ insertError (
674+ document ,
675+ new ParseError (
676+ `Dynamic argument cannot contain the '${ char } ' character.` ,
677+ undefined ,
678+ argument . range [ 1 ] ,
679+ argument . loc . end . line ,
680+ argument . loc . end . column ,
681+ ) ,
682+ )
683+ }
671684 }
672685
673686 if ( node . value == null ) {
0 commit comments