refactor(core): rename `AST` to `Ast` for all CSS parser code

This commit is contained in:
Matias Niemelä 2016-06-16 11:20:27 -07:00
parent 935c39a7e2
commit 4e7bb03e81
3 changed files with 233 additions and 233 deletions

View File

@ -96,32 +96,32 @@ function characterContainsDelimiter(code: number, delimiters: number): boolean {
return bitWiseAnd([getDelimFromCharacter(code), delimiters]) > 0;
}
export abstract class CssAST {
export abstract class CssAst {
constructor(public start: number, public end: number) {}
abstract visit(visitor: CssASTVisitor, context?: any): any;
abstract visit(visitor: CssAstVisitor, context?: any): any;
}
export interface CssASTVisitor {
visitCssValue(ast: CssStyleValueAST, context?: any): any;
visitCssInlineRule(ast: CssInlineRuleAST, context?: any): any;
visitCssAtRulePredicate(ast: CssAtRulePredicateAST, context?: any): any;
visitCssKeyframeRule(ast: CssKeyframeRuleAST, context?: any): any;
visitCssKeyframeDefinition(ast: CssKeyframeDefinitionAST, context?: any): any;
visitCssMediaQueryRule(ast: CssMediaQueryRuleAST, context?: any): any;
visitCssSelectorRule(ast: CssSelectorRuleAST, context?: any): any;
visitCssSelector(ast: CssSelectorAST, context?: any): any;
visitCssSimpleSelector(ast: CssSimpleSelectorAST, context?: any): any;
visitCssPseudoSelector(ast: CssPseudoSelectorAST, context?: any): any;
visitCssDefinition(ast: CssDefinitionAST, context?: any): any;
visitCssBlock(ast: CssBlockAST, context?: any): any;
visitCssStylesBlock(ast: CssStylesBlockAST, context?: any): any;
visitCssStyleSheet(ast: CssStyleSheetAST, context?: any): any;
visitCssUnknownRule(ast: CssUnknownRuleAST, context?: any): any;
visitCssUnknownTokenList(ast: CssUnknownTokenListAST, context?: any): any;
export interface CssAstVisitor {
visitCssValue(ast: CssStyleValueAst, context?: any): any;
visitCssInlineRule(ast: CssInlineRuleAst, context?: any): any;
visitCssAtRulePredicate(ast: CssAtRulePredicateAst, context?: any): any;
visitCssKeyframeRule(ast: CssKeyframeRuleAst, context?: any): any;
visitCssKeyframeDefinition(ast: CssKeyframeDefinitionAst, context?: any): any;
visitCssMediaQueryRule(ast: CssMediaQueryRuleAst, context?: any): any;
visitCssSelectorRule(ast: CssSelectorRuleAst, context?: any): any;
visitCssSelector(ast: CssSelectorAst, context?: any): any;
visitCssSimpleSelector(ast: CssSimpleSelectorAst, context?: any): any;
visitCssPseudoSelector(ast: CssPseudoSelectorAst, context?: any): any;
visitCssDefinition(ast: CssDefinitionAst, context?: any): any;
visitCssBlock(ast: CssBlockAst, context?: any): any;
visitCssStylesBlock(ast: CssStylesBlockAst, context?: any): any;
visitCssStyleSheet(ast: CssStyleSheetAst, context?: any): any;
visitCssUnknownRule(ast: CssUnknownRuleAst, context?: any): any;
visitCssUnknownTokenList(ast: CssUnknownTokenListAst, context?: any): any;
}
export class ParsedCssResult {
constructor(public errors: CssParseError[], public ast: CssStyleSheetAST) {}
constructor(public errors: CssParseError[], public ast: CssStyleSheetAst) {}
}
export class CssParser {
@ -184,7 +184,7 @@ export class CssParser {
}
/** @internal */
_parseStyleSheet(delimiters: number): CssStyleSheetAST {
_parseStyleSheet(delimiters: number): CssStyleSheetAst {
const start = this._getScannerIndex();
var results: any[] /** TODO #9100 */ = [];
this._scanner.consumeEmptyStatements();
@ -193,11 +193,11 @@ export class CssParser {
results.push(this._parseRule(delimiters));
}
const end = this._getScannerIndex() - 1;
return new CssStyleSheetAST(start, end, results);
return new CssStyleSheetAst(start, end, results);
}
/** @internal */
_parseRule(delimiters: number): CssRuleAST {
_parseRule(delimiters: number): CssRuleAst {
if (this._scanner.peek == $AT) {
return this._parseAtRule(delimiters);
}
@ -205,7 +205,7 @@ export class CssParser {
}
/** @internal */
_parseAtRule(delimiters: number): CssRuleAST {
_parseAtRule(delimiters: number): CssRuleAst {
const start = this._getScannerIndex();
var end: number;
@ -216,7 +216,7 @@ export class CssParser {
token.type == CssTokenType.AtKeyword,
`The CSS Rule ${token.strValue} is not a valid [@] rule.`, token);
var block: CssBlockAST;
var block: CssBlockAst;
var type = this._resolveBlockType(token);
switch (type) {
case BlockType.Charset:
@ -226,13 +226,13 @@ export class CssParser {
this._scanner.setMode(CssLexerMode.BLOCK);
end = value.end;
this._scanner.consumeEmptyStatements();
return new CssInlineRuleAST(start, end, type, value);
return new CssInlineRuleAst(start, end, type, value);
case BlockType.Viewport:
case BlockType.FontFace:
block = this._parseStyleBlock(delimiters);
end = this._getScannerIndex() - 1;
return new CssBlockRuleAST(start, end, type, block);
return new CssBlockRuleAst(start, end, type, block);
case BlockType.Keyframes:
var tokens =
@ -240,7 +240,7 @@ export class CssParser {
// keyframes only have one identifier name
var name = tokens[0];
end = this._getScannerIndex() - 1;
return new CssKeyframeRuleAST(start, end, name, this._parseKeyframeBlock(delimiters));
return new CssKeyframeRuleAst(start, end, name, this._parseKeyframeBlock(delimiters));
case BlockType.MediaQuery:
this._scanner.setMode(CssLexerMode.MEDIA_QUERY);
@ -248,11 +248,11 @@ export class CssParser {
this._collectUntilDelim(bitWiseOr([delimiters, RBRACE_DELIM_FLAG, LBRACE_DELIM_FLAG]));
end = this._getScannerIndex() - 1;
var strValue = this._scanner.input.substring(start, end);
var query = new CssAtRulePredicateAST(start, end, strValue, tokens);
var query = new CssAtRulePredicateAst(start, end, strValue, tokens);
block = this._parseBlock(delimiters);
end = this._getScannerIndex() - 1;
strValue = this._scanner.input.substring(start, end);
return new CssMediaQueryRuleAST(start, end, strValue, query, block);
return new CssMediaQueryRuleAst(start, end, strValue, query, block);
case BlockType.Document:
case BlockType.Supports:
@ -262,11 +262,11 @@ export class CssParser {
this._collectUntilDelim(bitWiseOr([delimiters, RBRACE_DELIM_FLAG, LBRACE_DELIM_FLAG]));
end = this._getScannerIndex() - 1;
var strValue = this._scanner.input.substring(start, end);
var query = new CssAtRulePredicateAST(start, end, strValue, tokens);
var query = new CssAtRulePredicateAst(start, end, strValue, tokens);
block = this._parseBlock(delimiters);
end = this._getScannerIndex() - 1;
strValue = this._scanner.input.substring(start, end);
return new CssBlockDefinitionRuleAST(start, end, strValue, type, query, block);
return new CssBlockDefinitionRuleAst(start, end, strValue, type, query, block);
// if a custom @rule { ... } is used it should still tokenize the insides
default:
@ -288,28 +288,28 @@ export class CssParser {
listOfTokens.push(this._consume(CssTokenType.Character, '}'));
}
end = this._getScannerIndex() - 1;
return new CssUnknownRuleAST(start, end, tokenName, listOfTokens);
return new CssUnknownRuleAst(start, end, tokenName, listOfTokens);
}
}
/** @internal */
_parseSelectorRule(delimiters: number): CssRuleAST {
_parseSelectorRule(delimiters: number): CssRuleAst {
const start = this._getScannerIndex();
var selectors = this._parseSelectors(delimiters);
var block = this._parseStyleBlock(delimiters);
const end = this._getScannerIndex() - 1;
var token: CssRuleAST;
var token: CssRuleAst;
if (isPresent(block)) {
token = new CssSelectorRuleAST(start, end, selectors, block);
token = new CssSelectorRuleAst(start, end, selectors, block);
} else {
var name = this._scanner.input.substring(start, end);
var innerTokens: CssToken[] = [];
selectors.forEach((selector: CssSelectorAST) => {
selector.selectorParts.forEach((part: CssSimpleSelectorAST) => {
selectors.forEach((selector: CssSelectorAst) => {
selector.selectorParts.forEach((part: CssSimpleSelectorAst) => {
part.tokens.forEach((token: CssToken) => { innerTokens.push(token); });
});
});
token = new CssUnknownTokenListAST(start, end, name, innerTokens);
token = new CssUnknownTokenListAst(start, end, name, innerTokens);
}
this._scanner.setMode(CssLexerMode.BLOCK);
this._scanner.consumeEmptyStatements();
@ -317,7 +317,7 @@ export class CssParser {
}
/** @internal */
_parseSelectors(delimiters: number): CssSelectorAST[] {
_parseSelectors(delimiters: number): CssSelectorAst[] {
delimiters = bitWiseOr([delimiters, LBRACE_DELIM_FLAG, SEMICOLON_DELIM_FLAG]);
var selectors: any[] /** TODO #9100 */ = [];
@ -365,7 +365,7 @@ export class CssParser {
}
/** @internal */
_parseKeyframeBlock(delimiters: number): CssBlockAST {
_parseKeyframeBlock(delimiters: number): CssBlockAst {
const start = this._getScannerIndex();
delimiters = bitWiseOr([delimiters, RBRACE_DELIM_FLAG]);
@ -381,11 +381,11 @@ export class CssParser {
this._consume(CssTokenType.Character, '}');
const end = this._getScannerIndex() - 1;
return new CssBlockAST(start, end, definitions);
return new CssBlockAst(start, end, definitions);
}
/** @internal */
_parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAST {
_parseKeyframeDefinition(delimiters: number): CssKeyframeDefinitionAst {
const start = this._getScannerIndex();
var stepTokens: any[] /** TODO #9100 */ = [];
delimiters = bitWiseOr([delimiters, LBRACE_DELIM_FLAG]);
@ -398,7 +398,7 @@ export class CssParser {
var styles = this._parseStyleBlock(bitWiseOr([delimiters, RBRACE_DELIM_FLAG]));
this._scanner.setMode(CssLexerMode.BLOCK);
const end = this._getScannerIndex() - 1;
return new CssKeyframeDefinitionAST(start, end, stepTokens, styles);
return new CssKeyframeDefinitionAst(start, end, stepTokens, styles);
}
/** @internal */
@ -408,7 +408,7 @@ export class CssParser {
}
/** @internal */
_parsePseudoSelector(delimiters: number): CssPseudoSelectorAST {
_parsePseudoSelector(delimiters: number): CssPseudoSelectorAst {
const start = this._getScannerIndex();
delimiters = bitWiseAnd([delimiters, bitWiseNot(COMMA_DELIM_FLAG)]);
@ -424,7 +424,7 @@ export class CssParser {
tokens.push(startToken);
}
var innerSelectors: CssSelectorAST[] = [];
var innerSelectors: CssSelectorAst[] = [];
this._scanner.setMode(CssLexerMode.PSEUDO_SELECTOR);
@ -472,19 +472,19 @@ export class CssParser {
const end = this._getScannerIndex() - 1;
var strValue = this._scanner.input.substring(start, end);
return new CssPseudoSelectorAST(
return new CssPseudoSelectorAst(
start, end, strValue, pseudoSelectorName, tokens, innerSelectors);
}
/** @internal */
_parseSimpleSelector(delimiters: number): CssSimpleSelectorAST {
_parseSimpleSelector(delimiters: number): CssSimpleSelectorAst {
const start = this._getScannerIndex();
delimiters = bitWiseOr([delimiters, COMMA_DELIM_FLAG]);
this._scanner.setMode(CssLexerMode.SELECTOR);
var selectorCssTokens: CssToken[] = [];
var pseudoSelectors: CssPseudoSelectorAST[] = [];
var pseudoSelectors: CssPseudoSelectorAst[] = [];
var previousToken: CssToken;
@ -611,18 +611,18 @@ export class CssParser {
}
var strValue = this._scanner.input.substring(start, end);
return new CssSimpleSelectorAST(
return new CssSimpleSelectorAst(
start, end, selectorCssTokens, strValue, pseudoSelectors, operator);
}
/** @internal */
_parseSelector(delimiters: number): CssSelectorAST {
_parseSelector(delimiters: number): CssSelectorAst {
const start = this._getScannerIndex();
delimiters = bitWiseOr([delimiters, COMMA_DELIM_FLAG]);
this._scanner.setMode(CssLexerMode.SELECTOR);
var simpleSelectors: CssSimpleSelectorAST[] = [];
var simpleSelectors: CssSimpleSelectorAst[] = [];
var end = this._getScannerIndex() - 1;
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
simpleSelectors.push(this._parseSimpleSelector(delimiters));
@ -636,11 +636,11 @@ export class CssParser {
end = simpleSelectors[limit].end;
}
return new CssSelectorAST(start, end, simpleSelectors);
return new CssSelectorAst(start, end, simpleSelectors);
}
/** @internal */
_parseValue(delimiters: number): CssStyleValueAST {
_parseValue(delimiters: number): CssStyleValueAst {
delimiters =
bitWiseOr([delimiters, RBRACE_DELIM_FLAG, SEMICOLON_DELIM_FLAG, NEWLINE_DELIM_FLAG]);
@ -693,7 +693,7 @@ export class CssParser {
}
var strValue = this._scanner.input.substring(start, end);
return new CssStyleValueAST(start, end, tokens, strValue);
return new CssStyleValueAst(start, end, tokens, strValue);
}
/** @internal */
@ -707,7 +707,7 @@ export class CssParser {
}
/** @internal */
_parseBlock(delimiters: number): CssBlockAST {
_parseBlock(delimiters: number): CssBlockAst {
const start = this._getScannerIndex();
delimiters = bitWiseOr([delimiters, RBRACE_DELIM_FLAG]);
@ -728,11 +728,11 @@ export class CssParser {
this._scanner.consumeEmptyStatements();
const end = this._getScannerIndex() - 1;
return new CssBlockAST(start, end, results);
return new CssBlockAst(start, end, results);
}
/** @internal */
_parseStyleBlock(delimiters: number): CssStylesBlockAST {
_parseStyleBlock(delimiters: number): CssStylesBlockAst {
const start = this._getScannerIndex();
delimiters = bitWiseOr([delimiters, RBRACE_DELIM_FLAG, LBRACE_DELIM_FLAG]);
@ -744,7 +744,7 @@ export class CssParser {
return null;
}
var definitions: CssDefinitionAST[] = [];
var definitions: CssDefinitionAst[] = [];
this._scanner.consumeEmptyStatements();
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
@ -758,11 +758,11 @@ export class CssParser {
this._scanner.consumeEmptyStatements();
const end = this._getScannerIndex() - 1;
return new CssStylesBlockAST(start, end, definitions);
return new CssStylesBlockAst(start, end, definitions);
}
/** @internal */
_parseDefinition(delimiters: number): CssDefinitionAST {
_parseDefinition(delimiters: number): CssDefinitionAst {
const start = this._getScannerIndex();
this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
@ -822,7 +822,7 @@ export class CssParser {
}
const end = this._getScannerIndex() - 1;
return new CssDefinitionAST(start, end, prop, value);
return new CssDefinitionAst(start, end, prop, value);
}
/** @internal */
@ -843,174 +843,174 @@ export class CssParser {
}
}
export class CssStyleValueAST extends CssAST {
export class CssStyleValueAst extends CssAst {
constructor(start: number, end: number, public tokens: CssToken[], public strValue: string) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any { return visitor.visitCssValue(this); }
visit(visitor: CssAstVisitor, context?: any): any { return visitor.visitCssValue(this); }
}
export abstract class CssRuleAST extends CssAST {
export abstract class CssRuleAst extends CssAst {
constructor(start: number, end: number) { super(start, end); }
}
export class CssBlockRuleAST extends CssRuleAST {
export class CssBlockRuleAst extends CssRuleAst {
constructor(
start: number, end: number, public type: BlockType, public block: CssBlockAST,
start: number, end: number, public type: BlockType, public block: CssBlockAst,
public name: CssToken = null) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssBlock(this.block, context);
}
}
export class CssKeyframeRuleAST extends CssBlockRuleAST {
constructor(start: number, end: number, name: CssToken, block: CssBlockAST) {
export class CssKeyframeRuleAst extends CssBlockRuleAst {
constructor(start: number, end: number, name: CssToken, block: CssBlockAst) {
super(start, end, BlockType.Keyframes, block, name);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssKeyframeRule(this, context);
}
}
export class CssKeyframeDefinitionAST extends CssBlockRuleAST {
export class CssKeyframeDefinitionAst extends CssBlockRuleAst {
public steps: CssToken[];
constructor(start: number, end: number, _steps: CssToken[], block: CssBlockAST) {
constructor(start: number, end: number, _steps: CssToken[], block: CssBlockAst) {
super(start, end, BlockType.Keyframes, block, mergeTokens(_steps, ','));
this.steps = _steps;
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssKeyframeDefinition(this, context);
}
}
export class CssBlockDefinitionRuleAST extends CssBlockRuleAST {
export class CssBlockDefinitionRuleAst extends CssBlockRuleAst {
constructor(
start: number, end: number, public strValue: string, type: BlockType,
public query: CssAtRulePredicateAST, block: CssBlockAST) {
public query: CssAtRulePredicateAst, block: CssBlockAst) {
super(start, end, type, block);
var firstCssToken: CssToken = query.tokens[0];
this.name = new CssToken(
firstCssToken.index, firstCssToken.column, firstCssToken.line, CssTokenType.Identifier,
this.strValue);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssBlock(this.block, context);
}
}
export class CssMediaQueryRuleAST extends CssBlockDefinitionRuleAST {
export class CssMediaQueryRuleAst extends CssBlockDefinitionRuleAst {
constructor(
start: number, end: number, strValue: string, query: CssAtRulePredicateAST,
block: CssBlockAST) {
start: number, end: number, strValue: string, query: CssAtRulePredicateAst,
block: CssBlockAst) {
super(start, end, strValue, BlockType.MediaQuery, query, block);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssMediaQueryRule(this, context);
}
}
export class CssAtRulePredicateAST extends CssAST {
export class CssAtRulePredicateAst extends CssAst {
constructor(start: number, end: number, public strValue: string, public tokens: CssToken[]) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssAtRulePredicate(this, context);
}
}
export class CssInlineRuleAST extends CssRuleAST {
constructor(start: number, end: number, public type: BlockType, public value: CssStyleValueAST) {
export class CssInlineRuleAst extends CssRuleAst {
constructor(start: number, end: number, public type: BlockType, public value: CssStyleValueAst) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssInlineRule(this, context);
}
}
export class CssSelectorRuleAST extends CssBlockRuleAST {
export class CssSelectorRuleAst extends CssBlockRuleAst {
public strValue: string;
constructor(start: number, end: number, public selectors: CssSelectorAST[], block: CssBlockAST) {
constructor(start: number, end: number, public selectors: CssSelectorAst[], block: CssBlockAst) {
super(start, end, BlockType.Selector, block);
this.strValue = selectors.map(selector => selector.strValue).join(',');
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssSelectorRule(this, context);
}
}
export class CssDefinitionAST extends CssAST {
export class CssDefinitionAst extends CssAst {
constructor(
start: number, end: number, public property: CssToken, public value: CssStyleValueAST) {
start: number, end: number, public property: CssToken, public value: CssStyleValueAst) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssDefinition(this, context);
}
}
export abstract class CssSelectorPartAST extends CssAST {
export abstract class CssSelectorPartAst extends CssAst {
constructor(start: number, end: number) { super(start, end); }
}
export class CssSelectorAST extends CssSelectorPartAST {
export class CssSelectorAst extends CssSelectorPartAst {
public strValue: string;
constructor(start: number, end: number, public selectorParts: CssSimpleSelectorAST[]) {
constructor(start: number, end: number, public selectorParts: CssSimpleSelectorAst[]) {
super(start, end);
this.strValue = selectorParts.map(part => part.strValue).join('');
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssSelector(this, context);
}
}
export class CssSimpleSelectorAST extends CssSelectorPartAST {
export class CssSimpleSelectorAst extends CssSelectorPartAst {
public selectorStrValue: string;
constructor(
start: number, end: number, public tokens: CssToken[], public strValue: string,
public pseudoSelectors: CssPseudoSelectorAST[], public operator: CssToken) {
public pseudoSelectors: CssPseudoSelectorAst[], public operator: CssToken) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssSimpleSelector(this, context);
}
}
export class CssPseudoSelectorAST extends CssSelectorPartAST {
export class CssPseudoSelectorAst extends CssSelectorPartAst {
constructor(
start: number, end: number, public strValue: string, public name: string,
public tokens: CssToken[], public innerSelectors: CssSelectorAST[]) {
public tokens: CssToken[], public innerSelectors: CssSelectorAst[]) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssPseudoSelector(this, context);
}
}
export class CssBlockAST extends CssAST {
constructor(start: number, end: number, public entries: CssAST[]) { super(start, end); }
visit(visitor: CssASTVisitor, context?: any): any { return visitor.visitCssBlock(this, context); }
export class CssBlockAst extends CssAst {
constructor(start: number, end: number, public entries: CssAst[]) { super(start, end); }
visit(visitor: CssAstVisitor, context?: any): any { return visitor.visitCssBlock(this, context); }
}
/*
a style block is different from a standard block because it contains
css prop:value definitions. A regular block can contain a list of AST entries.
css prop:value definitions. A regular block can contain a list of Ast entries.
*/
export class CssStylesBlockAST extends CssBlockAST {
constructor(start: number, end: number, public definitions: CssDefinitionAST[]) {
export class CssStylesBlockAst extends CssBlockAst {
constructor(start: number, end: number, public definitions: CssDefinitionAst[]) {
super(start, end, definitions);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssStylesBlock(this, context);
}
}
export class CssStyleSheetAST extends CssAST {
constructor(start: number, end: number, public rules: CssAST[]) { super(start, end); }
visit(visitor: CssASTVisitor, context?: any): any {
export class CssStyleSheetAst extends CssAst {
constructor(start: number, end: number, public rules: CssAst[]) { super(start, end); }
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssStyleSheet(this, context);
}
}
@ -1028,20 +1028,20 @@ export class CssParseError extends ParseError {
constructor(span: ParseSourceSpan, message: string) { super(span, message); }
}
export class CssUnknownRuleAST extends CssRuleAST {
export class CssUnknownRuleAst extends CssRuleAst {
constructor(start: number, end: number, public ruleName: string, public tokens: CssToken[]) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssUnknownRule(this, context);
}
}
export class CssUnknownTokenListAST extends CssRuleAST {
export class CssUnknownTokenListAst extends CssRuleAst {
constructor(start: number, end: number, public name: string, public tokens: CssToken[]) {
super(start, end);
}
visit(visitor: CssASTVisitor, context?: any): any {
visit(visitor: CssAstVisitor, context?: any): any {
return visitor.visitCssUnknownTokenList(this, context);
}
}

View File

@ -1,5 +1,5 @@
import {CssLexer} from '@angular/compiler/src/css/lexer';
import {BlockType, CssBlockAST, CssBlockDefinitionRuleAST, CssBlockRuleAST, CssDefinitionAST, CssInlineRuleAST, CssKeyframeDefinitionAST, CssKeyframeRuleAST, CssMediaQueryRuleAST, CssParseError, CssParser, CssRuleAST, CssSelectorAST, CssSelectorRuleAST, CssStyleSheetAST, CssStyleValueAST, ParsedCssResult} from '@angular/compiler/src/css/parser';
import {BlockType, CssBlockAst, CssBlockDefinitionRuleAst, CssBlockRuleAst, CssDefinitionAst, CssInlineRuleAst, CssKeyframeDefinitionAst, CssKeyframeRuleAst, CssMediaQueryRuleAst, CssParseError, CssParser, CssRuleAst, CssSelectorAst, CssSelectorRuleAst, CssStyleSheetAst, CssStyleValueAst, ParsedCssResult} from '@angular/compiler/src/css/parser';
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
import {BaseException} from '../../src/facade/exceptions';
@ -19,7 +19,7 @@ export function main() {
return parser.parse();
}
function makeAST(css: any /** TODO #9100 */): CssStyleSheetAST {
function makeAst(css: any /** TODO #9100 */): CssStyleSheetAst {
var output = parse(css);
var errors = output.errors;
if (errors.length > 0) {
@ -28,27 +28,27 @@ export function main() {
return output.ast;
}
it('should parse CSS into a stylesheet AST', () => {
it('should parse CSS into a stylesheet Ast', () => {
var styles = `
.selector {
prop: value123;
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
expect(ast.rules.length).toEqual(1);
var rule = <CssSelectorRuleAST>ast.rules[0];
var rule = <CssSelectorRuleAst>ast.rules[0];
var selector = rule.selectors[0];
expect(selector.strValue).toEqual('.selector');
var block: CssBlockAST = rule.block;
var block: CssBlockAst = rule.block;
expect(block.entries.length).toEqual(1);
var definition = <CssDefinitionAST>block.entries[0];
var definition = <CssDefinitionAst>block.entries[0];
expect(definition.property.strValue).toEqual('prop');
var value = <CssStyleValueAST>definition.value;
var value = <CssStyleValueAst>definition.value;
expect(value.tokens[0].strValue).toEqual('value123');
});
@ -59,10 +59,10 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
expect(ast.rules.length).toEqual(1);
var rule = <CssSelectorRuleAST>ast.rules[0];
var rule = <CssSelectorRuleAst>ast.rules[0];
expect(rule.selectors.length).toBe(7);
var classRule = rule.selectors[0];
@ -86,7 +86,7 @@ export function main() {
assertTokens(mozRule.selectorParts[0].pseudoSelectors[0].tokens, [':', '-moz-any-link']);
var style1 = <CssDefinitionAST>rule.block.entries[0];
var style1 = <CssDefinitionAst>rule.block.entries[0];
expect(style1.property.strValue).toEqual('prop');
assertTokens(style1.value.tokens, ['value123']);
});
@ -106,36 +106,36 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
expect(ast.rules.length).toEqual(1);
var rule = <CssKeyframeRuleAST>ast.rules[0];
var rule = <CssKeyframeRuleAst>ast.rules[0];
expect(rule.name.strValue).toEqual('rotateMe');
var block = <CssBlockAST>rule.block;
var fromRule = <CssKeyframeDefinitionAST>block.entries[0];
var block = <CssBlockAst>rule.block;
var fromRule = <CssKeyframeDefinitionAst>block.entries[0];
expect(fromRule.name.strValue).toEqual('from');
var fromStyle = <CssDefinitionAST>(<CssBlockAST>fromRule.block).entries[0];
var fromStyle = <CssDefinitionAst>(<CssBlockAst>fromRule.block).entries[0];
expect(fromStyle.property.strValue).toEqual('transform');
assertTokens(fromStyle.value.tokens, ['rotate', '(', '-360', 'deg', ')']);
var midRule = <CssKeyframeDefinitionAST>block.entries[1];
var midRule = <CssKeyframeDefinitionAst>block.entries[1];
expect(midRule.name.strValue).toEqual('50%');
var midStyle = <CssDefinitionAST>(<CssBlockAST>midRule.block).entries[0];
var midStyle = <CssDefinitionAst>(<CssBlockAst>midRule.block).entries[0];
expect(midStyle.property.strValue).toEqual('transform');
assertTokens(midStyle.value.tokens, ['rotate', '(', '0', 'deg', ')']);
var toRule = <CssKeyframeDefinitionAST>block.entries[2];
var toRule = <CssKeyframeDefinitionAst>block.entries[2];
expect(toRule.name.strValue).toEqual('to');
var toStyle = <CssDefinitionAST>(<CssBlockAST>toRule.block).entries[0];
var toStyle = <CssDefinitionAst>(<CssBlockAst>toRule.block).entries[0];
expect(toStyle.property.strValue).toEqual('transform');
assertTokens(toStyle.value.tokens, ['rotate', '(', '360', 'deg', ')']);
});
it('should parse media queries into a stylesheet AST', () => {
it('should parse media queries into a stylesheet Ast', () => {
var styles = `
@media all and (max-width:100px) {
.selector {
@ -144,19 +144,19 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
expect(ast.rules.length).toEqual(1);
var rule = <CssMediaQueryRuleAST>ast.rules[0];
var rule = <CssMediaQueryRuleAst>ast.rules[0];
assertTokens(rule.query, ['all', 'and', '(', 'max-width', ':', '100', 'px', ')']);
var block = <CssBlockAST>rule.block;
var block = <CssBlockAst>rule.block;
expect(block.entries.length).toEqual(1);
var rule2 = <CssSelectorRuleAST>block.entries[0];
var rule2 = <CssSelectorRuleAst>block.entries[0];
expect(rule2.selectors[0].strValue).toEqual('.selector');
var block2 = <CssBlockAST>rule2.block;
var block2 = <CssBlockAst>rule2.block;
expect(block2.entries.length).toEqual(1);
});
@ -167,17 +167,17 @@ export function main() {
@namespace ng url(http://angular.io/namespace/ng);
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var importRule = <CssInlineRuleAST>ast.rules[0];
var importRule = <CssInlineRuleAst>ast.rules[0];
expect(importRule.type).toEqual(BlockType.Import);
assertTokens(importRule.value.tokens, ['url', '(', 'remote', '.', 'css', ')']);
var charsetRule = <CssInlineRuleAST>ast.rules[1];
var charsetRule = <CssInlineRuleAst>ast.rules[1];
expect(charsetRule.type).toEqual(BlockType.Charset);
assertTokens(charsetRule.value.tokens, ['UTF-8']);
var namespaceRule = <CssInlineRuleAST>ast.rules[2];
var namespaceRule = <CssInlineRuleAst>ast.rules[2];
expect(namespaceRule.type).toEqual(BlockType.Namespace);
assertTokens(
namespaceRule.value.tokens, ['ng', 'url', '(', 'http://angular.io/namespace/ng', ')']);
@ -194,19 +194,19 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
expect(ast.rules.length).toEqual(1);
var defs = (<CssSelectorRuleAST>ast.rules[0]).block.entries;
var defs = (<CssSelectorRuleAst>ast.rules[0]).block.entries;
expect(defs.length).toEqual(4);
assertTokens((<CssDefinitionAST>defs[0]).value.tokens, ['url', '(', 'matias.css', ')']);
assertTokens((<CssDefinitionAst>defs[0]).value.tokens, ['url', '(', 'matias.css', ')']);
assertTokens(
(<CssDefinitionAST>defs[1]).value.tokens,
(<CssDefinitionAst>defs[1]).value.tokens,
['cubic-bezier', '(', '0.755, 0.050, 0.855, 0.060', ')']);
assertTokens((<CssDefinitionAST>defs[2]).value.tokens, ['calc', '(', '100% - 50px', ')']);
assertTokens((<CssDefinitionAst>defs[2]).value.tokens, ['calc', '(', '100% - 50px', ')']);
assertTokens(
(<CssDefinitionAST>defs[3]).value.tokens,
(<CssDefinitionAst>defs[3]).value.tokens,
['linear-gradient', '(', '45deg, rgba(100, 0, 0, 0.5), black', ')']);
});
@ -223,13 +223,13 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var fontFaceRule = <CssBlockRuleAST>ast.rules[0];
var fontFaceRule = <CssBlockRuleAst>ast.rules[0];
expect(fontFaceRule.type).toEqual(BlockType.FontFace);
expect(fontFaceRule.block.entries.length).toEqual(3);
var viewportRule = <CssBlockRuleAST>ast.rules[1];
var viewportRule = <CssBlockRuleAst>ast.rules[1];
expect(viewportRule.type).toEqual(BlockType.Viewport);
expect(viewportRule.block.entries.length).toEqual(2);
});
@ -250,17 +250,17 @@ export function main() {
;.selector2{prop:1}}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var importRule = <CssInlineRuleAST>ast.rules[0];
var importRule = <CssInlineRuleAst>ast.rules[0];
expect(importRule.type).toEqual(BlockType.Import);
assertTokens(importRule.value.tokens, ['url', '(', 'something something', ')']);
var fontFaceRule = <CssBlockRuleAST>ast.rules[1];
var fontFaceRule = <CssBlockRuleAst>ast.rules[1];
expect(fontFaceRule.type).toEqual(BlockType.FontFace);
expect(fontFaceRule.block.entries.length).toEqual(2);
var mediaQueryRule = <CssMediaQueryRuleAST>ast.rules[2];
var mediaQueryRule = <CssMediaQueryRuleAst>ast.rules[2];
assertTokens(mediaQueryRule.query, ['all', 'and', '(', 'max-width', ':', '100', 'px', ')']);
expect(mediaQueryRule.block.entries.length).toEqual(2);
});
@ -271,7 +271,7 @@ export function main() {
`;
expect(() => {
makeAST(styles);
makeAst(styles);
}).toThrowError(/^CSS Parse Error: The CSS "at" rule "@matias" is not allowed to used here/g);
});
@ -282,12 +282,12 @@ export function main() {
.non-empty-rule { property: value; }
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var rules = ast.rules;
expect((<CssSelectorRuleAST>rules[0]).block.entries.length).toEqual(0);
expect((<CssSelectorRuleAST>rules[1]).block.entries.length).toEqual(0);
expect((<CssSelectorRuleAST>rules[2]).block.entries.length).toEqual(1);
expect((<CssSelectorRuleAst>rules[0]).block.entries.length).toEqual(0);
expect((<CssSelectorRuleAst>rules[1]).block.entries.length).toEqual(0);
expect((<CssSelectorRuleAst>rules[2]).block.entries.length).toEqual(1);
});
it('should parse the @document rule', () => {
@ -312,13 +312,13 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var rules = ast.rules;
var documentRule = <CssBlockDefinitionRuleAST>rules[0];
var documentRule = <CssBlockDefinitionRuleAst>rules[0];
expect(documentRule.type).toEqual(BlockType.Document);
var rule = <CssSelectorRuleAST>documentRule.block.entries[0];
var rule = <CssSelectorRuleAst>documentRule.block.entries[0];
expect(rule.strValue).toEqual('body');
});
@ -332,24 +332,24 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var rules = ast.rules;
var pageRule1 = <CssBlockDefinitionRuleAST>rules[0];
var pageRule1 = <CssBlockDefinitionRuleAst>rules[0];
expect(pageRule1.query.strValue).toEqual('@page one');
expect(pageRule1.query.tokens[0].strValue).toEqual('one');
expect(pageRule1.type).toEqual(BlockType.Page);
var pageRule2 = <CssBlockDefinitionRuleAST>rules[1];
var pageRule2 = <CssBlockDefinitionRuleAst>rules[1];
expect(pageRule2.query.strValue).toEqual('@page two');
expect(pageRule2.query.tokens[0].strValue).toEqual('two');
expect(pageRule2.type).toEqual(BlockType.Page);
var selectorOne = <CssSelectorRuleAST>pageRule1.block.entries[0];
var selectorOne = <CssSelectorRuleAst>pageRule1.block.entries[0];
expect(selectorOne.strValue).toEqual('.selector');
var selectorTwo = <CssSelectorRuleAST>pageRule2.block.entries[0];
var selectorTwo = <CssSelectorRuleAst>pageRule2.block.entries[0];
expect(selectorTwo.strValue).toEqual('.selector2');
});
@ -360,15 +360,15 @@ export function main() {
}
`;
var ast = makeAST(styles);
var ast = makeAst(styles);
var rules = ast.rules;
var supportsRule = <CssBlockDefinitionRuleAST>rules[0];
var supportsRule = <CssBlockDefinitionRuleAst>rules[0];
assertTokens(supportsRule.query, ['(', 'animation-name', ':', 'rotate', ')']);
expect(supportsRule.type).toEqual(BlockType.Supports);
var selectorOne = <CssSelectorRuleAST>supportsRule.block.entries[0];
var selectorOne = <CssSelectorRuleAst>supportsRule.block.entries[0];
expect(selectorOne.strValue).toEqual('a:hover');
});
@ -398,15 +398,15 @@ export function main() {
expect(ast.rules.length).toEqual(3);
var rule1 = <CssSelectorRuleAST>ast.rules[0];
var rule1 = <CssSelectorRuleAst>ast.rules[0];
expect(rule1.selectors[0].strValue).toEqual('tag&');
expect(rule1.block.entries.length).toEqual(1);
var rule2 = <CssSelectorRuleAST>ast.rules[1];
var rule2 = <CssSelectorRuleAst>ast.rules[1];
expect(rule2.selectors[0].strValue).toEqual('.%tag');
expect(rule2.block.entries.length).toEqual(1);
var rule3 = <CssSelectorRuleAST>ast.rules[2];
var rule3 = <CssSelectorRuleAst>ast.rules[2];
expect(rule3.selectors[0].strValue).toEqual('#tag$');
expect(rule3.block.entries.length).toEqual(1);
});
@ -471,7 +471,7 @@ export function main() {
expect(errors.length).toEqual(0);
var rule1 = <CssSelectorRuleAST>ast.rules[0];
var rule1 = <CssSelectorRuleAst>ast.rules[0];
expect(rule1.selectors.length).toEqual(1);
var simpleSelector = rule1.selectors[0].selectorParts[0];
@ -493,7 +493,7 @@ export function main() {
expect(errors.length).toEqual(0);
var rule1 = <CssSelectorRuleAST>ast.rules[0];
var rule1 = <CssSelectorRuleAst>ast.rules[0];
expect(rule1.selectors.length).toEqual(1);
var simpleSelector = rule1.selectors[0].selectorParts[1];
@ -546,14 +546,14 @@ export function main() {
expect(ast.rules.length).toEqual(2);
var rule1 = <CssSelectorRuleAST>ast.rules[0];
var rule1 = <CssSelectorRuleAst>ast.rules[0];
expect(rule1.block.entries.length).toEqual(2);
var style1 = <CssDefinitionAST>rule1.block.entries[0];
var style1 = <CssDefinitionAst>rule1.block.entries[0];
expect(style1.property.strValue).toEqual('background color');
assertTokens(style1.value.tokens, ['red']);
var style2 = <CssDefinitionAST>rule1.block.entries[1];
var style2 = <CssDefinitionAst>rule1.block.entries[1];
expect(style2.property.strValue).toEqual('color');
assertTokens(style2.value.tokens, ['white']);
});
@ -653,7 +653,7 @@ export function main() {
var ast = output.ast;
expect(ast.rules.length).toEqual(6);
var finalRule = <CssBlockRuleAST>ast.rules[ast.rules.length - 1];
var finalRule = <CssBlockRuleAst>ast.rules[ast.rules.length - 1];
expect(finalRule.type).toEqual(BlockType.Keyframes);
expect(finalRule.block.entries.length).toEqual(4);
});

View File

@ -1,5 +1,5 @@
import {CssLexer} from '@angular/compiler/src/css/lexer';
import {BlockType, CssAST, CssASTVisitor, CssAtRulePredicateAST, CssBlockAST, CssBlockDefinitionRuleAST, CssBlockRuleAST, CssDefinitionAST, CssInlineRuleAST, CssKeyframeDefinitionAST, CssKeyframeRuleAST, CssMediaQueryRuleAST, CssParseError, CssParser, CssPseudoSelectorAST, CssRuleAST, CssSelectorAST, CssSelectorRuleAST, CssSimpleSelectorAST, CssStyleSheetAST, CssStyleValueAST, CssStylesBlockAST, CssToken, CssUnknownRuleAST, CssUnknownTokenListAST} from '@angular/compiler/src/css/parser';
import {BlockType, CssAst, CssAstVisitor, CssAtRulePredicateAst, CssBlockAst, CssBlockDefinitionRuleAst, CssBlockRuleAst, CssDefinitionAst, CssInlineRuleAst, CssKeyframeDefinitionAst, CssKeyframeRuleAst, CssMediaQueryRuleAst, CssParseError, CssParser, CssPseudoSelectorAst, CssRuleAst, CssSelectorAst, CssSelectorRuleAst, CssSimpleSelectorAst, CssStyleSheetAst, CssStyleValueAst, CssStylesBlockAst, CssToken, CssUnknownRuleAst, CssUnknownTokenListAst} from '@angular/compiler/src/css/parser';
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
import {BaseException} from '../../src/facade/exceptions';
@ -12,98 +12,98 @@ function _assertTokens(tokens: CssToken[], valuesArr: string[]): void {
}
}
class MyVisitor implements CssASTVisitor {
class MyVisitor implements CssAstVisitor {
captures: {[key: string]: any[]} = {};
_capture(method: string, ast: CssAST, context: any) {
_capture(method: string, ast: CssAst, context: any) {
this.captures[method] = isPresent(this.captures[method]) ? this.captures[method] : [];
this.captures[method].push([ast, context]);
}
constructor(ast: CssStyleSheetAST, context: any) { ast.visit(this, context); }
constructor(ast: CssStyleSheetAst, context: any) { ast.visit(this, context); }
visitCssValue(ast: CssStyleValueAST, context: any): void {
visitCssValue(ast: CssStyleValueAst, context: any): void {
this._capture('visitCssValue', ast, context);
}
visitCssInlineRule(ast: CssInlineRuleAST, context: any): void {
this._capture('visitInlineCssRule', ast, context);
visitCssInlineRule(ast: CssInlineRuleAst, context: any): void {
this._capture('visitCssInlineRule', ast, context);
}
visitCssAtRulePredicate(ast: CssAtRulePredicateAST, context: any): void {
visitCssAtRulePredicate(ast: CssAtRulePredicateAst, context: any): void {
this._capture('visitCssAtRulePredicate', ast, context);
}
visitCssKeyframeRule(ast: CssKeyframeRuleAST, context: any): void {
visitCssKeyframeRule(ast: CssKeyframeRuleAst, context: any): void {
this._capture('visitCssKeyframeRule', ast, context);
ast.block.visit(this, context);
}
visitCssKeyframeDefinition(ast: CssKeyframeDefinitionAST, context: any): void {
visitCssKeyframeDefinition(ast: CssKeyframeDefinitionAst, context: any): void {
this._capture('visitCssKeyframeDefinition', ast, context);
ast.block.visit(this, context);
}
visitCssMediaQueryRule(ast: CssMediaQueryRuleAST, context: any): void {
visitCssMediaQueryRule(ast: CssMediaQueryRuleAst, context: any): void {
this._capture('visitCssMediaQueryRule', ast, context);
ast.query.visit(this, context);
ast.block.visit(this, context);
}
visitCssSelectorRule(ast: CssSelectorRuleAST, context: any): void {
visitCssSelectorRule(ast: CssSelectorRuleAst, context: any): void {
this._capture('visitCssSelectorRule', ast, context);
ast.selectors.forEach((selAST: CssSelectorAST) => { selAST.visit(this, context); });
ast.selectors.forEach((selAst: CssSelectorAst) => { selAst.visit(this, context); });
ast.block.visit(this, context);
}
visitCssSelector(ast: CssSelectorAST, context: any): void {
visitCssSelector(ast: CssSelectorAst, context: any): void {
this._capture('visitCssSelector', ast, context);
ast.selectorParts.forEach(
(simpleAst: CssSimpleSelectorAST) => { simpleAst.visit(this, context); });
(simpleAst: CssSimpleSelectorAst) => { simpleAst.visit(this, context); });
}
visitCssSimpleSelector(ast: CssSimpleSelectorAST, context: any): void {
visitCssSimpleSelector(ast: CssSimpleSelectorAst, context: any): void {
this._capture('visitCssSimpleSelector', ast, context);
ast.pseudoSelectors.forEach(
(pseudoAst: CssPseudoSelectorAST) => { pseudoAst.visit(this, context); });
(pseudoAst: CssPseudoSelectorAst) => { pseudoAst.visit(this, context); });
}
visitCssDefinition(ast: CssDefinitionAST, context: any): void {
visitCssDefinition(ast: CssDefinitionAst, context: any): void {
this._capture('visitCssDefinition', ast, context);
ast.value.visit(this, context);
}
visitCssBlock(ast: CssBlockAST, context: any): void {
visitCssBlock(ast: CssBlockAst, context: any): void {
this._capture('visitCssBlock', ast, context);
ast.entries.forEach((entryAST: CssAST) => { entryAST.visit(this, context); });
ast.entries.forEach((entryAst: CssAst) => { entryAst.visit(this, context); });
}
visitCssStylesBlock(ast: CssStylesBlockAST, context: any): void {
visitCssStylesBlock(ast: CssStylesBlockAst, context: any): void {
this._capture('visitCssStylesBlock', ast, context);
ast.definitions.forEach(
(definitionAst: CssDefinitionAST) => { definitionAst.visit(this, context); });
(definitionAst: CssDefinitionAst) => { definitionAst.visit(this, context); });
}
visitCssStyleSheet(ast: CssStyleSheetAST, context: any): void {
visitCssStyleSheet(ast: CssStyleSheetAst, context: any): void {
this._capture('visitCssStyleSheet', ast, context);
ast.rules.forEach((ruleAST: CssRuleAST) => { ruleAST.visit(this, context); });
ast.rules.forEach((ruleAst: CssRuleAst) => { ruleAst.visit(this, context); });
}
visitCssUnknownRule(ast: CssUnknownRuleAST, context: any): void {
this._capture('visitUnknownRule', ast, context);
visitCssUnknownRule(ast: CssUnknownRuleAst, context: any): void {
this._capture('visitCssUnknownRule', ast, context);
}
visitCssUnknownTokenList(ast: CssUnknownTokenListAST, context: any): void {
this._capture('visitUnknownTokenList', ast, context);
visitCssUnknownTokenList(ast: CssUnknownTokenListAst, context: any): void {
this._capture('visitCssUnknownTokenList', ast, context);
}
visitCssPseudoSelector(ast: CssPseudoSelectorAST, context: any): void {
visitCssPseudoSelector(ast: CssPseudoSelectorAst, context: any): void {
this._capture('visitCssPseudoSelector', ast, context);
}
}
function _getCaptureAst(capture: any[], index = 0): CssAST {
return <CssAST>capture[index][0];
function _getCaptureAst(capture: any[], index = 0): CssAst {
return <CssAst>capture[index][0];
}
export function main() {
@ -163,22 +163,22 @@ export function main() {
expect(captures.length).toEqual(3);
var rule1 = <CssSelectorRuleAST>_getCaptureAst(captures, 0);
var rule1 = <CssSelectorRuleAst>_getCaptureAst(captures, 0);
expect(rule1).toEqual(ast.rules[0]);
var firstSelector = rule1.selectors[0];
var firstSimpleSelector = firstSelector.selectorParts[0];
_assertTokens(firstSimpleSelector.tokens, ['.', 'rule1']);
var rule2 = <CssSelectorRuleAST>_getCaptureAst(captures, 1);
var rule2 = <CssSelectorRuleAst>_getCaptureAst(captures, 1);
expect(rule2).toEqual(ast.rules[1]);
var secondSelector = rule2.selectors[0];
var secondSimpleSelector = secondSelector.selectorParts[0];
_assertTokens(secondSimpleSelector.tokens, ['.', 'rule2']);
var rule3 = <CssSelectorRuleAST>_getCaptureAst(captures, 2);
expect(rule3).toEqual((<CssMediaQueryRuleAST>ast.rules[2]).block.entries[0]);
var rule3 = <CssSelectorRuleAst>_getCaptureAst(captures, 2);
expect(rule3).toEqual((<CssMediaQueryRuleAst>ast.rules[2]).block.entries[0]);
var thirdSelector = rule3.selectors[0];
var thirdSimpleSelector = thirdSelector.selectorParts[0];
@ -191,23 +191,23 @@ export function main() {
expect(captures.length).toEqual(5);
var def1 = <CssDefinitionAST>_getCaptureAst(captures, 0);
var def1 = <CssDefinitionAst>_getCaptureAst(captures, 0);
expect(def1.property.strValue).toEqual('prop1');
expect(def1.value.tokens[0].strValue).toEqual('value1');
var def2 = <CssDefinitionAST>_getCaptureAst(captures, 1);
var def2 = <CssDefinitionAst>_getCaptureAst(captures, 1);
expect(def2.property.strValue).toEqual('prop2');
expect(def2.value.tokens[0].strValue).toEqual('value2');
var def3 = <CssDefinitionAST>_getCaptureAst(captures, 2);
var def3 = <CssDefinitionAst>_getCaptureAst(captures, 2);
expect(def3.property.strValue).toEqual('prop3');
expect(def3.value.tokens[0].strValue).toEqual('value3');
var def4 = <CssDefinitionAST>_getCaptureAst(captures, 3);
var def4 = <CssDefinitionAst>_getCaptureAst(captures, 3);
expect(def4.property.strValue).toEqual('prop4');
expect(def4.value.tokens[0].strValue).toEqual('value4');
var def5 = <CssDefinitionAST>_getCaptureAst(captures, 4);
var def5 = <CssDefinitionAst>_getCaptureAst(captures, 4);
expect(def5.property.strValue).toEqual('prop5');
expect(def5.value.tokens[0].strValue).toEqual('value5');
});
@ -218,7 +218,7 @@ export function main() {
expect(captures.length).toEqual(1);
var query1 = <CssMediaQueryRuleAST>_getCaptureAst(captures, 0);
var query1 = <CssMediaQueryRuleAst>_getCaptureAst(captures, 0);
_assertTokens(query1.query.tokens, ['all', 'and', '(', 'max-width', '100', 'px', ')']);
expect(query1.block.entries.length).toEqual(1);
});
@ -229,7 +229,7 @@ export function main() {
expect(captures.length).toEqual(1);
var predicate = <CssAtRulePredicateAST>_getCaptureAst(captures, 0);
var predicate = <CssAtRulePredicateAst>_getCaptureAst(captures, 0);
expect(predicate.strValue).toEqual('@media all (max-width: 100px)');
});
@ -239,7 +239,7 @@ export function main() {
expect(captures.length).toEqual(1);
var inline1 = <CssInlineRuleAST>_getCaptureAst(captures, 0);
var inline1 = <CssInlineRuleAst>_getCaptureAst(captures, 0);
expect(inline1.type).toEqual(BlockType.Import);
_assertTokens(inline1.value.tokens, ['url', '(', 'file.css', ')']);
});
@ -250,7 +250,7 @@ export function main() {
expect(captures.length).toEqual(1);
var keyframe1 = <CssKeyframeRuleAST>_getCaptureAst(captures, 0);
var keyframe1 = <CssKeyframeRuleAst>_getCaptureAst(captures, 0);
expect(keyframe1.name.strValue).toEqual('rotate');
expect(keyframe1.block.entries.length).toEqual(2);
});
@ -261,11 +261,11 @@ export function main() {
expect(captures.length).toEqual(2);
var def1 = <CssKeyframeDefinitionAST>_getCaptureAst(captures, 0);
var def1 = <CssKeyframeDefinitionAst>_getCaptureAst(captures, 0);
_assertTokens(def1.steps, ['from']);
expect(def1.block.entries.length).toEqual(1);
var def2 = <CssKeyframeDefinitionAST>_getCaptureAst(captures, 1);
var def2 = <CssKeyframeDefinitionAst>_getCaptureAst(captures, 1);
_assertTokens(def2.steps, ['50%', '100%']);
expect(def2.block.entries.length).toEqual(1);
});
@ -282,7 +282,7 @@ export function main() {
expect(captures.length).toEqual(1);
var rule = <CssUnknownRuleAST>_getCaptureAst(captures, 0);
var rule = <CssUnknownRuleAst>_getCaptureAst(captures, 0);
expect(rule.ruleName).toEqual('@someUnknownRule');
_assertTokens(rule.tokens, ['param', '{', 'one', 'two', 'three', '}']);
@ -296,7 +296,7 @@ export function main() {
expect(captures.length).toEqual(1);
var rule = <CssUnknownTokenListAST>_getCaptureAst(captures, 0);
var rule = <CssUnknownTokenListAst>_getCaptureAst(captures, 0);
_assertTokens(rule.tokens, ['one', 'two', 'three', 'four', 'five']);
});
@ -308,7 +308,7 @@ export function main() {
expect(captures.length).toEqual(1);
var rule = <CssUnknownTokenListAST>_getCaptureAst(captures, 0);
var rule = <CssUnknownTokenListAst>_getCaptureAst(captures, 0);
_assertTokens(rule.tokens, ['six', 'seven', 'eight']);
});
});