MCPcopy Index your code
hub / github.com/angular/angular / parseOnTrigger

Function parseOnTrigger

packages/compiler/src/render3/r3_deferred_triggers.ts:128–167  ·  view source on GitHub ↗
(
  {expression, sourceSpan}: html.BlockParameter,
  bindingParser: BindingParser,
  triggers: t.DeferredBlockTriggers,
  errors: ParseError[],
  placeholder: t.DeferredBlockPlaceholder | null,
)

Source from the content-addressed store, hash-verified

126
127/** Parses an `on` trigger */
128export function parseOnTrigger(
129 {expression, sourceSpan}: html.BlockParameter,
130 bindingParser: BindingParser,
131 triggers: t.DeferredBlockTriggers,
132 errors: ParseError[],
133 placeholder: t.DeferredBlockPlaceholder | null,
134): void {
135 const onIndex = expression.indexOf('on');
136 const onSourceSpan = new ParseSourceSpan(
137 sourceSpan.start.moveBy(onIndex),
138 sourceSpan.start.moveBy(onIndex + 'on'.length),
139 );
140 const prefetchSpan = getPrefetchSpan(expression, sourceSpan);
141 const hydrateSpan = getHydrateSpan(expression, sourceSpan);
142
143 // This is here just to be safe, we shouldn't enter this function
144 // in the first place if a block doesn't have the "on" keyword.
145 if (onIndex === -1) {
146 errors.push(new ParseError(sourceSpan, `Could not find "on" keyword in expression`));
147 } else {
148 const start = getTriggerParametersStart(expression, onIndex + 1);
149 const isHydrationTrigger = expression.startsWith('hydrate');
150 const parser = new OnTriggerParser(
151 expression,
152 bindingParser,
153 start,
154 sourceSpan,
155 triggers,
156 errors,
157 isHydrationTrigger
158 ? validateHydrateReferenceBasedTrigger
159 : validatePlainReferenceBasedTrigger,
160 isHydrationTrigger,
161 prefetchSpan,
162 onSourceSpan,
163 hydrateSpan,
164 );
165 parser.parse();
166 }
167}
168
169function getPrefetchSpan(expression: string, sourceSpan: ParseSourceSpan) {
170 if (!expression.startsWith('prefetch')) {

Callers 1

parsePrimaryTriggersFunction · 0.90

Calls 7

parseMethod · 0.95
getPrefetchSpanFunction · 0.85
getHydrateSpanFunction · 0.85
indexOfMethod · 0.80
moveByMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…