1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/compiler'), require('@angular/compiler-cli'), require('typescript')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/compiler', '@angular/compiler-cli', 'typescript'], factory) :
|
4 | (factory((global.ngast = global.ngast || {}),global._angular_core,global._angular_compiler,global._angular_compilerCli,global.ts));
|
5 | }(this, (function (exports,_angular_core,_angular_compiler,_angular_compilerCli,ts) { 'use strict';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var Symbol = (function () {
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function Symbol(_program, _symbol) {
|
24 | this._program = _program;
|
25 | this._symbol = _symbol;
|
26 | }
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | Symbol.prototype.getNode = function () {
|
36 | var _this = this;
|
37 | var program = this._program.getSourceFile(this._symbol.filePath);
|
38 | var findNode = function (node) {
|
39 | if (node.kind === ts.SyntaxKind.ClassDeclaration &&
|
40 | (node.name || { text: undefined }).text === _this._symbol.name) {
|
41 | return node;
|
42 | }
|
43 | else {
|
44 | return ts.forEachChild(node, findNode);
|
45 | }
|
46 | };
|
47 | return findNode(program);
|
48 | };
|
49 | Object.defineProperty(Symbol.prototype, "symbol", {
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | get: function () {
|
58 | return this._symbol;
|
59 | },
|
60 | enumerable: true,
|
61 | configurable: true
|
62 | });
|
63 | return Symbol;
|
64 | }());
|
65 |
|
66 | var ProviderSymbol = (function () {
|
67 | function ProviderSymbol(program, provider, metadataResolver) {
|
68 | this.program = program;
|
69 | this.provider = provider;
|
70 | this.metadataResolver = metadataResolver;
|
71 | }
|
72 | |
73 |
|
74 |
|
75 | ProviderSymbol.prototype.getMetadata = function () {
|
76 | return this.provider;
|
77 | };
|
78 | |
79 |
|
80 |
|
81 | ProviderSymbol.prototype.getDependencies = function () {
|
82 | var _this = this;
|
83 | return (this.provider.deps || []).map(function (d) {
|
84 | var token = d.token;
|
85 | if (d.token) {
|
86 | if (d.token.identifier) {
|
87 | token = d.token.identifier.reference;
|
88 | }
|
89 | }
|
90 | var meta = new _angular_compiler.ProviderMeta(token, d);
|
91 | return new ProviderSymbol(_this.program, _this.metadataResolver.getProviderMetadata(meta), _this.metadataResolver);
|
92 | });
|
93 | };
|
94 | return ProviderSymbol;
|
95 | }());
|
96 |
|
97 | var __extends = (undefined && undefined.__extends) || (function () {
|
98 | var extendStatics = Object.setPrototypeOf ||
|
99 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
100 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
101 | return function (d, b) {
|
102 | extendStatics(d, b);
|
103 | function __() { this.constructor = d; }
|
104 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
105 | };
|
106 | })();
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | var PipeSymbol = (function (_super) {
|
115 | __extends(PipeSymbol, _super);
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | function PipeSymbol(program, symbol, resolver, metadataResolver, projectSymbols) {
|
127 | var _this = _super.call(this, program, symbol) || this;
|
128 | _this.resolver = resolver;
|
129 | _this.metadataResolver = metadataResolver;
|
130 | _this.projectSymbols = projectSymbols;
|
131 | return _this;
|
132 | }
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | PipeSymbol.prototype.getModule = function () {
|
141 | return this.projectSymbols.getAnalyzedModules()
|
142 | .ngModuleByPipeOrDirective.get(this.symbol);
|
143 | };
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 | PipeSymbol.prototype.getMetadata = function () {
|
152 | return this.resolver.resolve(_angular_core.resolveForwardRef(this.symbol));
|
153 | };
|
154 | PipeSymbol.prototype.getDependencies = function () {
|
155 | var _this = this;
|
156 | var summary = this.metadataResolver.getInjectableSummary(this.symbol);
|
157 | if (!summary) {
|
158 | return [];
|
159 | }
|
160 | else {
|
161 | return (summary.type.diDeps || []).map(function (d) {
|
162 | var token = d.token;
|
163 | if (d.token) {
|
164 | if (d.token.identifier) {
|
165 | token = d.token.identifier.reference;
|
166 | }
|
167 | }
|
168 | var meta = new _angular_compiler.ProviderMeta(token, d);
|
169 | return new ProviderSymbol(_this._program, _this.metadataResolver.getProviderMetadata(meta), _this.metadataResolver);
|
170 | });
|
171 | }
|
172 | };
|
173 | return PipeSymbol;
|
174 | }(Symbol));
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | var $EOF = 0;
|
190 | var $TAB = 9;
|
191 | var $LF = 10;
|
192 | var $VTAB = 11;
|
193 | var $FF = 12;
|
194 | var $CR = 13;
|
195 | var $SPACE = 32;
|
196 | var $BANG = 33;
|
197 | var $DQ = 34;
|
198 | var $HASH = 35;
|
199 | var $$ = 36;
|
200 | var $PERCENT = 37;
|
201 | var $AMPERSAND = 38;
|
202 | var $SQ = 39;
|
203 | var $LPAREN = 40;
|
204 | var $RPAREN = 41;
|
205 | var $STAR = 42;
|
206 | var $PLUS = 43;
|
207 | var $COMMA = 44;
|
208 | var $MINUS = 45;
|
209 | var $PERIOD = 46;
|
210 | var $SLASH = 47;
|
211 | var $COLON = 58;
|
212 | var $SEMICOLON = 59;
|
213 |
|
214 | var $EQ = 61;
|
215 | var $GT = 62;
|
216 | var $QUESTION = 63;
|
217 | var $0 = 48;
|
218 | var $9 = 57;
|
219 | var $A = 65;
|
220 |
|
221 |
|
222 |
|
223 | var $Z = 90;
|
224 | var $LBRACKET = 91;
|
225 | var $BACKSLASH = 92;
|
226 | var $RBRACKET = 93;
|
227 | var $CARET = 94;
|
228 | var $_ = 95;
|
229 | var $a = 97;
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | var $z = 122;
|
239 | var $LBRACE = 123;
|
240 |
|
241 | var $RBRACE = 125;
|
242 | var $NBSP = 160;
|
243 | var $PIPE = 124;
|
244 | var $TILDA = 126;
|
245 | var $AT = 64;
|
246 |
|
247 | function isWhitespace(code) {
|
248 | return (code >= $TAB && code <= $SPACE) || (code == $NBSP);
|
249 | }
|
250 | function isDigit(code) {
|
251 | return $0 <= code && code <= $9;
|
252 | }
|
253 | function isAsciiLetter(code) {
|
254 | return code >= $a && code <= $z || code >= $A && code <= $Z;
|
255 | }
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | var ParseLocation = (function () {
|
265 | function ParseLocation(file, offset, line, col) {
|
266 | this.file = file;
|
267 | this.offset = offset;
|
268 | this.line = line;
|
269 | this.col = col;
|
270 | }
|
271 | ParseLocation.prototype.toString = function () {
|
272 | return this.offset != null ? this.file.url + "@" + this.line + ":" + this.col : this.file.url;
|
273 | };
|
274 | ParseLocation.prototype.moveBy = function (delta) {
|
275 | var source = this.file.content;
|
276 | var len = source.length;
|
277 | var offset = this.offset;
|
278 | var line = this.line;
|
279 | var col = this.col;
|
280 | while (offset > 0 && delta < 0) {
|
281 | offset--;
|
282 | delta++;
|
283 | var ch = source.charCodeAt(offset);
|
284 | if (ch == $LF) {
|
285 | line--;
|
286 | var priorLine = source.substr(0, offset - 1).lastIndexOf(String.fromCharCode($LF));
|
287 | col = priorLine > 0 ? offset - priorLine : offset;
|
288 | }
|
289 | else {
|
290 | col--;
|
291 | }
|
292 | }
|
293 | while (offset < len && delta > 0) {
|
294 | var ch = source.charCodeAt(offset);
|
295 | offset++;
|
296 | delta--;
|
297 | if (ch == $LF) {
|
298 | line++;
|
299 | col = 0;
|
300 | }
|
301 | else {
|
302 | col++;
|
303 | }
|
304 | }
|
305 | return new ParseLocation(this.file, offset, line, col);
|
306 | };
|
307 |
|
308 |
|
309 | ParseLocation.prototype.getContext = function (maxChars, maxLines) {
|
310 | var content = this.file.content;
|
311 | var startOffset = this.offset;
|
312 | if (startOffset != null) {
|
313 | if (startOffset > content.length - 1) {
|
314 | startOffset = content.length - 1;
|
315 | }
|
316 | var endOffset = startOffset;
|
317 | var ctxChars = 0;
|
318 | var ctxLines = 0;
|
319 | while (ctxChars < maxChars && startOffset > 0) {
|
320 | startOffset--;
|
321 | ctxChars++;
|
322 | if (content[startOffset] == '\n') {
|
323 | if (++ctxLines == maxLines) {
|
324 | break;
|
325 | }
|
326 | }
|
327 | }
|
328 | ctxChars = 0;
|
329 | ctxLines = 0;
|
330 | while (ctxChars < maxChars && endOffset < content.length - 1) {
|
331 | endOffset++;
|
332 | ctxChars++;
|
333 | if (content[endOffset] == '\n') {
|
334 | if (++ctxLines == maxLines) {
|
335 | break;
|
336 | }
|
337 | }
|
338 | }
|
339 | return {
|
340 | before: content.substring(startOffset, this.offset),
|
341 | after: content.substring(this.offset, endOffset + 1),
|
342 | };
|
343 | }
|
344 | return null;
|
345 | };
|
346 | return ParseLocation;
|
347 | }());
|
348 | var ParseSourceFile = (function () {
|
349 | function ParseSourceFile(content, url) {
|
350 | this.content = content;
|
351 | this.url = url;
|
352 | }
|
353 | return ParseSourceFile;
|
354 | }());
|
355 | var ParseSourceSpan = (function () {
|
356 | function ParseSourceSpan(start, end, details) {
|
357 | if (details === void 0) { details = null; }
|
358 | this.start = start;
|
359 | this.end = end;
|
360 | this.details = details;
|
361 | }
|
362 | ParseSourceSpan.prototype.toString = function () {
|
363 | return this.start.file.content.substring(this.start.offset, this.end.offset);
|
364 | };
|
365 | return ParseSourceSpan;
|
366 | }());
|
367 | var ParseErrorLevel;
|
368 | (function (ParseErrorLevel) {
|
369 | ParseErrorLevel[ParseErrorLevel["WARNING"] = 0] = "WARNING";
|
370 | ParseErrorLevel[ParseErrorLevel["ERROR"] = 1] = "ERROR";
|
371 | })(ParseErrorLevel || (ParseErrorLevel = {}));
|
372 | var ParseError = (function () {
|
373 | function ParseError(span, msg, level) {
|
374 | if (level === void 0) { level = ParseErrorLevel.ERROR; }
|
375 | this.span = span;
|
376 | this.msg = msg;
|
377 | this.level = level;
|
378 | }
|
379 | ParseError.prototype.toString = function () {
|
380 | var ctx = this.span.start.getContext(100, 3);
|
381 | var contextStr = ctx ? " (\"" + ctx.before + "[" + ParseErrorLevel[this.level] + " ->]" + ctx.after + "\")" : '';
|
382 | var details = this.span.details ? ", " + this.span.details : '';
|
383 | return "" + this.msg + contextStr + ": " + this.span.start + details;
|
384 | };
|
385 | return ParseError;
|
386 | }());
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 | var CssTokenType;
|
396 | (function (CssTokenType) {
|
397 | CssTokenType[CssTokenType["EOF"] = 0] = "EOF";
|
398 | CssTokenType[CssTokenType["String"] = 1] = "String";
|
399 | CssTokenType[CssTokenType["Comment"] = 2] = "Comment";
|
400 | CssTokenType[CssTokenType["Identifier"] = 3] = "Identifier";
|
401 | CssTokenType[CssTokenType["Number"] = 4] = "Number";
|
402 | CssTokenType[CssTokenType["IdentifierOrNumber"] = 5] = "IdentifierOrNumber";
|
403 | CssTokenType[CssTokenType["AtKeyword"] = 6] = "AtKeyword";
|
404 | CssTokenType[CssTokenType["Character"] = 7] = "Character";
|
405 | CssTokenType[CssTokenType["Whitespace"] = 8] = "Whitespace";
|
406 | CssTokenType[CssTokenType["Invalid"] = 9] = "Invalid";
|
407 | })(CssTokenType || (CssTokenType = {}));
|
408 | var CssLexerMode;
|
409 | (function (CssLexerMode) {
|
410 | CssLexerMode[CssLexerMode["ALL"] = 0] = "ALL";
|
411 | CssLexerMode[CssLexerMode["ALL_TRACK_WS"] = 1] = "ALL_TRACK_WS";
|
412 | CssLexerMode[CssLexerMode["SELECTOR"] = 2] = "SELECTOR";
|
413 | CssLexerMode[CssLexerMode["PSEUDO_SELECTOR"] = 3] = "PSEUDO_SELECTOR";
|
414 | CssLexerMode[CssLexerMode["PSEUDO_SELECTOR_WITH_ARGUMENTS"] = 4] = "PSEUDO_SELECTOR_WITH_ARGUMENTS";
|
415 | CssLexerMode[CssLexerMode["ATTRIBUTE_SELECTOR"] = 5] = "ATTRIBUTE_SELECTOR";
|
416 | CssLexerMode[CssLexerMode["AT_RULE_QUERY"] = 6] = "AT_RULE_QUERY";
|
417 | CssLexerMode[CssLexerMode["MEDIA_QUERY"] = 7] = "MEDIA_QUERY";
|
418 | CssLexerMode[CssLexerMode["BLOCK"] = 8] = "BLOCK";
|
419 | CssLexerMode[CssLexerMode["KEYFRAME_BLOCK"] = 9] = "KEYFRAME_BLOCK";
|
420 | CssLexerMode[CssLexerMode["STYLE_BLOCK"] = 10] = "STYLE_BLOCK";
|
421 | CssLexerMode[CssLexerMode["STYLE_VALUE"] = 11] = "STYLE_VALUE";
|
422 | CssLexerMode[CssLexerMode["STYLE_VALUE_FUNCTION"] = 12] = "STYLE_VALUE_FUNCTION";
|
423 | CssLexerMode[CssLexerMode["STYLE_CALC_FUNCTION"] = 13] = "STYLE_CALC_FUNCTION";
|
424 | })(CssLexerMode || (CssLexerMode = {}));
|
425 | var LexedCssResult = (function () {
|
426 | function LexedCssResult(error, token) {
|
427 | this.error = error;
|
428 | this.token = token;
|
429 | }
|
430 | return LexedCssResult;
|
431 | }());
|
432 | function generateErrorMessage(input, message, errorValue, index, row, column) {
|
433 | return message + " at column " + row + ":" + column + " in expression [" +
|
434 | findProblemCode(input, errorValue, index, column) + ']';
|
435 | }
|
436 | function findProblemCode(input, errorValue, index, column) {
|
437 | var endOfProblemLine = index;
|
438 | var current = charCode(input, index);
|
439 | while (current > 0 && !isNewline(current)) {
|
440 | current = charCode(input, ++endOfProblemLine);
|
441 | }
|
442 | var choppedString = input.substring(0, endOfProblemLine);
|
443 | var pointerPadding = '';
|
444 | for (var i = 0; i < column; i++) {
|
445 | pointerPadding += ' ';
|
446 | }
|
447 | var pointerString = '';
|
448 | for (var i = 0; i < errorValue.length; i++) {
|
449 | pointerString += '^';
|
450 | }
|
451 | return choppedString + '\n' + pointerPadding + pointerString + '\n';
|
452 | }
|
453 | var CssToken = (function () {
|
454 | function CssToken(index, column, line, type, strValue) {
|
455 | this.index = index;
|
456 | this.column = column;
|
457 | this.line = line;
|
458 | this.type = type;
|
459 | this.strValue = strValue;
|
460 | this.numValue = charCode(strValue, 0);
|
461 | }
|
462 | return CssToken;
|
463 | }());
|
464 | var CssLexer = (function () {
|
465 | function CssLexer() {
|
466 | }
|
467 | CssLexer.prototype.scan = function (text, trackComments) {
|
468 | if (trackComments === void 0) { trackComments = false; }
|
469 | return new CssScanner(text, trackComments);
|
470 | };
|
471 | return CssLexer;
|
472 | }());
|
473 | function cssScannerError(token, message) {
|
474 | var error = Error('CssParseError: ' + message);
|
475 | error[ERROR_RAW_MESSAGE] = message;
|
476 | error[ERROR_TOKEN] = token;
|
477 | return error;
|
478 | }
|
479 | var ERROR_TOKEN = 'ngToken';
|
480 | var ERROR_RAW_MESSAGE = 'ngRawMessage';
|
481 | function getRawMessage(error) {
|
482 | return error[ERROR_RAW_MESSAGE];
|
483 | }
|
484 |
|
485 | function _trackWhitespace(mode) {
|
486 | switch (mode) {
|
487 | case CssLexerMode.SELECTOR:
|
488 | case CssLexerMode.PSEUDO_SELECTOR:
|
489 | case CssLexerMode.ALL_TRACK_WS:
|
490 | case CssLexerMode.STYLE_VALUE:
|
491 | return true;
|
492 | default:
|
493 | return false;
|
494 | }
|
495 | }
|
496 | var CssScanner = (function () {
|
497 | function CssScanner(input, _trackComments) {
|
498 | if (_trackComments === void 0) { _trackComments = false; }
|
499 | this.input = input;
|
500 | this._trackComments = _trackComments;
|
501 | this.length = 0;
|
502 | this.index = -1;
|
503 | this.column = -1;
|
504 | this.line = 0;
|
505 |
|
506 | this._currentMode = CssLexerMode.BLOCK;
|
507 |
|
508 | this._currentError = null;
|
509 | this.length = this.input.length;
|
510 | this.peekPeek = this.peekAt(0);
|
511 | this.advance();
|
512 | }
|
513 | CssScanner.prototype.getMode = function () { return this._currentMode; };
|
514 | CssScanner.prototype.setMode = function (mode) {
|
515 | if (this._currentMode != mode) {
|
516 | if (_trackWhitespace(this._currentMode) && !_trackWhitespace(mode)) {
|
517 | this.consumeWhitespace();
|
518 | }
|
519 | this._currentMode = mode;
|
520 | }
|
521 | };
|
522 | CssScanner.prototype.advance = function () {
|
523 | if (isNewline(this.peek)) {
|
524 | this.column = 0;
|
525 | this.line++;
|
526 | }
|
527 | else {
|
528 | this.column++;
|
529 | }
|
530 | this.index++;
|
531 | this.peek = this.peekPeek;
|
532 | this.peekPeek = this.peekAt(this.index + 1);
|
533 | };
|
534 | CssScanner.prototype.peekAt = function (index) {
|
535 | return index >= this.length ? $EOF : this.input.charCodeAt(index);
|
536 | };
|
537 | CssScanner.prototype.consumeEmptyStatements = function () {
|
538 | this.consumeWhitespace();
|
539 | while (this.peek == $SEMICOLON) {
|
540 | this.advance();
|
541 | this.consumeWhitespace();
|
542 | }
|
543 | };
|
544 | CssScanner.prototype.consumeWhitespace = function () {
|
545 | while (isWhitespace(this.peek) || isNewline(this.peek)) {
|
546 | this.advance();
|
547 | if (!this._trackComments && isCommentStart(this.peek, this.peekPeek)) {
|
548 | this.advance();
|
549 | this.advance();
|
550 | while (!isCommentEnd(this.peek, this.peekPeek)) {
|
551 | if (this.peek == $EOF) {
|
552 | this.error('Unterminated comment');
|
553 | }
|
554 | this.advance();
|
555 | }
|
556 | this.advance();
|
557 | this.advance();
|
558 | }
|
559 | }
|
560 | };
|
561 | CssScanner.prototype.consume = function (type, value) {
|
562 | if (value === void 0) { value = null; }
|
563 | var mode = this._currentMode;
|
564 | this.setMode(_trackWhitespace(mode) ? CssLexerMode.ALL_TRACK_WS : CssLexerMode.ALL);
|
565 | var previousIndex = this.index;
|
566 | var previousLine = this.line;
|
567 | var previousColumn = this.column;
|
568 | var next = undefined;
|
569 | var output = this.scan();
|
570 | if (output != null) {
|
571 |
|
572 | if (output.error != null) {
|
573 | this.setMode(mode);
|
574 | return output;
|
575 | }
|
576 | next = output.token;
|
577 | }
|
578 | if (next == null) {
|
579 | next = new CssToken(this.index, this.column, this.line, CssTokenType.EOF, 'end of file');
|
580 | }
|
581 | var isMatchingType = false;
|
582 | if (type == CssTokenType.IdentifierOrNumber) {
|
583 |
|
584 | isMatchingType = next.type == CssTokenType.Number || next.type == CssTokenType.Identifier;
|
585 | }
|
586 | else {
|
587 | isMatchingType = next.type == type;
|
588 | }
|
589 |
|
590 |
|
591 | this.setMode(mode);
|
592 | var error = null;
|
593 | if (!isMatchingType || (value != null && value != next.strValue)) {
|
594 | var errorMessage = CssTokenType[next.type] + ' does not match expected ' + CssTokenType[type] + ' value';
|
595 | if (value != null) {
|
596 | errorMessage += ' ("' + next.strValue + '" should match "' + value + '")';
|
597 | }
|
598 | error = cssScannerError(next, generateErrorMessage(this.input, errorMessage, next.strValue, previousIndex, previousLine, previousColumn));
|
599 | }
|
600 | return new LexedCssResult(error, next);
|
601 | };
|
602 | CssScanner.prototype.scan = function () {
|
603 | var trackWS = _trackWhitespace(this._currentMode);
|
604 | if (this.index == 0 && !trackWS) {
|
605 | this.consumeWhitespace();
|
606 | }
|
607 | var token = this._scan();
|
608 | if (token == null)
|
609 | return null;
|
610 | var error = this._currentError;
|
611 | this._currentError = null;
|
612 | if (!trackWS) {
|
613 | this.consumeWhitespace();
|
614 | }
|
615 | return new LexedCssResult(error, token);
|
616 | };
|
617 |
|
618 | CssScanner.prototype._scan = function () {
|
619 | var peek = this.peek;
|
620 | var peekPeek = this.peekPeek;
|
621 | if (peek == $EOF)
|
622 | return null;
|
623 | if (isCommentStart(peek, peekPeek)) {
|
624 |
|
625 |
|
626 | var commentToken = this.scanComment();
|
627 | if (this._trackComments) {
|
628 | return commentToken;
|
629 | }
|
630 | }
|
631 | if (_trackWhitespace(this._currentMode) && (isWhitespace(peek) || isNewline(peek))) {
|
632 | return this.scanWhitespace();
|
633 | }
|
634 | peek = this.peek;
|
635 | peekPeek = this.peekPeek;
|
636 | if (peek == $EOF)
|
637 | return null;
|
638 | if (isStringStart(peek, peekPeek)) {
|
639 | return this.scanString();
|
640 | }
|
641 |
|
642 | if (this._currentMode == CssLexerMode.STYLE_VALUE_FUNCTION) {
|
643 | return this.scanCssValueFunction();
|
644 | }
|
645 | var isModifier = peek == $PLUS || peek == $MINUS;
|
646 | var digitA = isModifier ? false : isDigit(peek);
|
647 | var digitB = isDigit(peekPeek);
|
648 | if (digitA || (isModifier && (peekPeek == $PERIOD || digitB)) ||
|
649 | (peek == $PERIOD && digitB)) {
|
650 | return this.scanNumber();
|
651 | }
|
652 | if (peek == $AT) {
|
653 | return this.scanAtExpression();
|
654 | }
|
655 | if (isIdentifierStart(peek, peekPeek)) {
|
656 | return this.scanIdentifier();
|
657 | }
|
658 | if (isValidCssCharacter(peek, this._currentMode)) {
|
659 | return this.scanCharacter();
|
660 | }
|
661 | return this.error("Unexpected character [" + String.fromCharCode(peek) + "]");
|
662 | };
|
663 | CssScanner.prototype.scanComment = function () {
|
664 | if (this.assertCondition(isCommentStart(this.peek, this.peekPeek), 'Expected comment start value')) {
|
665 | return null;
|
666 | }
|
667 | var start = this.index;
|
668 | var startingColumn = this.column;
|
669 | var startingLine = this.line;
|
670 | this.advance();
|
671 | this.advance();
|
672 | while (!isCommentEnd(this.peek, this.peekPeek)) {
|
673 | if (this.peek == $EOF) {
|
674 | this.error('Unterminated comment');
|
675 | }
|
676 | this.advance();
|
677 | }
|
678 | this.advance();
|
679 | this.advance();
|
680 | var str = this.input.substring(start, this.index);
|
681 | return new CssToken(start, startingColumn, startingLine, CssTokenType.Comment, str);
|
682 | };
|
683 | CssScanner.prototype.scanWhitespace = function () {
|
684 | var start = this.index;
|
685 | var startingColumn = this.column;
|
686 | var startingLine = this.line;
|
687 | while (isWhitespace(this.peek) && this.peek != $EOF) {
|
688 | this.advance();
|
689 | }
|
690 | var str = this.input.substring(start, this.index);
|
691 | return new CssToken(start, startingColumn, startingLine, CssTokenType.Whitespace, str);
|
692 | };
|
693 | CssScanner.prototype.scanString = function () {
|
694 | if (this.assertCondition(isStringStart(this.peek, this.peekPeek), 'Unexpected non-string starting value')) {
|
695 | return null;
|
696 | }
|
697 | var target = this.peek;
|
698 | var start = this.index;
|
699 | var startingColumn = this.column;
|
700 | var startingLine = this.line;
|
701 | var previous = target;
|
702 | this.advance();
|
703 | while (!isCharMatch(target, previous, this.peek)) {
|
704 | if (this.peek == $EOF || isNewline(this.peek)) {
|
705 | this.error('Unterminated quote');
|
706 | }
|
707 | previous = this.peek;
|
708 | this.advance();
|
709 | }
|
710 | if (this.assertCondition(this.peek == target, 'Unterminated quote')) {
|
711 | return null;
|
712 | }
|
713 | this.advance();
|
714 | var str = this.input.substring(start, this.index);
|
715 | return new CssToken(start, startingColumn, startingLine, CssTokenType.String, str);
|
716 | };
|
717 | CssScanner.prototype.scanNumber = function () {
|
718 | var start = this.index;
|
719 | var startingColumn = this.column;
|
720 | if (this.peek == $PLUS || this.peek == $MINUS) {
|
721 | this.advance();
|
722 | }
|
723 | var periodUsed = false;
|
724 | while (isDigit(this.peek) || this.peek == $PERIOD) {
|
725 | if (this.peek == $PERIOD) {
|
726 | if (periodUsed) {
|
727 | this.error('Unexpected use of a second period value');
|
728 | }
|
729 | periodUsed = true;
|
730 | }
|
731 | this.advance();
|
732 | }
|
733 | var strValue = this.input.substring(start, this.index);
|
734 | return new CssToken(start, startingColumn, this.line, CssTokenType.Number, strValue);
|
735 | };
|
736 | CssScanner.prototype.scanIdentifier = function () {
|
737 | if (this.assertCondition(isIdentifierStart(this.peek, this.peekPeek), 'Expected identifier starting value')) {
|
738 | return null;
|
739 | }
|
740 | var start = this.index;
|
741 | var startingColumn = this.column;
|
742 | while (isIdentifierPart(this.peek)) {
|
743 | this.advance();
|
744 | }
|
745 | var strValue = this.input.substring(start, this.index);
|
746 | return new CssToken(start, startingColumn, this.line, CssTokenType.Identifier, strValue);
|
747 | };
|
748 | CssScanner.prototype.scanCssValueFunction = function () {
|
749 | var start = this.index;
|
750 | var startingColumn = this.column;
|
751 | var parenBalance = 1;
|
752 | while (this.peek != $EOF && parenBalance > 0) {
|
753 | this.advance();
|
754 | if (this.peek == $LPAREN) {
|
755 | parenBalance++;
|
756 | }
|
757 | else if (this.peek == $RPAREN) {
|
758 | parenBalance--;
|
759 | }
|
760 | }
|
761 | var strValue = this.input.substring(start, this.index);
|
762 | return new CssToken(start, startingColumn, this.line, CssTokenType.Identifier, strValue);
|
763 | };
|
764 | CssScanner.prototype.scanCharacter = function () {
|
765 | var start = this.index;
|
766 | var startingColumn = this.column;
|
767 | if (this.assertCondition(isValidCssCharacter(this.peek, this._currentMode), charStr(this.peek) + ' is not a valid CSS character')) {
|
768 | return null;
|
769 | }
|
770 | var c = this.input.substring(start, start + 1);
|
771 | this.advance();
|
772 | return new CssToken(start, startingColumn, this.line, CssTokenType.Character, c);
|
773 | };
|
774 | CssScanner.prototype.scanAtExpression = function () {
|
775 | if (this.assertCondition(this.peek == $AT, 'Expected @ value')) {
|
776 | return null;
|
777 | }
|
778 | var start = this.index;
|
779 | var startingColumn = this.column;
|
780 | this.advance();
|
781 | if (isIdentifierStart(this.peek, this.peekPeek)) {
|
782 | var ident = this.scanIdentifier();
|
783 | var strValue = '@' + ident.strValue;
|
784 | return new CssToken(start, startingColumn, this.line, CssTokenType.AtKeyword, strValue);
|
785 | }
|
786 | else {
|
787 | return this.scanCharacter();
|
788 | }
|
789 | };
|
790 | CssScanner.prototype.assertCondition = function (status, errorMessage) {
|
791 | if (!status) {
|
792 | this.error(errorMessage);
|
793 | return true;
|
794 | }
|
795 | return false;
|
796 | };
|
797 | CssScanner.prototype.error = function (message, errorTokenValue, doNotAdvance) {
|
798 | if (errorTokenValue === void 0) { errorTokenValue = null; }
|
799 | if (doNotAdvance === void 0) { doNotAdvance = false; }
|
800 | var index = this.index;
|
801 | var column = this.column;
|
802 | var line = this.line;
|
803 | errorTokenValue = errorTokenValue || String.fromCharCode(this.peek);
|
804 | var invalidToken = new CssToken(index, column, line, CssTokenType.Invalid, errorTokenValue);
|
805 | var errorMessage = generateErrorMessage(this.input, message, errorTokenValue, index, line, column);
|
806 | if (!doNotAdvance) {
|
807 | this.advance();
|
808 | }
|
809 | this._currentError = cssScannerError(invalidToken, errorMessage);
|
810 | return invalidToken;
|
811 | };
|
812 | return CssScanner;
|
813 | }());
|
814 | function isCharMatch(target, previous, code) {
|
815 | return code == target && previous != $BACKSLASH;
|
816 | }
|
817 | function isCommentStart(code, next) {
|
818 | return code == $SLASH && next == $STAR;
|
819 | }
|
820 | function isCommentEnd(code, next) {
|
821 | return code == $STAR && next == $SLASH;
|
822 | }
|
823 | function isStringStart(code, next) {
|
824 | var target = code;
|
825 | if (target == $BACKSLASH) {
|
826 | target = next;
|
827 | }
|
828 | return target == $DQ || target == $SQ;
|
829 | }
|
830 | function isIdentifierStart(code, next) {
|
831 | var target = code;
|
832 | if (target == $MINUS) {
|
833 | target = next;
|
834 | }
|
835 | return isAsciiLetter(target) || target == $BACKSLASH || target == $MINUS ||
|
836 | target == $_;
|
837 | }
|
838 | function isIdentifierPart(target) {
|
839 | return isAsciiLetter(target) || target == $BACKSLASH || target == $MINUS ||
|
840 | target == $_ || isDigit(target);
|
841 | }
|
842 | function isValidPseudoSelectorCharacter(code) {
|
843 | switch (code) {
|
844 | case $LPAREN:
|
845 | case $RPAREN:
|
846 | return true;
|
847 | default:
|
848 | return false;
|
849 | }
|
850 | }
|
851 | function isValidKeyframeBlockCharacter(code) {
|
852 | return code == $PERCENT;
|
853 | }
|
854 | function isValidAttributeSelectorCharacter(code) {
|
855 |
|
856 | switch (code) {
|
857 | case $$:
|
858 | case $PIPE:
|
859 | case $CARET:
|
860 | case $TILDA:
|
861 | case $STAR:
|
862 | case $EQ:
|
863 | return true;
|
864 | default:
|
865 | return false;
|
866 | }
|
867 | }
|
868 | function isValidSelectorCharacter(code) {
|
869 |
|
870 |
|
871 |
|
872 |
|
873 | switch (code) {
|
874 | case $HASH:
|
875 | case $PERIOD:
|
876 | case $TILDA:
|
877 | case $STAR:
|
878 | case $PLUS:
|
879 | case $GT:
|
880 | case $COLON:
|
881 | case $PIPE:
|
882 | case $COMMA:
|
883 | case $LBRACKET:
|
884 | case $RBRACKET:
|
885 | return true;
|
886 | default:
|
887 | return false;
|
888 | }
|
889 | }
|
890 | function isValidStyleBlockCharacter(code) {
|
891 |
|
892 |
|
893 | switch (code) {
|
894 | case $HASH:
|
895 | case $SEMICOLON:
|
896 | case $COLON:
|
897 | case $PERCENT:
|
898 | case $SLASH:
|
899 | case $BACKSLASH:
|
900 | case $BANG:
|
901 | case $PERIOD:
|
902 | case $LPAREN:
|
903 | case $RPAREN:
|
904 | return true;
|
905 | default:
|
906 | return false;
|
907 | }
|
908 | }
|
909 | function isValidMediaQueryRuleCharacter(code) {
|
910 |
|
911 | switch (code) {
|
912 | case $LPAREN:
|
913 | case $RPAREN:
|
914 | case $COLON:
|
915 | case $PERCENT:
|
916 | case $PERIOD:
|
917 | return true;
|
918 | default:
|
919 | return false;
|
920 | }
|
921 | }
|
922 | function isValidAtRuleCharacter(code) {
|
923 |
|
924 | switch (code) {
|
925 | case $LPAREN:
|
926 | case $RPAREN:
|
927 | case $COLON:
|
928 | case $PERCENT:
|
929 | case $PERIOD:
|
930 | case $SLASH:
|
931 | case $BACKSLASH:
|
932 | case $HASH:
|
933 | case $EQ:
|
934 | case $QUESTION:
|
935 | case $AMPERSAND:
|
936 | case $STAR:
|
937 | case $COMMA:
|
938 | case $MINUS:
|
939 | case $PLUS:
|
940 | return true;
|
941 | default:
|
942 | return false;
|
943 | }
|
944 | }
|
945 | function isValidStyleFunctionCharacter(code) {
|
946 | switch (code) {
|
947 | case $PERIOD:
|
948 | case $MINUS:
|
949 | case $PLUS:
|
950 | case $STAR:
|
951 | case $SLASH:
|
952 | case $LPAREN:
|
953 | case $RPAREN:
|
954 | case $COMMA:
|
955 | return true;
|
956 | default:
|
957 | return false;
|
958 | }
|
959 | }
|
960 | function isValidBlockCharacter(code) {
|
961 |
|
962 |
|
963 | return code == $AT;
|
964 | }
|
965 | function isValidCssCharacter(code, mode) {
|
966 | switch (mode) {
|
967 | case CssLexerMode.ALL:
|
968 | case CssLexerMode.ALL_TRACK_WS:
|
969 | return true;
|
970 | case CssLexerMode.SELECTOR:
|
971 | return isValidSelectorCharacter(code);
|
972 | case CssLexerMode.PSEUDO_SELECTOR_WITH_ARGUMENTS:
|
973 | return isValidPseudoSelectorCharacter(code);
|
974 | case CssLexerMode.ATTRIBUTE_SELECTOR:
|
975 | return isValidAttributeSelectorCharacter(code);
|
976 | case CssLexerMode.MEDIA_QUERY:
|
977 | return isValidMediaQueryRuleCharacter(code);
|
978 | case CssLexerMode.AT_RULE_QUERY:
|
979 | return isValidAtRuleCharacter(code);
|
980 | case CssLexerMode.KEYFRAME_BLOCK:
|
981 | return isValidKeyframeBlockCharacter(code);
|
982 | case CssLexerMode.STYLE_BLOCK:
|
983 | case CssLexerMode.STYLE_VALUE:
|
984 | return isValidStyleBlockCharacter(code);
|
985 | case CssLexerMode.STYLE_CALC_FUNCTION:
|
986 | return isValidStyleFunctionCharacter(code);
|
987 | case CssLexerMode.BLOCK:
|
988 | return isValidBlockCharacter(code);
|
989 | default:
|
990 | return false;
|
991 | }
|
992 | }
|
993 | function charCode(input, index) {
|
994 | return index >= input.length ? $EOF : input.charCodeAt(index);
|
995 | }
|
996 | function charStr(code) {
|
997 | return String.fromCharCode(code);
|
998 | }
|
999 | function isNewline(code) {
|
1000 | switch (code) {
|
1001 | case $FF:
|
1002 | case $CR:
|
1003 | case $LF:
|
1004 | case $VTAB:
|
1005 | return true;
|
1006 | default:
|
1007 | return false;
|
1008 | }
|
1009 | }
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | var __extends$3 = (undefined && undefined.__extends) || (function () {
|
1019 | var extendStatics = Object.setPrototypeOf ||
|
1020 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
1021 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
1022 | return function (d, b) {
|
1023 | extendStatics(d, b);
|
1024 | function __() { this.constructor = d; }
|
1025 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
1026 | };
|
1027 | })();
|
1028 | var BlockType;
|
1029 | (function (BlockType) {
|
1030 | BlockType[BlockType["Import"] = 0] = "Import";
|
1031 | BlockType[BlockType["Charset"] = 1] = "Charset";
|
1032 | BlockType[BlockType["Namespace"] = 2] = "Namespace";
|
1033 | BlockType[BlockType["Supports"] = 3] = "Supports";
|
1034 | BlockType[BlockType["Keyframes"] = 4] = "Keyframes";
|
1035 | BlockType[BlockType["MediaQuery"] = 5] = "MediaQuery";
|
1036 | BlockType[BlockType["Selector"] = 6] = "Selector";
|
1037 | BlockType[BlockType["FontFace"] = 7] = "FontFace";
|
1038 | BlockType[BlockType["Page"] = 8] = "Page";
|
1039 | BlockType[BlockType["Document"] = 9] = "Document";
|
1040 | BlockType[BlockType["Viewport"] = 10] = "Viewport";
|
1041 | BlockType[BlockType["Unsupported"] = 11] = "Unsupported";
|
1042 | })(BlockType || (BlockType = {}));
|
1043 | var CssAst = (function () {
|
1044 | function CssAst(location) {
|
1045 | this.location = location;
|
1046 | }
|
1047 | Object.defineProperty(CssAst.prototype, "start", {
|
1048 | get: function () { return this.location.start; },
|
1049 | enumerable: true,
|
1050 | configurable: true
|
1051 | });
|
1052 | Object.defineProperty(CssAst.prototype, "end", {
|
1053 | get: function () { return this.location.end; },
|
1054 | enumerable: true,
|
1055 | configurable: true
|
1056 | });
|
1057 | return CssAst;
|
1058 | }());
|
1059 | var CssStyleValueAst = (function (_super) {
|
1060 | __extends$3(CssStyleValueAst, _super);
|
1061 | function CssStyleValueAst(location, tokens, strValue) {
|
1062 | var _this = _super.call(this, location) || this;
|
1063 | _this.tokens = tokens;
|
1064 | _this.strValue = strValue;
|
1065 | return _this;
|
1066 | }
|
1067 | CssStyleValueAst.prototype.visit = function (visitor, context) { return visitor.visitCssValue(this); };
|
1068 | return CssStyleValueAst;
|
1069 | }(CssAst));
|
1070 | var CssRuleAst = (function (_super) {
|
1071 | __extends$3(CssRuleAst, _super);
|
1072 | function CssRuleAst(location) {
|
1073 | return _super.call(this, location) || this;
|
1074 | }
|
1075 | return CssRuleAst;
|
1076 | }(CssAst));
|
1077 | var CssBlockRuleAst = (function (_super) {
|
1078 | __extends$3(CssBlockRuleAst, _super);
|
1079 | function CssBlockRuleAst(location, type, block, name) {
|
1080 | if (name === void 0) { name = null; }
|
1081 | var _this = _super.call(this, location) || this;
|
1082 | _this.location = location;
|
1083 | _this.type = type;
|
1084 | _this.block = block;
|
1085 | _this.name = name;
|
1086 | return _this;
|
1087 | }
|
1088 | CssBlockRuleAst.prototype.visit = function (visitor, context) {
|
1089 | return visitor.visitCssBlock(this.block, context);
|
1090 | };
|
1091 | return CssBlockRuleAst;
|
1092 | }(CssRuleAst));
|
1093 | var CssKeyframeRuleAst = (function (_super) {
|
1094 | __extends$3(CssKeyframeRuleAst, _super);
|
1095 | function CssKeyframeRuleAst(location, name, block) {
|
1096 | return _super.call(this, location, BlockType.Keyframes, block, name) || this;
|
1097 | }
|
1098 | CssKeyframeRuleAst.prototype.visit = function (visitor, context) {
|
1099 | return visitor.visitCssKeyframeRule(this, context);
|
1100 | };
|
1101 | return CssKeyframeRuleAst;
|
1102 | }(CssBlockRuleAst));
|
1103 | var CssKeyframeDefinitionAst = (function (_super) {
|
1104 | __extends$3(CssKeyframeDefinitionAst, _super);
|
1105 | function CssKeyframeDefinitionAst(location, steps, block) {
|
1106 | var _this = _super.call(this, location, BlockType.Keyframes, block, mergeTokens(steps, ',')) || this;
|
1107 | _this.steps = steps;
|
1108 | return _this;
|
1109 | }
|
1110 | CssKeyframeDefinitionAst.prototype.visit = function (visitor, context) {
|
1111 | return visitor.visitCssKeyframeDefinition(this, context);
|
1112 | };
|
1113 | return CssKeyframeDefinitionAst;
|
1114 | }(CssBlockRuleAst));
|
1115 | var CssBlockDefinitionRuleAst = (function (_super) {
|
1116 | __extends$3(CssBlockDefinitionRuleAst, _super);
|
1117 | function CssBlockDefinitionRuleAst(location, strValue, type, query, block) {
|
1118 | var _this = _super.call(this, location, type, block) || this;
|
1119 | _this.strValue = strValue;
|
1120 | _this.query = query;
|
1121 | var firstCssToken = query.tokens[0];
|
1122 | _this.name = new CssToken(firstCssToken.index, firstCssToken.column, firstCssToken.line, CssTokenType.Identifier, _this.strValue);
|
1123 | return _this;
|
1124 | }
|
1125 | CssBlockDefinitionRuleAst.prototype.visit = function (visitor, context) {
|
1126 | return visitor.visitCssBlock(this.block, context);
|
1127 | };
|
1128 | return CssBlockDefinitionRuleAst;
|
1129 | }(CssBlockRuleAst));
|
1130 | var CssMediaQueryRuleAst = (function (_super) {
|
1131 | __extends$3(CssMediaQueryRuleAst, _super);
|
1132 | function CssMediaQueryRuleAst(location, strValue, query, block) {
|
1133 | return _super.call(this, location, strValue, BlockType.MediaQuery, query, block) || this;
|
1134 | }
|
1135 | CssMediaQueryRuleAst.prototype.visit = function (visitor, context) {
|
1136 | return visitor.visitCssMediaQueryRule(this, context);
|
1137 | };
|
1138 | return CssMediaQueryRuleAst;
|
1139 | }(CssBlockDefinitionRuleAst));
|
1140 | var CssAtRulePredicateAst = (function (_super) {
|
1141 | __extends$3(CssAtRulePredicateAst, _super);
|
1142 | function CssAtRulePredicateAst(location, strValue, tokens) {
|
1143 | var _this = _super.call(this, location) || this;
|
1144 | _this.strValue = strValue;
|
1145 | _this.tokens = tokens;
|
1146 | return _this;
|
1147 | }
|
1148 | CssAtRulePredicateAst.prototype.visit = function (visitor, context) {
|
1149 | return visitor.visitCssAtRulePredicate(this, context);
|
1150 | };
|
1151 | return CssAtRulePredicateAst;
|
1152 | }(CssAst));
|
1153 | var CssInlineRuleAst = (function (_super) {
|
1154 | __extends$3(CssInlineRuleAst, _super);
|
1155 | function CssInlineRuleAst(location, type, value) {
|
1156 | var _this = _super.call(this, location) || this;
|
1157 | _this.type = type;
|
1158 | _this.value = value;
|
1159 | return _this;
|
1160 | }
|
1161 | CssInlineRuleAst.prototype.visit = function (visitor, context) {
|
1162 | return visitor.visitCssInlineRule(this, context);
|
1163 | };
|
1164 | return CssInlineRuleAst;
|
1165 | }(CssRuleAst));
|
1166 | var CssSelectorRuleAst = (function (_super) {
|
1167 | __extends$3(CssSelectorRuleAst, _super);
|
1168 | function CssSelectorRuleAst(location, selectors, block) {
|
1169 | var _this = _super.call(this, location, BlockType.Selector, block) || this;
|
1170 | _this.selectors = selectors;
|
1171 | _this.strValue = selectors.map(function (selector) { return selector.strValue; }).join(',');
|
1172 | return _this;
|
1173 | }
|
1174 | CssSelectorRuleAst.prototype.visit = function (visitor, context) {
|
1175 | return visitor.visitCssSelectorRule(this, context);
|
1176 | };
|
1177 | return CssSelectorRuleAst;
|
1178 | }(CssBlockRuleAst));
|
1179 | var CssDefinitionAst = (function (_super) {
|
1180 | __extends$3(CssDefinitionAst, _super);
|
1181 | function CssDefinitionAst(location, property, value) {
|
1182 | var _this = _super.call(this, location) || this;
|
1183 | _this.property = property;
|
1184 | _this.value = value;
|
1185 | return _this;
|
1186 | }
|
1187 | CssDefinitionAst.prototype.visit = function (visitor, context) {
|
1188 | return visitor.visitCssDefinition(this, context);
|
1189 | };
|
1190 | return CssDefinitionAst;
|
1191 | }(CssAst));
|
1192 | var CssSelectorPartAst = (function (_super) {
|
1193 | __extends$3(CssSelectorPartAst, _super);
|
1194 | function CssSelectorPartAst(location) {
|
1195 | return _super.call(this, location) || this;
|
1196 | }
|
1197 | return CssSelectorPartAst;
|
1198 | }(CssAst));
|
1199 | var CssSelectorAst = (function (_super) {
|
1200 | __extends$3(CssSelectorAst, _super);
|
1201 | function CssSelectorAst(location, selectorParts) {
|
1202 | var _this = _super.call(this, location) || this;
|
1203 | _this.selectorParts = selectorParts;
|
1204 | _this.strValue = selectorParts.map(function (part) { return part.strValue; }).join('');
|
1205 | return _this;
|
1206 | }
|
1207 | CssSelectorAst.prototype.visit = function (visitor, context) {
|
1208 | return visitor.visitCssSelector(this, context);
|
1209 | };
|
1210 | return CssSelectorAst;
|
1211 | }(CssSelectorPartAst));
|
1212 | var CssSimpleSelectorAst = (function (_super) {
|
1213 | __extends$3(CssSimpleSelectorAst, _super);
|
1214 | function CssSimpleSelectorAst(location, tokens, strValue, pseudoSelectors, operator) {
|
1215 | var _this = _super.call(this, location) || this;
|
1216 | _this.tokens = tokens;
|
1217 | _this.strValue = strValue;
|
1218 | _this.pseudoSelectors = pseudoSelectors;
|
1219 | _this.operator = operator;
|
1220 | return _this;
|
1221 | }
|
1222 | CssSimpleSelectorAst.prototype.visit = function (visitor, context) {
|
1223 | return visitor.visitCssSimpleSelector(this, context);
|
1224 | };
|
1225 | return CssSimpleSelectorAst;
|
1226 | }(CssSelectorPartAst));
|
1227 | var CssPseudoSelectorAst = (function (_super) {
|
1228 | __extends$3(CssPseudoSelectorAst, _super);
|
1229 | function CssPseudoSelectorAst(location, strValue, name, tokens, innerSelectors) {
|
1230 | var _this = _super.call(this, location) || this;
|
1231 | _this.strValue = strValue;
|
1232 | _this.name = name;
|
1233 | _this.tokens = tokens;
|
1234 | _this.innerSelectors = innerSelectors;
|
1235 | return _this;
|
1236 | }
|
1237 | CssPseudoSelectorAst.prototype.visit = function (visitor, context) {
|
1238 | return visitor.visitCssPseudoSelector(this, context);
|
1239 | };
|
1240 | return CssPseudoSelectorAst;
|
1241 | }(CssSelectorPartAst));
|
1242 | var CssBlockAst = (function (_super) {
|
1243 | __extends$3(CssBlockAst, _super);
|
1244 | function CssBlockAst(location, entries) {
|
1245 | var _this = _super.call(this, location) || this;
|
1246 | _this.entries = entries;
|
1247 | return _this;
|
1248 | }
|
1249 | CssBlockAst.prototype.visit = function (visitor, context) { return visitor.visitCssBlock(this, context); };
|
1250 | return CssBlockAst;
|
1251 | }(CssAst));
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 | var CssStylesBlockAst = (function (_super) {
|
1257 | __extends$3(CssStylesBlockAst, _super);
|
1258 | function CssStylesBlockAst(location, definitions) {
|
1259 | var _this = _super.call(this, location, definitions) || this;
|
1260 | _this.definitions = definitions;
|
1261 | return _this;
|
1262 | }
|
1263 | CssStylesBlockAst.prototype.visit = function (visitor, context) {
|
1264 | return visitor.visitCssStylesBlock(this, context);
|
1265 | };
|
1266 | return CssStylesBlockAst;
|
1267 | }(CssBlockAst));
|
1268 | var CssStyleSheetAst = (function (_super) {
|
1269 | __extends$3(CssStyleSheetAst, _super);
|
1270 | function CssStyleSheetAst(location, rules) {
|
1271 | var _this = _super.call(this, location) || this;
|
1272 | _this.rules = rules;
|
1273 | return _this;
|
1274 | }
|
1275 | CssStyleSheetAst.prototype.visit = function (visitor, context) {
|
1276 | return visitor.visitCssStyleSheet(this, context);
|
1277 | };
|
1278 | return CssStyleSheetAst;
|
1279 | }(CssAst));
|
1280 | var CssUnknownRuleAst = (function (_super) {
|
1281 | __extends$3(CssUnknownRuleAst, _super);
|
1282 | function CssUnknownRuleAst(location, ruleName, tokens) {
|
1283 | var _this = _super.call(this, location) || this;
|
1284 | _this.ruleName = ruleName;
|
1285 | _this.tokens = tokens;
|
1286 | return _this;
|
1287 | }
|
1288 | CssUnknownRuleAst.prototype.visit = function (visitor, context) {
|
1289 | return visitor.visitCssUnknownRule(this, context);
|
1290 | };
|
1291 | return CssUnknownRuleAst;
|
1292 | }(CssRuleAst));
|
1293 | var CssUnknownTokenListAst = (function (_super) {
|
1294 | __extends$3(CssUnknownTokenListAst, _super);
|
1295 | function CssUnknownTokenListAst(location, name, tokens) {
|
1296 | var _this = _super.call(this, location) || this;
|
1297 | _this.name = name;
|
1298 | _this.tokens = tokens;
|
1299 | return _this;
|
1300 | }
|
1301 | CssUnknownTokenListAst.prototype.visit = function (visitor, context) {
|
1302 | return visitor.visitCssUnknownTokenList(this, context);
|
1303 | };
|
1304 | return CssUnknownTokenListAst;
|
1305 | }(CssRuleAst));
|
1306 | function mergeTokens(tokens, separator) {
|
1307 | if (separator === void 0) { separator = ''; }
|
1308 | var mainToken = tokens[0];
|
1309 | var str = mainToken.strValue;
|
1310 | for (var i = 1; i < tokens.length; i++) {
|
1311 | str += separator + tokens[i].strValue;
|
1312 | }
|
1313 | return new CssToken(mainToken.index, mainToken.column, mainToken.line, mainToken.type, str);
|
1314 | }
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 | var __extends$2 = (undefined && undefined.__extends) || (function () {
|
1324 | var extendStatics = Object.setPrototypeOf ||
|
1325 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
1326 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
1327 | return function (d, b) {
|
1328 | extendStatics(d, b);
|
1329 | function __() { this.constructor = d; }
|
1330 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
1331 | };
|
1332 | })();
|
1333 | var SPACE_OPERATOR = ' ';
|
1334 | var SLASH_CHARACTER = '/';
|
1335 | var GT_CHARACTER = '>';
|
1336 | var TRIPLE_GT_OPERATOR_STR = '>>>';
|
1337 | var DEEP_OPERATOR_STR = '/deep/';
|
1338 | var EOF_DELIM_FLAG = 1;
|
1339 | var RBRACE_DELIM_FLAG = 2;
|
1340 | var LBRACE_DELIM_FLAG = 4;
|
1341 | var COMMA_DELIM_FLAG = 8;
|
1342 | var COLON_DELIM_FLAG = 16;
|
1343 | var SEMICOLON_DELIM_FLAG = 32;
|
1344 | var NEWLINE_DELIM_FLAG = 64;
|
1345 | var RPAREN_DELIM_FLAG = 128;
|
1346 | var LPAREN_DELIM_FLAG = 256;
|
1347 | var SPACE_DELIM_FLAG = 512;
|
1348 | function _pseudoSelectorSupportsInnerSelectors(name) {
|
1349 | return ['not', 'host', 'host-context'].indexOf(name) >= 0;
|
1350 | }
|
1351 | function isSelectorOperatorCharacter(code) {
|
1352 | switch (code) {
|
1353 | case $SLASH:
|
1354 | case $TILDA:
|
1355 | case $PLUS:
|
1356 | case $GT:
|
1357 | return true;
|
1358 | default:
|
1359 | return isWhitespace(code);
|
1360 | }
|
1361 | }
|
1362 | function getDelimFromCharacter(code) {
|
1363 | switch (code) {
|
1364 | case $EOF:
|
1365 | return EOF_DELIM_FLAG;
|
1366 | case $COMMA:
|
1367 | return COMMA_DELIM_FLAG;
|
1368 | case $COLON:
|
1369 | return COLON_DELIM_FLAG;
|
1370 | case $SEMICOLON:
|
1371 | return SEMICOLON_DELIM_FLAG;
|
1372 | case $RBRACE:
|
1373 | return RBRACE_DELIM_FLAG;
|
1374 | case $LBRACE:
|
1375 | return LBRACE_DELIM_FLAG;
|
1376 | case $RPAREN:
|
1377 | return RPAREN_DELIM_FLAG;
|
1378 | case $SPACE:
|
1379 | case $TAB:
|
1380 | return SPACE_DELIM_FLAG;
|
1381 | default:
|
1382 | return isNewline(code) ? NEWLINE_DELIM_FLAG : 0;
|
1383 | }
|
1384 | }
|
1385 | function characterContainsDelimiter(code, delimiters) {
|
1386 | return (getDelimFromCharacter(code) & delimiters) > 0;
|
1387 | }
|
1388 | var ParsedCssResult = (function () {
|
1389 | function ParsedCssResult(errors, ast) {
|
1390 | this.errors = errors;
|
1391 | this.ast = ast;
|
1392 | }
|
1393 | return ParsedCssResult;
|
1394 | }());
|
1395 | var CssParser = (function () {
|
1396 | function CssParser() {
|
1397 | this._errors = [];
|
1398 | }
|
1399 | |
1400 |
|
1401 |
|
1402 |
|
1403 | CssParser.prototype.parse = function (css, url) {
|
1404 | var lexer = new CssLexer();
|
1405 | this._file = new ParseSourceFile(css, url);
|
1406 | this._scanner = lexer.scan(css, false);
|
1407 | var ast = this._parseStyleSheet(EOF_DELIM_FLAG);
|
1408 | var errors = this._errors;
|
1409 | this._errors = [];
|
1410 | var result = new ParsedCssResult(errors, ast);
|
1411 | this._file = null;
|
1412 | this._scanner = null;
|
1413 | return result;
|
1414 | };
|
1415 |
|
1416 | CssParser.prototype._parseStyleSheet = function (delimiters) {
|
1417 | var results = [];
|
1418 | this._scanner.consumeEmptyStatements();
|
1419 | while (this._scanner.peek != $EOF) {
|
1420 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1421 | results.push(this._parseRule(delimiters));
|
1422 | }
|
1423 | var span = null;
|
1424 | if (results.length > 0) {
|
1425 | var firstRule = results[0];
|
1426 |
|
1427 |
|
1428 | span = this._generateSourceSpan(firstRule, this._lastToken);
|
1429 | }
|
1430 | return new CssStyleSheetAst(span, results);
|
1431 | };
|
1432 |
|
1433 | CssParser.prototype._getSourceContent = function () { return this._scanner != null ? this._scanner.input : ''; };
|
1434 |
|
1435 | CssParser.prototype._extractSourceContent = function (start, end) {
|
1436 | return this._getSourceContent().substring(start, end + 1);
|
1437 | };
|
1438 |
|
1439 | CssParser.prototype._generateSourceSpan = function (start, end) {
|
1440 | if (end === void 0) { end = null; }
|
1441 | var startLoc;
|
1442 | if (start instanceof CssAst) {
|
1443 | startLoc = start.location.start;
|
1444 | }
|
1445 | else {
|
1446 | var token = start;
|
1447 | if (token == null) {
|
1448 |
|
1449 |
|
1450 | token = this._lastToken;
|
1451 | }
|
1452 | startLoc = new ParseLocation(this._file, token.index, token.line, token.column);
|
1453 | }
|
1454 | if (end == null) {
|
1455 | end = this._lastToken;
|
1456 | }
|
1457 | var endLine = -1;
|
1458 | var endColumn = -1;
|
1459 | var endIndex = -1;
|
1460 | if (end instanceof CssAst) {
|
1461 | endLine = end.location.end.line;
|
1462 | endColumn = end.location.end.col;
|
1463 | endIndex = end.location.end.offset;
|
1464 | }
|
1465 | else if (end instanceof CssToken) {
|
1466 | endLine = end.line;
|
1467 | endColumn = end.column;
|
1468 | endIndex = end.index;
|
1469 | }
|
1470 | var endLoc = new ParseLocation(this._file, endIndex, endLine, endColumn);
|
1471 | return new ParseSourceSpan(startLoc, endLoc);
|
1472 | };
|
1473 |
|
1474 | CssParser.prototype._resolveBlockType = function (token) {
|
1475 | switch (token.strValue) {
|
1476 | case '@-o-keyframes':
|
1477 | case '@-moz-keyframes':
|
1478 | case '@-webkit-keyframes':
|
1479 | case '@keyframes':
|
1480 | return BlockType.Keyframes;
|
1481 | case '@charset':
|
1482 | return BlockType.Charset;
|
1483 | case '@import':
|
1484 | return BlockType.Import;
|
1485 | case '@namespace':
|
1486 | return BlockType.Namespace;
|
1487 | case '@page':
|
1488 | return BlockType.Page;
|
1489 | case '@document':
|
1490 | return BlockType.Document;
|
1491 | case '@media':
|
1492 | return BlockType.MediaQuery;
|
1493 | case '@font-face':
|
1494 | return BlockType.FontFace;
|
1495 | case '@viewport':
|
1496 | return BlockType.Viewport;
|
1497 | case '@supports':
|
1498 | return BlockType.Supports;
|
1499 | default:
|
1500 | return BlockType.Unsupported;
|
1501 | }
|
1502 | };
|
1503 |
|
1504 | CssParser.prototype._parseRule = function (delimiters) {
|
1505 | if (this._scanner.peek == $AT) {
|
1506 | return this._parseAtRule(delimiters);
|
1507 | }
|
1508 | return this._parseSelectorRule(delimiters);
|
1509 | };
|
1510 |
|
1511 | CssParser.prototype._parseAtRule = function (delimiters) {
|
1512 | var start = this._getScannerIndex();
|
1513 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1514 | var token = this._scan();
|
1515 | var startToken = token;
|
1516 | this._assertCondition(token.type == CssTokenType.AtKeyword, "The CSS Rule " + token.strValue + " is not a valid [@] rule.", token);
|
1517 | var block;
|
1518 | var type = this._resolveBlockType(token);
|
1519 | var span;
|
1520 | var tokens;
|
1521 | var endToken;
|
1522 | var end;
|
1523 | var strValue;
|
1524 | var query;
|
1525 | switch (type) {
|
1526 | case BlockType.Charset:
|
1527 | case BlockType.Namespace:
|
1528 | case BlockType.Import:
|
1529 | var value = this._parseValue(delimiters);
|
1530 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1531 | this._scanner.consumeEmptyStatements();
|
1532 | span = this._generateSourceSpan(startToken, value);
|
1533 | return new CssInlineRuleAst(span, type, value);
|
1534 | case BlockType.Viewport:
|
1535 | case BlockType.FontFace:
|
1536 | block = this._parseStyleBlock(delimiters);
|
1537 | span = this._generateSourceSpan(startToken, block);
|
1538 | return new CssBlockRuleAst(span, type, block);
|
1539 | case BlockType.Keyframes:
|
1540 | tokens = this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG);
|
1541 |
|
1542 | var name_1 = tokens[0];
|
1543 | block = this._parseKeyframeBlock(delimiters);
|
1544 | span = this._generateSourceSpan(startToken, block);
|
1545 | return new CssKeyframeRuleAst(span, name_1, block);
|
1546 | case BlockType.MediaQuery:
|
1547 | this._scanner.setMode(CssLexerMode.MEDIA_QUERY);
|
1548 | tokens = this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG);
|
1549 | endToken = tokens[tokens.length - 1];
|
1550 |
|
1551 |
|
1552 | end = endToken.index + endToken.strValue.length - 1;
|
1553 | strValue = this._extractSourceContent(start, end);
|
1554 | span = this._generateSourceSpan(startToken, endToken);
|
1555 | query = new CssAtRulePredicateAst(span, strValue, tokens);
|
1556 | block = this._parseBlock(delimiters);
|
1557 | strValue = this._extractSourceContent(start, this._getScannerIndex() - 1);
|
1558 | span = this._generateSourceSpan(startToken, block);
|
1559 | return new CssMediaQueryRuleAst(span, strValue, query, block);
|
1560 | case BlockType.Document:
|
1561 | case BlockType.Supports:
|
1562 | case BlockType.Page:
|
1563 | this._scanner.setMode(CssLexerMode.AT_RULE_QUERY);
|
1564 | tokens = this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG);
|
1565 | endToken = tokens[tokens.length - 1];
|
1566 |
|
1567 |
|
1568 | end = endToken.index + endToken.strValue.length - 1;
|
1569 | strValue = this._extractSourceContent(start, end);
|
1570 | span = this._generateSourceSpan(startToken, tokens[tokens.length - 1]);
|
1571 | query = new CssAtRulePredicateAst(span, strValue, tokens);
|
1572 | block = this._parseBlock(delimiters);
|
1573 | strValue = this._extractSourceContent(start, block.end.offset);
|
1574 | span = this._generateSourceSpan(startToken, block);
|
1575 | return new CssBlockDefinitionRuleAst(span, strValue, type, query, block);
|
1576 |
|
1577 | default:
|
1578 | var listOfTokens_1 = [];
|
1579 | var tokenName = token.strValue;
|
1580 | this._scanner.setMode(CssLexerMode.ALL);
|
1581 | this._error(generateErrorMessage(this._getSourceContent(), "The CSS \"at\" rule \"" + tokenName + "\" is not allowed to used here", token.strValue, token.index, token.line, token.column), token);
|
1582 | this._collectUntilDelim(delimiters | LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG)
|
1583 | .forEach(function (token) { listOfTokens_1.push(token); });
|
1584 | if (this._scanner.peek == $LBRACE) {
|
1585 | listOfTokens_1.push(this._consume(CssTokenType.Character, '{'));
|
1586 | this._collectUntilDelim(delimiters | RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG)
|
1587 | .forEach(function (token) { listOfTokens_1.push(token); });
|
1588 | listOfTokens_1.push(this._consume(CssTokenType.Character, '}'));
|
1589 | }
|
1590 | endToken = listOfTokens_1[listOfTokens_1.length - 1];
|
1591 | span = this._generateSourceSpan(startToken, endToken);
|
1592 | return new CssUnknownRuleAst(span, tokenName, listOfTokens_1);
|
1593 | }
|
1594 | };
|
1595 |
|
1596 | CssParser.prototype._parseSelectorRule = function (delimiters) {
|
1597 | var start = this._getScannerIndex();
|
1598 | var selectors = this._parseSelectors(delimiters);
|
1599 | var block = this._parseStyleBlock(delimiters);
|
1600 | var ruleAst;
|
1601 | var span;
|
1602 | var startSelector = selectors[0];
|
1603 | if (block != null) {
|
1604 | span = this._generateSourceSpan(startSelector, block);
|
1605 | ruleAst = new CssSelectorRuleAst(span, selectors, block);
|
1606 | }
|
1607 | else {
|
1608 | var name_2 = this._extractSourceContent(start, this._getScannerIndex() - 1);
|
1609 | var innerTokens_1 = [];
|
1610 | selectors.forEach(function (selector) {
|
1611 | selector.selectorParts.forEach(function (part) {
|
1612 | part.tokens.forEach(function (token) { innerTokens_1.push(token); });
|
1613 | });
|
1614 | });
|
1615 | var endToken = innerTokens_1[innerTokens_1.length - 1];
|
1616 | span = this._generateSourceSpan(startSelector, endToken);
|
1617 | ruleAst = new CssUnknownTokenListAst(span, name_2, innerTokens_1);
|
1618 | }
|
1619 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1620 | this._scanner.consumeEmptyStatements();
|
1621 | return ruleAst;
|
1622 | };
|
1623 |
|
1624 | CssParser.prototype._parseSelectors = function (delimiters) {
|
1625 | delimiters |= LBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG;
|
1626 | var selectors = [];
|
1627 | var isParsingSelectors = true;
|
1628 | while (isParsingSelectors) {
|
1629 | selectors.push(this._parseSelector(delimiters));
|
1630 | isParsingSelectors = !characterContainsDelimiter(this._scanner.peek, delimiters);
|
1631 | if (isParsingSelectors) {
|
1632 | this._consume(CssTokenType.Character, ',');
|
1633 | isParsingSelectors = !characterContainsDelimiter(this._scanner.peek, delimiters);
|
1634 | if (isParsingSelectors) {
|
1635 | this._scanner.consumeWhitespace();
|
1636 | }
|
1637 | }
|
1638 | }
|
1639 | return selectors;
|
1640 | };
|
1641 |
|
1642 | CssParser.prototype._scan = function () {
|
1643 | var output = this._scanner.scan();
|
1644 | var token = output.token;
|
1645 | var error = output.error;
|
1646 | if (error != null) {
|
1647 | this._error(getRawMessage(error), token);
|
1648 | }
|
1649 | this._lastToken = token;
|
1650 | return token;
|
1651 | };
|
1652 |
|
1653 | CssParser.prototype._getScannerIndex = function () { return this._scanner.index; };
|
1654 |
|
1655 | CssParser.prototype._consume = function (type, value) {
|
1656 | if (value === void 0) { value = null; }
|
1657 | var output = this._scanner.consume(type, value);
|
1658 | var token = output.token;
|
1659 | var error = output.error;
|
1660 | if (error != null) {
|
1661 | this._error(getRawMessage(error), token);
|
1662 | }
|
1663 | this._lastToken = token;
|
1664 | return token;
|
1665 | };
|
1666 |
|
1667 | CssParser.prototype._parseKeyframeBlock = function (delimiters) {
|
1668 | delimiters |= RBRACE_DELIM_FLAG;
|
1669 | this._scanner.setMode(CssLexerMode.KEYFRAME_BLOCK);
|
1670 | var startToken = this._consume(CssTokenType.Character, '{');
|
1671 | var definitions = [];
|
1672 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1673 | definitions.push(this._parseKeyframeDefinition(delimiters));
|
1674 | }
|
1675 | var endToken = this._consume(CssTokenType.Character, '}');
|
1676 | var span = this._generateSourceSpan(startToken, endToken);
|
1677 | return new CssBlockAst(span, definitions);
|
1678 | };
|
1679 |
|
1680 | CssParser.prototype._parseKeyframeDefinition = function (delimiters) {
|
1681 | var start = this._getScannerIndex();
|
1682 | var stepTokens = [];
|
1683 | delimiters |= LBRACE_DELIM_FLAG;
|
1684 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1685 | stepTokens.push(this._parseKeyframeLabel(delimiters | COMMA_DELIM_FLAG));
|
1686 | if (this._scanner.peek != $LBRACE) {
|
1687 | this._consume(CssTokenType.Character, ',');
|
1688 | }
|
1689 | }
|
1690 | var stylesBlock = this._parseStyleBlock(delimiters | RBRACE_DELIM_FLAG);
|
1691 | var span = this._generateSourceSpan(stepTokens[0], stylesBlock);
|
1692 | var ast = new CssKeyframeDefinitionAst(span, stepTokens, stylesBlock);
|
1693 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1694 | return ast;
|
1695 | };
|
1696 |
|
1697 | CssParser.prototype._parseKeyframeLabel = function (delimiters) {
|
1698 | this._scanner.setMode(CssLexerMode.KEYFRAME_BLOCK);
|
1699 | return mergeTokens(this._collectUntilDelim(delimiters));
|
1700 | };
|
1701 |
|
1702 | CssParser.prototype._parsePseudoSelector = function (delimiters) {
|
1703 | var start = this._getScannerIndex();
|
1704 | delimiters &= ~COMMA_DELIM_FLAG;
|
1705 |
|
1706 | var startingDelims = delimiters;
|
1707 | var startToken = this._consume(CssTokenType.Character, ':');
|
1708 | var tokens = [startToken];
|
1709 | if (this._scanner.peek == $COLON) {
|
1710 | tokens.push(this._consume(CssTokenType.Character, ':'));
|
1711 | }
|
1712 | var innerSelectors = [];
|
1713 | this._scanner.setMode(CssLexerMode.PSEUDO_SELECTOR);
|
1714 |
|
1715 | var pseudoSelectorToken = this._consume(CssTokenType.Identifier);
|
1716 | var pseudoSelectorName = pseudoSelectorToken.strValue;
|
1717 | tokens.push(pseudoSelectorToken);
|
1718 |
|
1719 | if (this._scanner.peek == $LPAREN) {
|
1720 | this._scanner.setMode(CssLexerMode.PSEUDO_SELECTOR_WITH_ARGUMENTS);
|
1721 | var openParenToken = this._consume(CssTokenType.Character, '(');
|
1722 | tokens.push(openParenToken);
|
1723 |
|
1724 | if (_pseudoSelectorSupportsInnerSelectors(pseudoSelectorName)) {
|
1725 | var innerDelims = startingDelims | LPAREN_DELIM_FLAG | RPAREN_DELIM_FLAG;
|
1726 | if (pseudoSelectorName == 'not') {
|
1727 |
|
1728 |
|
1729 |
|
1730 | innerDelims |= COMMA_DELIM_FLAG;
|
1731 | }
|
1732 |
|
1733 | this._parseSelectors(innerDelims).forEach(function (selector, index) {
|
1734 | innerSelectors.push(selector);
|
1735 | });
|
1736 | }
|
1737 | else {
|
1738 |
|
1739 |
|
1740 | var innerValueDelims = delimiters | LBRACE_DELIM_FLAG | COLON_DELIM_FLAG |
|
1741 | RPAREN_DELIM_FLAG | LPAREN_DELIM_FLAG;
|
1742 | while (!characterContainsDelimiter(this._scanner.peek, innerValueDelims)) {
|
1743 | var token = this._scan();
|
1744 | tokens.push(token);
|
1745 | }
|
1746 | }
|
1747 | var closeParenToken = this._consume(CssTokenType.Character, ')');
|
1748 | tokens.push(closeParenToken);
|
1749 | }
|
1750 | var end = this._getScannerIndex() - 1;
|
1751 | var strValue = this._extractSourceContent(start, end);
|
1752 | var endToken = tokens[tokens.length - 1];
|
1753 | var span = this._generateSourceSpan(startToken, endToken);
|
1754 | return new CssPseudoSelectorAst(span, strValue, pseudoSelectorName, tokens, innerSelectors);
|
1755 | };
|
1756 |
|
1757 | CssParser.prototype._parseSimpleSelector = function (delimiters) {
|
1758 | var start = this._getScannerIndex();
|
1759 | delimiters |= COMMA_DELIM_FLAG;
|
1760 | this._scanner.setMode(CssLexerMode.SELECTOR);
|
1761 | var selectorCssTokens = [];
|
1762 | var pseudoSelectors = [];
|
1763 | var previousToken = undefined;
|
1764 | var selectorPartDelimiters = delimiters | SPACE_DELIM_FLAG;
|
1765 | var loopOverSelector = !characterContainsDelimiter(this._scanner.peek, selectorPartDelimiters);
|
1766 | var hasAttributeError = false;
|
1767 | while (loopOverSelector) {
|
1768 | var peek = this._scanner.peek;
|
1769 | switch (peek) {
|
1770 | case $COLON:
|
1771 | var innerPseudo = this._parsePseudoSelector(delimiters);
|
1772 | pseudoSelectors.push(innerPseudo);
|
1773 | this._scanner.setMode(CssLexerMode.SELECTOR);
|
1774 | break;
|
1775 | case $LBRACKET:
|
1776 |
|
1777 |
|
1778 |
|
1779 | selectorCssTokens.push(this._scan());
|
1780 | this._scanner.setMode(CssLexerMode.ATTRIBUTE_SELECTOR);
|
1781 | break;
|
1782 | case $RBRACKET:
|
1783 | if (this._scanner.getMode() != CssLexerMode.ATTRIBUTE_SELECTOR) {
|
1784 | hasAttributeError = true;
|
1785 | }
|
1786 |
|
1787 |
|
1788 | this._scanner.setMode(CssLexerMode.SELECTOR);
|
1789 | selectorCssTokens.push(this._scan());
|
1790 | break;
|
1791 | default:
|
1792 | if (isSelectorOperatorCharacter(peek)) {
|
1793 | loopOverSelector = false;
|
1794 | continue;
|
1795 | }
|
1796 | var token = this._scan();
|
1797 | previousToken = token;
|
1798 | selectorCssTokens.push(token);
|
1799 | break;
|
1800 | }
|
1801 | loopOverSelector = !characterContainsDelimiter(this._scanner.peek, selectorPartDelimiters);
|
1802 | }
|
1803 | hasAttributeError =
|
1804 | hasAttributeError || this._scanner.getMode() == CssLexerMode.ATTRIBUTE_SELECTOR;
|
1805 | if (hasAttributeError) {
|
1806 | this._error("Unbalanced CSS attribute selector at column " + previousToken.line + ":" + previousToken.column, previousToken);
|
1807 | }
|
1808 | var end = this._getScannerIndex() - 1;
|
1809 |
|
1810 |
|
1811 | var operator = null;
|
1812 | var operatorScanCount = 0;
|
1813 | var lastOperatorToken = null;
|
1814 | if (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1815 | while (operator == null && !characterContainsDelimiter(this._scanner.peek, delimiters) &&
|
1816 | isSelectorOperatorCharacter(this._scanner.peek)) {
|
1817 | var token = this._scan();
|
1818 | var tokenOperator = token.strValue;
|
1819 | operatorScanCount++;
|
1820 | lastOperatorToken = token;
|
1821 | if (tokenOperator != SPACE_OPERATOR) {
|
1822 | switch (tokenOperator) {
|
1823 | case SLASH_CHARACTER:
|
1824 |
|
1825 | var deepToken = this._consume(CssTokenType.Identifier);
|
1826 | var deepSlash = this._consume(CssTokenType.Character);
|
1827 | var index = lastOperatorToken.index;
|
1828 | var line = lastOperatorToken.line;
|
1829 | var column = lastOperatorToken.column;
|
1830 | if (deepToken != null && deepToken.strValue.toLowerCase() == 'deep' &&
|
1831 | deepSlash.strValue == SLASH_CHARACTER) {
|
1832 | token = new CssToken(lastOperatorToken.index, lastOperatorToken.column, lastOperatorToken.line, CssTokenType.Identifier, DEEP_OPERATOR_STR);
|
1833 | }
|
1834 | else {
|
1835 | var text = SLASH_CHARACTER + deepToken.strValue + deepSlash.strValue;
|
1836 | this._error(generateErrorMessage(this._getSourceContent(), text + " is an invalid CSS operator", text, index, line, column), lastOperatorToken);
|
1837 | token = new CssToken(index, column, line, CssTokenType.Invalid, text);
|
1838 | }
|
1839 | break;
|
1840 | case GT_CHARACTER:
|
1841 |
|
1842 | if (this._scanner.peek == $GT && this._scanner.peekPeek == $GT) {
|
1843 | this._consume(CssTokenType.Character, GT_CHARACTER);
|
1844 | this._consume(CssTokenType.Character, GT_CHARACTER);
|
1845 | token = new CssToken(lastOperatorToken.index, lastOperatorToken.column, lastOperatorToken.line, CssTokenType.Identifier, TRIPLE_GT_OPERATOR_STR);
|
1846 | }
|
1847 | break;
|
1848 | }
|
1849 | operator = token;
|
1850 | }
|
1851 | }
|
1852 |
|
1853 |
|
1854 |
|
1855 | if (operator != null) {
|
1856 | end = operator.index;
|
1857 | }
|
1858 | }
|
1859 | this._scanner.consumeWhitespace();
|
1860 | var strValue = this._extractSourceContent(start, end);
|
1861 |
|
1862 |
|
1863 |
|
1864 | if (operator == null && operatorScanCount > 0 && this._scanner.peek != $LBRACE) {
|
1865 | operator = lastOperatorToken;
|
1866 | }
|
1867 |
|
1868 |
|
1869 | var startTokenOrAst = null;
|
1870 | var endTokenOrAst = null;
|
1871 | if (selectorCssTokens.length > 0) {
|
1872 | startTokenOrAst = startTokenOrAst || selectorCssTokens[0];
|
1873 | endTokenOrAst = selectorCssTokens[selectorCssTokens.length - 1];
|
1874 | }
|
1875 | if (pseudoSelectors.length > 0) {
|
1876 | startTokenOrAst = startTokenOrAst || pseudoSelectors[0];
|
1877 | endTokenOrAst = pseudoSelectors[pseudoSelectors.length - 1];
|
1878 | }
|
1879 | if (operator != null) {
|
1880 | startTokenOrAst = startTokenOrAst || operator;
|
1881 | endTokenOrAst = operator;
|
1882 | }
|
1883 | var span = this._generateSourceSpan(startTokenOrAst, endTokenOrAst);
|
1884 | return new CssSimpleSelectorAst(span, selectorCssTokens, strValue, pseudoSelectors, operator);
|
1885 | };
|
1886 |
|
1887 | CssParser.prototype._parseSelector = function (delimiters) {
|
1888 | delimiters |= COMMA_DELIM_FLAG;
|
1889 | this._scanner.setMode(CssLexerMode.SELECTOR);
|
1890 | var simpleSelectors = [];
|
1891 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1892 | simpleSelectors.push(this._parseSimpleSelector(delimiters));
|
1893 | this._scanner.consumeWhitespace();
|
1894 | }
|
1895 | var firstSelector = simpleSelectors[0];
|
1896 | var lastSelector = simpleSelectors[simpleSelectors.length - 1];
|
1897 | var span = this._generateSourceSpan(firstSelector, lastSelector);
|
1898 | return new CssSelectorAst(span, simpleSelectors);
|
1899 | };
|
1900 |
|
1901 | CssParser.prototype._parseValue = function (delimiters) {
|
1902 | delimiters |= RBRACE_DELIM_FLAG | SEMICOLON_DELIM_FLAG | NEWLINE_DELIM_FLAG;
|
1903 | this._scanner.setMode(CssLexerMode.STYLE_VALUE);
|
1904 | var start = this._getScannerIndex();
|
1905 | var tokens = [];
|
1906 | var wsStr = '';
|
1907 | var previous = undefined;
|
1908 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1909 | var token = void 0;
|
1910 | if (previous != null && previous.type == CssTokenType.Identifier &&
|
1911 | this._scanner.peek == $LPAREN) {
|
1912 | token = this._consume(CssTokenType.Character, '(');
|
1913 | tokens.push(token);
|
1914 | this._scanner.setMode(CssLexerMode.STYLE_VALUE_FUNCTION);
|
1915 | token = this._scan();
|
1916 | tokens.push(token);
|
1917 | this._scanner.setMode(CssLexerMode.STYLE_VALUE);
|
1918 | token = this._consume(CssTokenType.Character, ')');
|
1919 | tokens.push(token);
|
1920 | }
|
1921 | else {
|
1922 | token = this._scan();
|
1923 | if (token.type == CssTokenType.Whitespace) {
|
1924 | wsStr += token.strValue;
|
1925 | }
|
1926 | else {
|
1927 | wsStr = '';
|
1928 | tokens.push(token);
|
1929 | }
|
1930 | }
|
1931 | previous = token;
|
1932 | }
|
1933 | var end = this._getScannerIndex() - 1;
|
1934 | this._scanner.consumeWhitespace();
|
1935 | var code = this._scanner.peek;
|
1936 | if (code == $SEMICOLON) {
|
1937 | this._consume(CssTokenType.Character, ';');
|
1938 | }
|
1939 | else if (code != $RBRACE) {
|
1940 | this._error(generateErrorMessage(this._getSourceContent(), "The CSS key/value definition did not end with a semicolon", previous.strValue, previous.index, previous.line, previous.column), previous);
|
1941 | }
|
1942 | var strValue = this._extractSourceContent(start, end);
|
1943 | var startToken = tokens[0];
|
1944 | var endToken = tokens[tokens.length - 1];
|
1945 | var span = this._generateSourceSpan(startToken, endToken);
|
1946 | return new CssStyleValueAst(span, tokens, strValue);
|
1947 | };
|
1948 |
|
1949 | CssParser.prototype._collectUntilDelim = function (delimiters, assertType) {
|
1950 | if (assertType === void 0) { assertType = null; }
|
1951 | var tokens = [];
|
1952 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1953 | var val = assertType != null ? this._consume(assertType) : this._scan();
|
1954 | tokens.push(val);
|
1955 | }
|
1956 | return tokens;
|
1957 | };
|
1958 |
|
1959 | CssParser.prototype._parseBlock = function (delimiters) {
|
1960 | delimiters |= RBRACE_DELIM_FLAG;
|
1961 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1962 | var startToken = this._consume(CssTokenType.Character, '{');
|
1963 | this._scanner.consumeEmptyStatements();
|
1964 | var results = [];
|
1965 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1966 | results.push(this._parseRule(delimiters));
|
1967 | }
|
1968 | var endToken = this._consume(CssTokenType.Character, '}');
|
1969 | this._scanner.setMode(CssLexerMode.BLOCK);
|
1970 | this._scanner.consumeEmptyStatements();
|
1971 | var span = this._generateSourceSpan(startToken, endToken);
|
1972 | return new CssBlockAst(span, results);
|
1973 | };
|
1974 |
|
1975 | CssParser.prototype._parseStyleBlock = function (delimiters) {
|
1976 | delimiters |= RBRACE_DELIM_FLAG | LBRACE_DELIM_FLAG;
|
1977 | this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
|
1978 | var startToken = this._consume(CssTokenType.Character, '{');
|
1979 | if (startToken.numValue != $LBRACE) {
|
1980 | return null;
|
1981 | }
|
1982 | var definitions = [];
|
1983 | this._scanner.consumeEmptyStatements();
|
1984 | while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
|
1985 | definitions.push(this._parseDefinition(delimiters));
|
1986 | this._scanner.consumeEmptyStatements();
|
1987 | }
|
1988 | var endToken = this._consume(CssTokenType.Character, '}');
|
1989 | this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
|
1990 | this._scanner.consumeEmptyStatements();
|
1991 | var span = this._generateSourceSpan(startToken, endToken);
|
1992 | return new CssStylesBlockAst(span, definitions);
|
1993 | };
|
1994 |
|
1995 | CssParser.prototype._parseDefinition = function (delimiters) {
|
1996 | this._scanner.setMode(CssLexerMode.STYLE_BLOCK);
|
1997 | var prop = this._consume(CssTokenType.Identifier);
|
1998 | var parseValue = false;
|
1999 | var value = null;
|
2000 | var endToken = prop;
|
2001 |
|
2002 |
|
2003 |
|
2004 | switch (this._scanner.peek) {
|
2005 | case $SEMICOLON:
|
2006 | case $RBRACE:
|
2007 | case $EOF:
|
2008 | parseValue = false;
|
2009 | break;
|
2010 | default:
|
2011 | var propStr_1 = [prop.strValue];
|
2012 | if (this._scanner.peek != $COLON) {
|
2013 |
|
2014 | var nextValue = this._consume(CssTokenType.Character, ':');
|
2015 | propStr_1.push(nextValue.strValue);
|
2016 | var remainingTokens = this._collectUntilDelim(delimiters | COLON_DELIM_FLAG | SEMICOLON_DELIM_FLAG, CssTokenType.Identifier);
|
2017 | if (remainingTokens.length > 0) {
|
2018 | remainingTokens.forEach(function (token) { propStr_1.push(token.strValue); });
|
2019 | }
|
2020 | endToken = prop =
|
2021 | new CssToken(prop.index, prop.column, prop.line, prop.type, propStr_1.join(' '));
|
2022 | }
|
2023 |
|
2024 | if (this._scanner.peek == $COLON) {
|
2025 | this._consume(CssTokenType.Character, ':');
|
2026 | parseValue = true;
|
2027 | }
|
2028 | break;
|
2029 | }
|
2030 | if (parseValue) {
|
2031 | value = this._parseValue(delimiters);
|
2032 | endToken = value;
|
2033 | }
|
2034 | else {
|
2035 | this._error(generateErrorMessage(this._getSourceContent(), "The CSS property was not paired with a style value", prop.strValue, prop.index, prop.line, prop.column), prop);
|
2036 | }
|
2037 | var span = this._generateSourceSpan(prop, endToken);
|
2038 | return new CssDefinitionAst(span, prop, value);
|
2039 | };
|
2040 |
|
2041 | CssParser.prototype._assertCondition = function (status, errorMessage, problemToken) {
|
2042 | if (!status) {
|
2043 | this._error(errorMessage, problemToken);
|
2044 | return true;
|
2045 | }
|
2046 | return false;
|
2047 | };
|
2048 |
|
2049 | CssParser.prototype._error = function (message, problemToken) {
|
2050 | var length = problemToken.strValue.length;
|
2051 | var error = CssParseError.create(this._file, 0, problemToken.line, problemToken.column, length, message);
|
2052 | this._errors.push(error);
|
2053 | };
|
2054 | return CssParser;
|
2055 | }());
|
2056 | var CssParseError = (function (_super) {
|
2057 | __extends$2(CssParseError, _super);
|
2058 | function CssParseError(span, message) {
|
2059 | return _super.call(this, span, message) || this;
|
2060 | }
|
2061 | CssParseError.create = function (file, offset, line, col, length, errMsg) {
|
2062 | var start = new ParseLocation(file, offset, line, col);
|
2063 | var end = new ParseLocation(file, offset, line, col + length);
|
2064 | var span = new ParseSourceSpan(start, end);
|
2065 | return new CssParseError(span, 'CSS Parse Error: ' + errMsg);
|
2066 | };
|
2067 | return CssParseError;
|
2068 | }(ParseError));
|
2069 |
|
2070 | var parseCss = function (text) {
|
2071 | var parser = new CssParser();
|
2072 | return parser.parse(text, '').ast;
|
2073 | };
|
2074 |
|
2075 | var __extends$1 = (undefined && undefined.__extends) || (function () {
|
2076 | var extendStatics = Object.setPrototypeOf ||
|
2077 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
2078 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
2079 | return function (d, b) {
|
2080 | extendStatics(d, b);
|
2081 | function __() { this.constructor = d; }
|
2082 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
2083 | };
|
2084 | })();
|
2085 |
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 | var DirectiveSymbol = (function (_super) {
|
2094 | __extends$1(DirectiveSymbol, _super);
|
2095 | |
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 | function DirectiveSymbol(program, symbol, metadataResolver, directiveNormalizer, resolver, reflector, resourceResolver, projectSymbols) {
|
2110 | var _this = _super.call(this, program, symbol) || this;
|
2111 | _this.metadataResolver = metadataResolver;
|
2112 | _this.directiveNormalizer = directiveNormalizer;
|
2113 | _this.resolver = resolver;
|
2114 | _this.reflector = reflector;
|
2115 | _this.resourceResolver = resourceResolver;
|
2116 | _this.projectSymbols = projectSymbols;
|
2117 | _this.urlResolver = new _angular_compiler.UrlResolver();
|
2118 | return _this;
|
2119 | }
|
2120 | |
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 | DirectiveSymbol.prototype.getNonResolvedMetadata = function () {
|
2131 | var data = this.metadataResolver.getNonNormalizedDirectiveMetadata(this.symbol);
|
2132 | if (data) {
|
2133 | return data.metadata;
|
2134 | }
|
2135 | return null;
|
2136 | };
|
2137 |
|
2138 | |
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 | DirectiveSymbol.prototype.getResolvedMetadata = function () {
|
2148 | var _this = this;
|
2149 | var metadata = this.metadataResolver.getNonNormalizedDirectiveMetadata(this.symbol);
|
2150 | var componentType = _angular_core.resolveForwardRef(this.symbol);
|
2151 | if (!metadata) {
|
2152 | return null;
|
2153 | }
|
2154 | var componentUrl = _angular_compiler.componentModuleUrl(this.reflector, componentType, metadata);
|
2155 | var templateMetadata = metadata.metadata.template;
|
2156 |
|
2157 | if (!templateMetadata) {
|
2158 | return null;
|
2159 | }
|
2160 | if (!templateMetadata.template && templateMetadata.templateUrl) {
|
2161 | templateMetadata.templateUrl = this.urlResolver.resolve(componentUrl, templateMetadata.templateUrl);
|
2162 | templateMetadata.template = this.resourceResolver.getSync(templateMetadata.templateUrl);
|
2163 | }
|
2164 | var module = this.getModule();
|
2165 | if (!module) {
|
2166 | return null;
|
2167 | }
|
2168 | var currentMetadata = this.directiveNormalizer.normalizeTemplateSync(Object.assign(templateMetadata, {
|
2169 | ngModuleType: module.type.reference,
|
2170 | moduleUrl: componentUrl,
|
2171 | componentType: componentType
|
2172 | }));
|
2173 | if (templateMetadata.templateUrl) {
|
2174 | currentMetadata.template = this.resourceResolver.getSync(templateMetadata.templateUrl);
|
2175 | currentMetadata.templateUrl = templateMetadata.templateUrl;
|
2176 | }
|
2177 | currentMetadata.styles = currentMetadata.styles.concat(currentMetadata.styleUrls.map(function (path) {
|
2178 | return _this.resourceResolver.getSync(path);
|
2179 | }));
|
2180 | return currentMetadata;
|
2181 | };
|
2182 | |
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 | DirectiveSymbol.prototype.getModule = function () {
|
2190 | return this.projectSymbols
|
2191 | .getAnalyzedModules().ngModuleByPipeOrDirective.get(this.symbol);
|
2192 | };
|
2193 | |
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 | DirectiveSymbol.prototype.getStyleAsts = function () {
|
2201 | var metadata = this.getResolvedMetadata();
|
2202 | if (metadata) {
|
2203 | return metadata.styles.map(function (s) { return parseCss(s); });
|
2204 | }
|
2205 | return null;
|
2206 | };
|
2207 | |
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 | DirectiveSymbol.prototype.getDirectiveContext = function () {
|
2216 | var _this = this;
|
2217 | var analyzedModules = this.projectSymbols.getAnalyzedModules();
|
2218 | var ngModule = analyzedModules.ngModuleByPipeOrDirective.get(this.symbol);
|
2219 | if (!ngModule) {
|
2220 | throw new Error('Cannot find module associated with the directive ' + this.symbol.name);
|
2221 | }
|
2222 | var resolvedDirectives = ngModule.transitiveModule.directives.map(function (d) { return _this.metadataResolver.getNonNormalizedDirectiveMetadata(d.reference); });
|
2223 |
|
2224 | var tempDirectives = resolvedDirectives
|
2225 | .map(function (d) {
|
2226 | if (d) {
|
2227 | return d.metadata.toSummary();
|
2228 | }
|
2229 | else {
|
2230 | return null;
|
2231 | }
|
2232 | });
|
2233 | var directives = [];
|
2234 | for (var i = 0; i < tempDirectives.length; i += 1) {
|
2235 | var dir = tempDirectives[i];
|
2236 | if (dir) {
|
2237 | directives.push(dir);
|
2238 | }
|
2239 | }
|
2240 | var pipes = ngModule.transitiveModule.pipes.map(function (p) { return _this.metadataResolver.getOrLoadPipeMetadata(p.reference).toSummary(); });
|
2241 | var schemas = ngModule.schemas;
|
2242 | return {
|
2243 | pipes: pipes, directives: directives, schemas: schemas
|
2244 | };
|
2245 | };
|
2246 | |
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 | DirectiveSymbol.prototype.getTemplateAst = function () {
|
2254 | var result;
|
2255 | try {
|
2256 | var resolvedMetadata = this.metadataResolver.getNonNormalizedDirectiveMetadata(this.symbol);
|
2257 | var dirMetadata = this.getResolvedMetadata();
|
2258 | if (dirMetadata) {
|
2259 | var source = dirMetadata.template;
|
2260 | if (!source) {
|
2261 | result = { errors: [{ message: 'Cannot find template for the directive' }] };
|
2262 | }
|
2263 | else {
|
2264 | var metadata = resolvedMetadata && resolvedMetadata.metadata;
|
2265 | if (metadata) {
|
2266 | var rawHtmlParser = new _angular_compiler.HtmlParser();
|
2267 | var htmlParser = new _angular_compiler.I18NHtmlParser(rawHtmlParser);
|
2268 | var expressionParser = new _angular_compiler.Parser(new _angular_compiler.Lexer());
|
2269 | var parser = void 0;
|
2270 | parser = new _angular_compiler.TemplateParser(new _angular_compiler.CompilerConfig, expressionParser, new _angular_compiler.DomElementSchemaRegistry(), htmlParser, {
|
2271 | log: function () {
|
2272 | return null;
|
2273 | },
|
2274 | warn: function () {
|
2275 | return null;
|
2276 | }
|
2277 | }, []);
|
2278 | var htmlResult = htmlParser.parse(source, '');
|
2279 | var _a = this.getDirectiveContext(), directives = _a.directives, pipes = _a.pipes, schemas = _a.schemas;
|
2280 | var parseResult = parser.tryParseHtml(htmlResult, metadata, directives, pipes, schemas);
|
2281 | result = {
|
2282 | templateAst: parseResult.templateAst,
|
2283 | parseErrors: parseResult.errors,
|
2284 | errors: []
|
2285 | };
|
2286 | }
|
2287 | else {
|
2288 | result = { errors: [{ message: 'Cannot find metadata for the directive' }] };
|
2289 | }
|
2290 | }
|
2291 | }
|
2292 | else {
|
2293 | result = { errors: [{ message: 'Cannot find metadata for the directive' }] };
|
2294 | }
|
2295 | }
|
2296 | catch (e) {
|
2297 | result = { errors: [{ message: e.message }] };
|
2298 | }
|
2299 | return result;
|
2300 | };
|
2301 | DirectiveSymbol.prototype.getDependencies = function () {
|
2302 | var _this = this;
|
2303 | var summary = this.metadataResolver.getInjectableSummary(this.symbol);
|
2304 | if (!summary) {
|
2305 | return [];
|
2306 | }
|
2307 | else {
|
2308 | return (summary.type.diDeps || []).map(function (d) {
|
2309 | var token = d.token;
|
2310 | if (d.token) {
|
2311 | if (d.token.identifier) {
|
2312 | token = d.token.identifier.reference;
|
2313 | }
|
2314 | }
|
2315 | var meta = new _angular_compiler.ProviderMeta(token, d);
|
2316 | return new ProviderSymbol(_this._program, _this.metadataResolver.getProviderMetadata(meta), _this.metadataResolver);
|
2317 | });
|
2318 | }
|
2319 | };
|
2320 | DirectiveSymbol.prototype.getProviders = function () {
|
2321 | var _this = this;
|
2322 | var meta = this.getNonResolvedMetadata();
|
2323 | if (meta) {
|
2324 | return (meta.providers || []).map(function (d) {
|
2325 | return new ProviderSymbol(_this._program, d, _this.metadataResolver);
|
2326 | });
|
2327 | }
|
2328 | return [];
|
2329 | };
|
2330 | DirectiveSymbol.prototype.getViewProviders = function () {
|
2331 | var _this = this;
|
2332 | var meta = this.getNonResolvedMetadata();
|
2333 | if (meta) {
|
2334 | return (meta.viewProviders || []).map(function (d) {
|
2335 | return new ProviderSymbol(_this._program, d, _this.metadataResolver);
|
2336 | });
|
2337 | }
|
2338 | else {
|
2339 | return [];
|
2340 | }
|
2341 | };
|
2342 | |
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 | DirectiveSymbol.prototype.isComponent = function () {
|
2350 | var meta = this.getResolvedMetadata();
|
2351 | if (meta) {
|
2352 | return !!meta.template || !!meta.templateUrl;
|
2353 | }
|
2354 | else {
|
2355 | return false;
|
2356 | }
|
2357 | };
|
2358 | return DirectiveSymbol;
|
2359 | }(Symbol));
|
2360 |
|
2361 | var __extends$4 = (undefined && undefined.__extends) || (function () {
|
2362 | var extendStatics = Object.setPrototypeOf ||
|
2363 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
2364 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
2365 | return function (d, b) {
|
2366 | extendStatics(d, b);
|
2367 | function __() { this.constructor = d; }
|
2368 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
2369 | };
|
2370 | })();
|
2371 | var ModuleSymbol = (function (_super) {
|
2372 | __extends$4(ModuleSymbol, _super);
|
2373 | function ModuleSymbol(program, symbol, metadataResolver, directiveNormalizer, resolver, pipeResolver, reflector, resourceResolver, projectSymbols) {
|
2374 | var _this = _super.call(this, program, symbol) || this;
|
2375 | _this.metadataResolver = metadataResolver;
|
2376 | _this.directiveNormalizer = directiveNormalizer;
|
2377 | _this.resolver = resolver;
|
2378 | _this.pipeResolver = pipeResolver;
|
2379 | _this.reflector = reflector;
|
2380 | _this.resourceResolver = resourceResolver;
|
2381 | _this.projectSymbols = projectSymbols;
|
2382 | var meta = _this.metadataResolver.getNgModuleMetadata(symbol);
|
2383 | if (meta) {
|
2384 | _this.module = meta;
|
2385 | }
|
2386 | else {
|
2387 | throw new Error('No metadata for ' + symbol.name);
|
2388 | }
|
2389 | return _this;
|
2390 | }
|
2391 | ModuleSymbol.prototype.getBootstrapComponents = function () {
|
2392 | return this.getWrapperDirectives(this.module.bootstrapComponents);
|
2393 | };
|
2394 | ModuleSymbol.prototype.getDeclaredDirectives = function () {
|
2395 | return this.getWrapperDirectives(this.module.declaredDirectives);
|
2396 | };
|
2397 | ModuleSymbol.prototype.getExportedDirectives = function () {
|
2398 | return this.getWrapperDirectives(this.module.exportedDirectives);
|
2399 | };
|
2400 | ModuleSymbol.prototype.getExportedPipes = function () {
|
2401 | return this.getWrappedPipes(this.module.exportedPipes);
|
2402 | };
|
2403 | ModuleSymbol.prototype.getDeclaredPipes = function () {
|
2404 | return this.getWrappedPipes(this.module.declaredPipes);
|
2405 | };
|
2406 | ModuleSymbol.prototype.getImportedModules = function () {
|
2407 | return this.getWrappedModules(this.module.importedModules);
|
2408 | };
|
2409 | ModuleSymbol.prototype.getExportedModules = function () {
|
2410 | return this.getWrappedModules(this.module.exportedModules);
|
2411 | };
|
2412 | |
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 | ModuleSymbol.prototype.getModuleSummary = function () {
|
2420 | return this.metadataResolver.getNgModuleSummary(this.symbol);
|
2421 | };
|
2422 | ModuleSymbol.prototype.getProviders = function () {
|
2423 | var _this = this;
|
2424 | return this.module.providers.map(function (p) {
|
2425 | return new ProviderSymbol(_this._program, p, _this.metadataResolver);
|
2426 | });
|
2427 | };
|
2428 | ModuleSymbol.prototype.getWrappedModules = function (modules) {
|
2429 | var _this = this;
|
2430 | return modules.map(function (s) {
|
2431 | return new ModuleSymbol(_this._program, s.type.reference, _this.metadataResolver, _this.directiveNormalizer, _this.resolver, _this.pipeResolver, _this.reflector, _this.resourceResolver, _this.projectSymbols);
|
2432 | });
|
2433 | };
|
2434 | ModuleSymbol.prototype.getWrappedPipes = function (pipes) {
|
2435 | var _this = this;
|
2436 | return pipes.map(function (i) {
|
2437 | return new PipeSymbol(_this._program, i.reference, _this.pipeResolver, _this.metadataResolver, _this.projectSymbols);
|
2438 | });
|
2439 | };
|
2440 | ModuleSymbol.prototype.getWrapperDirectives = function (dirs) {
|
2441 | var _this = this;
|
2442 | return dirs.map(function (i) {
|
2443 | return new DirectiveSymbol(_this._program, i.reference, _this.metadataResolver, _this.directiveNormalizer, _this.resolver, _this.reflector, _this.resourceResolver, _this.projectSymbols);
|
2444 | });
|
2445 | };
|
2446 | return ModuleSymbol;
|
2447 | }(Symbol));
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 | var ProjectSymbols = (function () {
|
2457 | |
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 | function ProjectSymbols(program, resourceResolver, errorReporter) {
|
2466 | this.program = program;
|
2467 | this.resourceResolver = resourceResolver;
|
2468 | this.errorReporter = errorReporter;
|
2469 | this.options = this.program.getCompilerOptions();
|
2470 | this.init();
|
2471 | }
|
2472 | |
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 | ProjectSymbols.prototype.getModules = function () {
|
2480 | var _this = this;
|
2481 | this.validate();
|
2482 | var resultMap = new Map();
|
2483 | this.getAnalyzedModules()
|
2484 | .ngModules
|
2485 | .forEach(function (m, s) {
|
2486 | resultMap.set(m.type.reference, m);
|
2487 | });
|
2488 | var result = [];
|
2489 | resultMap.forEach(function (v) { return result.push(new ModuleSymbol(_this.program, v.type.reference, _this.metadataResolver, _this.directiveNormalizer, _this.directiveResolver, _this.pipeResolver, _this.reflector, _this.resourceResolver, _this)); });
|
2490 | return result;
|
2491 | };
|
2492 | |
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | ProjectSymbols.prototype.getDirectives = function () {
|
2500 | var _this = this;
|
2501 | return this.extractProgramSymbols()
|
2502 | .filter(function (symbol) { return _this.metadataResolver.isDirective(symbol); })
|
2503 | .map(function (symbol) { return new DirectiveSymbol(_this.program, symbol, _this.metadataResolver, _this.directiveNormalizer, _this.directiveResolver, _this.reflector, _this.resourceResolver, _this); });
|
2504 | };
|
2505 | |
2506 |
|
2507 |
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 | ProjectSymbols.prototype.getPipes = function () {
|
2513 | var _this = this;
|
2514 | return this.extractProgramSymbols()
|
2515 | .filter(function (v) { return _this.metadataResolver.isPipe(v); })
|
2516 | .map(function (p) { return new PipeSymbol(_this.program, p, _this.pipeResolver, _this.metadataResolver, _this); });
|
2517 | };
|
2518 | |
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 | ProjectSymbols.prototype.getProviders = function () {
|
2526 | var resultSet = new Map();
|
2527 | this.getModules().forEach(function (m) {
|
2528 | m.getProviders().forEach(function (p) { return resultSet.set(p.getMetadata(), p); });
|
2529 | });
|
2530 | this.getDirectives().forEach(function (d) {
|
2531 | d.getProviders().forEach(function (p) { return resultSet.set(p.getMetadata(), p); });
|
2532 | d.getViewProviders().forEach(function (p) { return resultSet.set(p.getMetadata(), p); });
|
2533 | });
|
2534 | var finalResult = [];
|
2535 | resultSet.forEach(function (v) { return finalResult.push(v); });
|
2536 | return finalResult;
|
2537 | };
|
2538 | |
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 | ProjectSymbols.prototype.updateProgram = function (program) {
|
2548 | if (program !== this.program) {
|
2549 | this.program = program;
|
2550 | this.validate();
|
2551 | }
|
2552 | };
|
2553 | |
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 |
|
2561 | ProjectSymbols.prototype.getDirectiveFromNode = function (declaration, fileName) {
|
2562 | var sourceFile = this.program.getSourceFile(fileName);
|
2563 | var identifier = declaration.name;
|
2564 | if (identifier) {
|
2565 | return new DirectiveSymbol(this.program, this.reflector.getStaticSymbol(sourceFile.fileName, identifier.text), this.metadataResolver, this.directiveNormalizer, this.directiveResolver, this.reflector, this.resourceResolver, this);
|
2566 | }
|
2567 | else {
|
2568 | return null;
|
2569 | }
|
2570 | };
|
2571 |
|
2572 | ProjectSymbols.prototype.getAnalyzedModules = function () {
|
2573 | var analyzedModules = this.analyzedModules;
|
2574 | if (!analyzedModules) {
|
2575 | var analyzeHost = { isSourceFile: function (filePath) { return true; } };
|
2576 | var programSymbols = _angular_compiler.extractProgramSymbols(this.staticSymbolResolver, this.program.getSourceFiles().map(function (sf) { return sf.fileName; }), analyzeHost);
|
2577 | analyzedModules = this.analyzedModules =
|
2578 | _angular_compiler.analyzeNgModules(programSymbols, analyzeHost, this.metadataResolver);
|
2579 | }
|
2580 | return analyzedModules;
|
2581 | };
|
2582 | ProjectSymbols.prototype.extractProgramSymbols = function () {
|
2583 | return _angular_compiler.extractProgramSymbols(this.staticSymbolResolver, this.program.getSourceFiles().map(function (sf) { return sf.fileName; }), {
|
2584 | isSourceFile: function () { return true; }
|
2585 | });
|
2586 | };
|
2587 | ProjectSymbols.prototype.validate = function () {
|
2588 | var program = this.program;
|
2589 | if (this.lastProgram !== program) {
|
2590 | this.clearCaches();
|
2591 | this.lastProgram = program;
|
2592 | this.init();
|
2593 | }
|
2594 | };
|
2595 | ProjectSymbols.prototype.clearCaches = function () {
|
2596 | this.metadataResolver.clearCache();
|
2597 | this.directiveNormalizer.clearCache();
|
2598 | };
|
2599 | ProjectSymbols.prototype.init = function () {
|
2600 | var staticSymbolCache = new _angular_compiler.StaticSymbolCache();
|
2601 | var summaryResolver = new _angular_compiler.AotSummaryResolver({
|
2602 | loadSummary: function (filePath) { return ''; },
|
2603 | isSourceFile: function (sourceFilePath) { return true; },
|
2604 | getOutputFileName: function () { return ''; }
|
2605 | }, staticSymbolCache);
|
2606 | var parser = new _angular_compiler.HtmlParser();
|
2607 | var config = new _angular_compiler.CompilerConfig({
|
2608 | defaultEncapsulation: _angular_core.ViewEncapsulation.Emulated,
|
2609 | useJit: false
|
2610 | });
|
2611 | var defaultDir = this.program.getCurrentDirectory();
|
2612 | this.options.baseUrl = this.options.baseUrl || defaultDir;
|
2613 | this.options.basePath = this.options.basePath || defaultDir;
|
2614 | this.options.genDir = this.options.genDir || defaultDir;
|
2615 | this.staticResolverHost = new _angular_compilerCli.CompilerHost(this.program, this.options, new _angular_compilerCli.NodeCompilerHostContext());
|
2616 | this.staticSymbolResolver = new _angular_compiler.StaticSymbolResolver(
|
2617 |
|
2618 | this.staticResolverHost, staticSymbolCache, summaryResolver, this.errorReporter);
|
2619 | this.summaryResolver = new _angular_compiler.AotSummaryResolver({
|
2620 | loadSummary: function (filePath) { return null; },
|
2621 | isSourceFile: function (sourceFilePath) { return true; },
|
2622 | getOutputFileName: function (sourceFilePath) { return null; }
|
2623 | }, staticSymbolCache);
|
2624 | this.reflector = new _angular_compiler.StaticReflector(this.summaryResolver, this.staticSymbolResolver, [], [], this.errorReporter);
|
2625 | var ngModuleResolver = new _angular_compiler.NgModuleResolver(this.reflector);
|
2626 | this.directiveResolver = new _angular_compiler.DirectiveResolver(this.reflector);
|
2627 | this.pipeResolver = new _angular_compiler.PipeResolver(this.reflector);
|
2628 | this.urlResolver = _angular_compiler.createOfflineCompileUrlResolver();
|
2629 | this.directiveNormalizer = new _angular_compiler.DirectiveNormalizer(this.resourceResolver, this.urlResolver, parser, config);
|
2630 | this.metadataResolver = new _angular_compiler.CompileMetadataResolver(new _angular_compiler.CompilerConfig(), ngModuleResolver, this.directiveResolver, this.pipeResolver, summaryResolver, new _angular_compiler.DomElementSchemaRegistry(), this.directiveNormalizer, new _angular_core.ɵConsole(), staticSymbolCache, this.reflector);
|
2631 | };
|
2632 | return ProjectSymbols;
|
2633 | }());
|
2634 |
|
2635 | exports.ProjectSymbols = ProjectSymbols;
|
2636 | exports.ModuleSymbol = ModuleSymbol;
|
2637 | exports.ProviderSymbol = ProviderSymbol;
|
2638 | exports.DirectiveSymbol = DirectiveSymbol;
|
2639 | exports.PipeSymbol = PipeSymbol;
|
2640 | exports.Symbol = Symbol;
|
2641 |
|
2642 | Object.defineProperty(exports, '__esModule', { value: true });
|
2643 |
|
2644 | })));
|