@@ -41,6 +41,7 @@ const createNewExpressionParser = (name, argProcessor, defaultArr = []) => {
4141 return ( node ) => {
4242 if ( node . kind !== ts . SyntaxKind . NewExpression ) {
4343 if ( ts . isPropertyAssignment ( node . parent ) || ts . isPropertyDeclaration ( node . parent ) ) {
44+ // scriptName/attributeName will be filled by caller if caught
4445 throw new ParsingError ( node , 'Invalid Property' , `Property "${ node . name . text } " is not a ${ name } .` ) ;
4546 }
4647 return defaultArr ;
@@ -353,6 +354,7 @@ export class ScriptParser {
353354 * @property {ParsingError[] } [errors] - The array to store parsing errors
354355 * @property {boolean } [requiresAttributeTag] - Whether the attribute requires an @attribute tag
355356 * @property {number } [depth] - The current recursion depth
357+ * @property {string } [scriptName] - The current script name for context
356358 */
357359
358360 /**
@@ -369,6 +371,7 @@ export class ScriptParser {
369371 const errors = opts . errors ?? [ ] ;
370372 const requiresAttributeTag = opts . requiresAttributeTag ?? true ;
371373 const depth = opts . depth ?? 0 ;
374+ const scriptName = opts . scriptName ?? undefined ;
372375
373376 // return early if we've reached the maximum depth
374377 if ( depth > 10 ) {
@@ -385,7 +388,9 @@ export class ScriptParser {
385388 const attributeMetadata = this . attributeParser . parseAttributeComment (
386389 member ,
387390 errors ,
388- requiresAttributeTag
391+ requiresAttributeTag ,
392+ scriptName ,
393+ memberName
389394 ) ;
390395
391396 // If we found metadata, extract the type and add it to the found attributes
@@ -404,7 +409,7 @@ export class ScriptParser {
404409 } else {
405410 errorMessage = `This attribute has an invalid @type tag. An attribute should be one of the following: ${ supportedTypes } .` ;
406411 }
407- const error = new ParsingError ( member , 'Invalid Type' , errorMessage ) ;
412+ const error = new ParsingError ( member , 'Invalid Type' , errorMessage , node . name . getText ( ) , memberName , undefined ) ;
408413 errors . push ( error ) ;
409414 continue ;
410415
@@ -438,23 +443,32 @@ export class ScriptParser {
438443 error = new ParsingError (
439444 typeTag . typeExpression ,
440445 'Invalid Type' ,
441- `"${ typeTag . typeExpression . getText ( ) } " is not a valid attribute type. An attribute should be one of the following: ${ supportedTypes } `
446+ `"${ typeTag . typeExpression . getText ( ) } " is not a valid attribute type. An attribute should be one of the following: ${ supportedTypes } ` ,
447+ undefined ,
448+ node . name . getText ( ) ,
449+ memberName
442450 ) ;
443451
444452 } else if ( initializer ) {
445453 // If the attribute is initialized with an invalid type, add an error associated with the initializer
446454 error = new ParsingError (
447455 initializer ,
448456 'Invalid Type' ,
449- `"${ initializer . getText ( ) } " is not a valid attribute type. An attribute should be one of the following: ${ supportedTypes } `
457+ `"${ initializer . getText ( ) } " is not a valid attribute type. An attribute should be one of the following: ${ supportedTypes } ` ,
458+ undefined ,
459+ node . name . getText ( ) ,
460+ memberName
450461 ) ;
451462
452463 } else {
453464 // If the attribute does not have a type tag or initializer, add an error that references the member
454465 error = new ParsingError (
455466 member ,
456467 'Invalid Type' ,
457- `Attribute is an invalid type. An attribute should be one of the following: ${ supportedTypes } `
468+ `Attribute is an invalid type. An attribute should be one of the following: ${ supportedTypes } ` ,
469+ undefined ,
470+ node . name . getText ( ) ,
471+ memberName
458472 ) ;
459473 }
460474
@@ -471,13 +485,13 @@ export class ScriptParser {
471485 // If the type is an interface or an initialized object, we need to parse the attribute comments, if not, just the intitialized object
472486 let commentAttributes ;
473487 if ( typeIsInterface || isInitialized ) {
474- commentAttributes = this . extractAttributes ( typeNode , { errors, requiresAttributeTag : false , depth : depth + 1 } ) ;
488+ commentAttributes = this . extractAttributes ( typeNode , { errors, requiresAttributeTag : false , depth : depth + 1 , scriptName } ) ;
475489 }
476490
477491 // Iterate through the nested attributes and extract their metadata
478492 const nestedAttributes = members . reduce ( ( attributes , prop ) => {
479493
480- const attribute = this . attributeParser . getNodeAsAttribute ( prop , errors ) ;
494+ const attribute = this . attributeParser . getNodeAsAttribute ( prop , errors , scriptName ) ;
481495
482496 // If the attribute is a supported type, add it to the list of found attributes
483497 if ( attribute && this . allSupportedTypesSet . has ( attribute . type ) ) {
0 commit comments