import { DeploymentTemplateDoc , IScopedParseResult } from "../documents/templates/DeploymentTemplateDoc" ; import { assert } from '../fixed_assert' ; import * as TLE from "../language/expressions/TLE" ; import * as Json from "../language/json/JSON" ; import { Span } from "../language/Span" ; /**
 * Finds all spans that represent a call to "reference()" inside of a variable definition
 */ export class ReferenceInVariableDefinitionsVisitor extends Json . Visitor { private _referenceSpans : Span [ ] = [ ] ; constructor ( private _deploymentTemplate ) { super ( ) ; assert ( _deploymentTemplate ) ; } public get referenceSpans ( ) : Span [ ] { return this . _referenceSpans ; } public visitStringValue ( value ) { assert ( value , "Cannot visit a null or undefined Json.StringValue." ) ; const tleParseResult = this . _deploymentTemplate . getTLEParseResultFromJsonStringValue ( value ) ; if ( tleParseResult . parseResult . expression ) { const tleVisitor = new ReferenceInVariableDefinitionTLEVisitor ( ) ; tleParseResult . parseResult . expression . accept ( tleVisitor ) ; const jsonValueStartIndex = value . startIndex ; for ( const tleReferenceSpan of tleVisitor . referenceSpans ) { this . _referenceSpans . push ( tleReferenceSpan . translate ( jsonValueStartIndex ) ) ; } } } } class ReferenceInVariableDefinitionTLEVisitor extends TLE . TleVisitor { private _referenceSpans : Span [ ] = [ ] ; public get referenceSpans ( ) : Span [ ] { return this . _referenceSpans ; } public visitFunctionCall ( functionValue ) { if ( functionValue && functionValue . nameToken && functionValue . doesNameMatch ( "" , "reference" ) ) { this . _referenceSpans . push ( functionValue . nameToken . span ) ; } super . visitFunctionCall ( functionValue ) ; } }