@@ -2,7 +2,7 @@ import ts, {flattenDiagnosticMessageText} from "typescript";
22import {
33 DataType ,
44 Flow ,
5- FunctionDefinition ,
5+ FunctionDefinition , NodeFunction ,
66 NodeFunctionIdWrapper ,
77 NodeParameter ,
88 ReferenceValue
@@ -52,8 +52,8 @@ export const getFlowValidation = (
5252 if ( ! ref . nodeFunctionId ) return "undefined" ;
5353
5454 let refCode = ref . parameterIndex !== undefined
55- ? `p_${ sanitizeId ( ref . nodeFunctionId ) } _${ ref . parameterIndex } `
56- : `node_${ sanitizeId ( ref . nodeFunctionId ) } ` ;
55+ ? `/* @pos ${ nodeId } ${ index } */ p_${ sanitizeId ( ref . nodeFunctionId ) } _${ ref . parameterIndex } `
56+ : `/* @pos ${ nodeId } ${ index } */ node_${ sanitizeId ( ref . nodeFunctionId ) } ` ;
5757
5858 ref . referencePath ?. forEach ( pathObj => {
5959 refCode += `?.${ pathObj . path } ` ;
@@ -63,14 +63,14 @@ export const getFlowValidation = (
6363 }
6464
6565 if ( val . __typename === "LiteralValue" ) {
66- return JSON . stringify ( val . value ) ;
66+ return `/* @pos ${ nodeId } ${ index } */ ${ JSON . stringify ( val . value ) } ` ;
6767 }
6868
6969 if ( val . __typename === "NodeFunctionIdWrapper" ) {
7070 const wrapper = val as NodeFunctionIdWrapper ;
7171 const lambdaArgName = `p_${ sanitizeId ( node . id ! ) } _${ index } ` ;
7272 const subTreeCode = generateNodeCode ( wrapper . id ! , indent + " " ) ;
73- return `(${ lambdaArgName } ) => {\n${ subTreeCode } ${ indent } }` ;
73+ return `/* @pos ${ nodeId } ${ index } */ (${ lambdaArgName } ) => {\n${ subTreeCode } ${ indent } }` ;
7474 }
7575
7676 return "undefined" ;
@@ -121,10 +121,25 @@ export const getFlowValidation = (
121121
122122 if ( isMockError ) return null ;
123123
124+ let nodeId : NodeFunction [ 'id' ] | undefined ;
125+ let parameterIndex : number | undefined ;
126+
127+ if ( d . start !== undefined ) {
128+ const fullText = sourceFile . getFullText ( ) ;
129+ const textBefore = fullText . substring ( 0 , d . start ) ;
130+ const posMatch = textBefore . match ( / \/ \* @ p o s ( [ ^ ] + ) ( \d + ) \* \/ \s * $ / ) ;
131+ if ( posMatch ) {
132+ nodeId = posMatch [ 1 ] as NodeFunction [ 'id' ] ;
133+ parameterIndex = parseInt ( posMatch [ 2 ] , 10 ) ;
134+ }
135+ }
136+
124137 return {
125138 message,
126139 code : d . code ,
127140 severity : "error" as const ,
141+ nodeId,
142+ parameterIndex
128143 } ;
129144 } ) . filter ( ( e ) => e !== null ) ;
130145
0 commit comments