/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import * as chars from '../chars'; import { Lexer, TokenType } from '../expression_parser/lexer'; import { ParseError, ParseSourceSpan } from '../parse_util'; import * as t from './r3_ast'; /** Pattern for a timing value in a trigger. */ const TIME_PATTERN = /^\d+(ms|s)?$/; /** Pattern for a separator between keywords in a trigger expression. */ const SEPARATOR_PATTERN = /^\s$/; /** Pairs of characters that form syntax that is comma-delimited. */ const COMMA_DELIMITED_SYNTAX = new Map([ [chars.$LBRACE, chars.$RBRACE], [chars.$LBRACKET, chars.$RBRACKET], [chars.$LPAREN, chars.$RPAREN], // Function calls ]); /** Possible types of `on` triggers. */ var OnTriggerType; (function (OnTriggerType) { OnTriggerType["IDLE"] = "idle"; OnTriggerType["TIMER"] = "timer"; OnTriggerType["INTERACTION"] = "interaction"; OnTriggerType["IMMEDIATE"] = "immediate"; OnTriggerType["HOVER"] = "hover"; OnTriggerType["VIEWPORT"] = "viewport"; })(OnTriggerType || (OnTriggerType = {})); /** Parses a `when` deferred trigger. */ export function parseWhenTrigger({ expression, sourceSpan }, bindingParser, errors) { const whenIndex = expression.indexOf('when'); // This is here just to be safe, we shouldn't enter this function // in the first place if a block doesn't have the "when" keyword. if (whenIndex === -1) { errors.push(new ParseError(sourceSpan, `Could not find "when" keyword in expression`)); return null; } const start = getTriggerParametersStart(expression, whenIndex + 1); const parsed = bindingParser.parseBinding(expression.slice(start), false, sourceSpan, sourceSpan.start.offset + start); return new t.BoundDeferredTrigger(parsed, sourceSpan); } /** Parses an `on` trigger */ export function parseOnTrigger({ expression, sourceSpan }, errors) { const onIndex = expression.indexOf('on'); // This is here just to be safe, we shouldn't enter this function // in the first place if a block doesn't have the "on" keyword. if (onIndex === -1) { errors.push(new ParseError(sourceSpan, `Could not find "on" keyword in expression`)); return []; } const start = getTriggerParametersStart(expression, onIndex + 1); return new OnTriggerParser(expression, start, sourceSpan, errors).parse(); } class OnTriggerParser { constructor(expression, start, span, errors) { this.expression = expression; this.start = start; this.span = span; this.errors = errors; this.index = 0; this.triggers = []; this.tokens = new Lexer().tokenize(expression.slice(start)); } parse() { while (this.tokens.length > 0 && this.index < this.tokens.length) { const token = this.token(); if (!token.isIdentifier()) { this.unexpectedToken(token); break; } // An identifier immediately followed by a comma or the end of // the expression cannot have parameters so we can exit early. if (this.isFollowedByOrLast(chars.$COMMA)) { this.consumeTrigger(token, []); this.advance(); } else if (this.isFollowedByOrLast(chars.$LPAREN)) { this.advance(); // Advance to the opening paren. const prevErrors = this.errors.length; const parameters = this.consumeParameters(); if (this.errors.length !== prevErrors) { break; } this.consumeTrigger(token, parameters); this.advance(); // Advance past the closing paren. } else if (this.index < this.tokens.length - 1) { this.unexpectedToken(this.tokens[this.index + 1]); } this.advance(); } return this.triggers; } advance() { this.index++; } isFollowedByOrLast(char) { if (this.index === this.tokens.length - 1) { return true; } return this.tokens[this.index + 1].isCharacter(char); } token() { return this.tokens[Math.min(this.index, this.tokens.length - 1)]; } consumeTrigger(identifier, parameters) { const startSpan = this.span.start.moveBy(this.start + identifier.index - this.tokens[0].index); const endSpan = startSpan.moveBy(this.token().end - identifier.index); const sourceSpan = new ParseSourceSpan(startSpan, endSpan); try { switch (identifier.toString()) { case OnTriggerType.IDLE: this.triggers.push(createIdleTrigger(parameters, sourceSpan)); break; case OnTriggerType.TIMER: this.triggers.push(createTimerTrigger(parameters, sourceSpan)); break; case OnTriggerType.INTERACTION: this.triggers.push(createInteractionTrigger(parameters, sourceSpan)); break; case OnTriggerType.IMMEDIATE: this.triggers.push(createImmediateTrigger(parameters, sourceSpan)); break; case OnTriggerType.HOVER: this.triggers.push(createHoverTrigger(parameters, sourceSpan)); break; case OnTriggerType.VIEWPORT: this.triggers.push(createViewportTrigger(parameters, sourceSpan)); break; default: throw new Error(`Unrecognized trigger type "${identifier}"`); } } catch (e) { this.error(identifier, e.message); } } consumeParameters() { const parameters = []; if (!this.token().isCharacter(chars.$LPAREN)) { this.unexpectedToken(this.token()); return parameters; } this.advance(); const commaDelimStack = []; let current = ''; while (this.index < this.tokens.length) { const token = this.token(); // Stop parsing if we've hit the end character and we're outside of a comma-delimited syntax. // Note that we don't need to account for strings here since the lexer already parsed them // into string tokens. if (token.isCharacter(chars.$RPAREN) && commaDelimStack.length === 0) { if (current.length) { parameters.push(current); } break; } // In the `on` microsyntax "top-level" commas (e.g. ones outside of an parameters) separate // the different triggers (e.g. `on idle,timer(500)`). This is problematic, because the // function-like syntax also implies that multiple parameters can be passed into the // individual trigger (e.g. `on foo(a, b)`). To avoid tripping up the parser with commas that // are part of other sorts of syntax (object literals, arrays), we treat anything inside // a comma-delimited syntax block as plain text. if (token.type === TokenType.Character && COMMA_DELIMITED_SYNTAX.has(token.numValue)) { commaDelimStack.push(COMMA_DELIMITED_SYNTAX.get(token.numValue)); } if (commaDelimStack.length > 0 && token.isCharacter(commaDelimStack[commaDelimStack.length - 1])) { commaDelimStack.pop(); } // If we hit a comma outside of a comma-delimited syntax, it means // that we're at the top level and we're starting a new parameter. if (commaDelimStack.length === 0 && token.isCharacter(chars.$COMMA) && current.length > 0) { parameters.push(current); current = ''; this.advance(); continue; } // Otherwise treat the token as a plain text character in the current parameter. current += this.tokenText(); this.advance(); } if (!this.token().isCharacter(chars.$RPAREN) || commaDelimStack.length > 0) { this.error(this.token(), 'Unexpected end of expression'); } if (this.index < this.tokens.length - 1 && !this.tokens[this.index + 1].isCharacter(chars.$COMMA)) { this.unexpectedToken(this.tokens[this.index + 1]); } return parameters; } tokenText() { // Tokens have a toString already which we could use, but for string tokens it omits the quotes. // Eventually we could expose this information on the token directly. return this.expression.slice(this.start + this.token().index, this.start + this.token().end); } error(token, message) { const newStart = this.span.start.moveBy(this.start + token.index); const newEnd = newStart.moveBy(token.end - token.index); this.errors.push(new ParseError(new ParseSourceSpan(newStart, newEnd), message)); } unexpectedToken(token) { this.error(token, `Unexpected token "${token}"`); } } function createIdleTrigger(parameters, sourceSpan) { if (parameters.length > 0) { throw new Error(`"${OnTriggerType.IDLE}" trigger cannot have parameters`); } return new t.IdleDeferredTrigger(sourceSpan); } function createTimerTrigger(parameters, sourceSpan) { if (parameters.length !== 1) { throw new Error(`"${OnTriggerType.TIMER}" trigger must have exactly one parameter`); } const delay = parseDeferredTime(parameters[0]); if (delay === null) { throw new Error(`Could not parse time value of trigger "${OnTriggerType.TIMER}"`); } return new t.TimerDeferredTrigger(delay, sourceSpan); } function createInteractionTrigger(parameters, sourceSpan) { if (parameters.length > 1) { throw new Error(`"${OnTriggerType.INTERACTION}" trigger can only have zero or one parameters`); } return new t.InteractionDeferredTrigger(parameters[0] ?? null, sourceSpan); } function createImmediateTrigger(parameters, sourceSpan) { if (parameters.length > 0) { throw new Error(`"${OnTriggerType.IMMEDIATE}" trigger cannot have parameters`); } return new t.ImmediateDeferredTrigger(sourceSpan); } function createHoverTrigger(parameters, sourceSpan) { if (parameters.length > 0) { throw new Error(`"${OnTriggerType.HOVER}" trigger cannot have parameters`); } return new t.HoverDeferredTrigger(sourceSpan); } function createViewportTrigger(parameters, sourceSpan) { // TODO: the RFC has some more potential parameters for `viewport`. if (parameters.length > 1) { throw new Error(`"${OnTriggerType.VIEWPORT}" trigger can only have zero or one parameters`); } return new t.ViewportDeferredTrigger(parameters[0] ?? null, sourceSpan); } /** Gets the index within an expression at which the trigger parameters start. */ export function getTriggerParametersStart(value, startPosition = 0) { let hasFoundSeparator = false; for (let i = startPosition; i < value.length; i++) { if (SEPARATOR_PATTERN.test(value[i])) { hasFoundSeparator = true; } else if (hasFoundSeparator) { return i; } } return -1; } /** * Parses a time expression from a deferred trigger to * milliseconds. Returns null if it cannot be parsed. */ export function parseDeferredTime(value) { const match = value.match(TIME_PATTERN); if (!match) { return null; } const [time, units] = match; return parseInt(time) * (units === 's' ? 1000 : 1); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicjNfZGVmZXJyZWRfdHJpZ2dlcnMuanMiLCJzb3VyY2VSb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