33import { Base } from "./base.js" ;
44import { Default } from "./default.js" ;
55import { ExtendedAttributes } from "./extended-attributes.js" ;
6- import { unescape , type_with_extended_attributes , autoParenter , getFirstToken } from "./helpers.js" ;
6+ import {
7+ unescape ,
8+ type_with_extended_attributes ,
9+ autoParenter ,
10+ getFirstToken ,
11+ } from "./helpers.js" ;
712import { argumentNameKeywords , Tokeniser } from "../tokeniser.js" ;
813import { validationError } from "../error.js" ;
9- import { idlTypeIncludesDictionary , dictionaryIncludesRequiredField } from "../validators/helpers.js" ;
14+ import {
15+ idlTypeIncludesDictionary ,
16+ dictionaryIncludesRequiredField ,
17+ } from "../validators/helpers.js" ;
1018
1119export class Argument extends Base {
1220 /**
@@ -16,7 +24,9 @@ export class Argument extends Base {
1624 const start_position = tokeniser . position ;
1725 /** @type {Base["tokens"] } */
1826 const tokens = { } ;
19- const ret = autoParenter ( new Argument ( { source : tokeniser . source , tokens } ) ) ;
27+ const ret = autoParenter (
28+ new Argument ( { source : tokeniser . source , tokens } )
29+ ) ;
2030 ret . extAttrs = ExtendedAttributes . parse ( tokeniser ) ;
2131 tokens . optional = tokeniser . consume ( "optional" ) ;
2232 ret . idlType = type_with_extended_attributes ( tokeniser , "argument-type" ) ;
@@ -52,23 +62,46 @@ export class Argument extends Base {
5262 */
5363 * validate ( defs ) {
5464 yield * this . idlType . validate ( defs ) ;
55- const result = idlTypeIncludesDictionary ( this . idlType , defs , { useNullableInner : true } ) ;
65+ const result = idlTypeIncludesDictionary ( this . idlType , defs , {
66+ useNullableInner : true ,
67+ } ) ;
5668 if ( result ) {
5769 if ( this . idlType . nullable ) {
5870 const message = `Dictionary arguments cannot be nullable.` ;
59- yield validationError ( this . tokens . name , this , "no-nullable-dict-arg" , message ) ;
71+ yield validationError (
72+ this . tokens . name ,
73+ this ,
74+ "no-nullable-dict-arg" ,
75+ message
76+ ) ;
6077 } else if ( ! this . optional ) {
61- if ( this . parent && ! dictionaryIncludesRequiredField ( result . dictionary , defs ) && isLastRequiredArgument ( this ) ) {
78+ if (
79+ this . parent &&
80+ ! dictionaryIncludesRequiredField ( result . dictionary , defs ) &&
81+ isLastRequiredArgument ( this )
82+ ) {
6283 const message = `Dictionary argument must be optional if it has no required fields` ;
63- yield validationError ( this . tokens . name , this , "dict-arg-optional" , message , {
64- autofix : autofixDictionaryArgumentOptionality ( this )
65- } ) ;
84+ yield validationError (
85+ this . tokens . name ,
86+ this ,
87+ "dict-arg-optional" ,
88+ message ,
89+ {
90+ autofix : autofixDictionaryArgumentOptionality ( this ) ,
91+ }
92+ ) ;
6693 }
6794 } else if ( ! this . default ) {
6895 const message = `Optional dictionary arguments must have a default value of \`{}\`.` ;
69- yield validationError ( this . tokens . name , this , "dict-arg-default" , message , {
70- autofix : autofixOptionalDictionaryDefaultValue ( this )
71- } ) ;
96+ yield validationError (
97+ this . tokens . name ,
98+ this ,
99+ "dict-arg-default" ,
100+ message ,
101+ {
102+ autofix : autofixOptionalDictionaryDefaultValue ( this ) ,
103+ }
104+ ) ;
72105 }
73106 }
74107 }
@@ -80,7 +113,7 @@ export class Argument extends Base {
80113function isLastRequiredArgument ( arg ) {
81114 const list = arg . parent . arguments || arg . parent . list ;
82115 const index = list . indexOf ( arg ) ;
83- const requiredExists = list . slice ( index + 1 ) . some ( a => ! a . optional ) ;
116+ const requiredExists = list . slice ( index + 1 ) . some ( ( a ) => ! a . optional ) ;
84117 return ! requiredExists ;
85118}
86119
@@ -90,7 +123,11 @@ function isLastRequiredArgument(arg) {
90123function autofixDictionaryArgumentOptionality ( arg ) {
91124 return ( ) => {
92125 const firstToken = getFirstToken ( arg . idlType ) ;
93- arg . tokens . optional = { type : "optional" , value : "optional" , trivia : firstToken . trivia } ;
126+ arg . tokens . optional = {
127+ type : "optional" ,
128+ value : "optional" ,
129+ trivia : firstToken . trivia ,
130+ } ;
94131 firstToken . trivia = " " ;
95132 autofixOptionalDictionaryDefaultValue ( arg ) ( ) ;
96133 } ;
0 commit comments