validator/engine/parse-css.js
/**
   * Parses one Qualified rule or ErrorToken appended to either rules or errors
   * respectively. Rule will include a prelude with the CSS selector (if any)
   * and a list of declarations.
   *
   * @param {!parse_css.TokenStream} tokenStream
   * @param {!Array<!parse_css.Rule>} rules output array for new rule
   * @param {!Array<!parse_css.ErrorToken>} errors output array for new error.
   */
Parses one Qualified rule or ErrorToken appended to either rules or errors
respectively. Rule will include a prelude with the CSS selector (if any)
and a list of declarations.

@param {!parse_css.TokenStream} tokenStream
@param {!Array} rules output array for new rule
@param {!Array} errors output array for new error.
Parses one Qualified rule or ErrorToken appended to either rules or errors respectively . Rule will include a prelude with the CSS selector ( if any ) and a list of declarations . @param { !parse_css . TokenStream } tokenStream @param { !Array } rules output array for new rule @param { !Array } errors output array for new error .
parseAQualifiedRule(tokenStream, rules, errors) {
    goog.asserts.assert(
        tokenStream.current().tokenType !== parse_css.TokenType.EOF_TOKEN &&
            tokenStream.current().tokenType !== parse_css.TokenType.AT_KEYWORD,
        'Internal Error: parseAQualifiedRule precondition not met');
    if (amp.validator.LIGHT && errors.length > 0) {
      return;
    }
    const rule = tokenStream.current().copyPosTo(new parse_css.QualifiedRule());
    tokenStream.reconsume();
    while (true) {
      tokenStream.consume();
      const current = tokenStream.current().tokenType;
      if (current === parse_css.TokenType.EOF_TOKEN) {
        if (amp.validator.LIGHT) {
          errors.push(parse_css.TRIVIAL_ERROR_TOKEN);
        } else {
          errors.push(rule.copyPosTo(new parse_css.ErrorToken(
              amp.validator.ValidationError.Code
                  .CSS_SYNTAX_EOF_IN_PRELUDE_OF_QUALIFIED_RULE,
              ['style'])));
        }
        return;
      }
      if (current === parse_css.TokenType.OPEN_CURLY) {
        rule.prelude.push(
            tokenStream.current().copyPosTo(new parse_css.EOFToken()));
        rule.declarations = this.parseAListOfDeclarations(
            parse_css.extractASimpleBlock(tokenStream), errors);
        rules.push(rule);
        return;
      }
      consumeAComponentValue(tokenStream, rule.prelude);
    }
  }
parseAQualifiedRule ( tokenStream , rules , errors ) { goog . asserts . assert ( tokenStream . current ( ) . tokenType !== parse_css . TokenType . EOF_TOKEN && tokenStream . current ( ) . tokenType !== parse_css . TokenType . AT_KEYWORD , 'Internal Error: parseAQualifiedRule precondition not met' ) ; if ( amp . validator . LIGHT && errors . length > 0 ) { return ; } const rule = tokenStream . current ( ) . copyPosTo ( new parse_css . QualifiedRule ( ) ) ; tokenStream . reconsume ( ) ; while ( true ) { tokenStream . consume ( ) ; const current = tokenStream . current ( ) . tokenType ; if ( current === parse_css . TokenType . EOF_TOKEN ) { if ( amp . validator . LIGHT ) { errors . push ( parse_css . TRIVIAL_ERROR_TOKEN ) ; } else { errors . push ( rule . copyPosTo ( new parse_css . ErrorToken ( amp . validator . ValidationError . Code . CSS_SYNTAX_EOF_IN_PRELUDE_OF_QUALIFIED_RULE , [ 'style' ] ) ) ) ; } return ; } if ( current === parse_css . TokenType . OPEN_CURLY ) { rule . prelude . push ( tokenStream . current ( ) . copyPosTo ( new parse_css . EOFToken ( ) ) ) ; rule . declarations = this . parseAListOfDeclarations ( parse_css . extractASimpleBlock ( tokenStream ) , errors ) ; rules . push ( rule ) ; return ; } consumeAComponentValue ( tokenStream , rule . prelude ) ; } }
Parses one Qualified rule or ErrorToken appended to either rules or errors
 respectively.
Parses one Qualified rule or ErrorToken appended to either rules or errors respectively .
// This consumes declarations (ie: "color: red;" ) inside // a qualified rule as that rule's value. // This consumes a CSS selector as the rules prelude.