source: trip-planner-front/node_modules/@angular/compiler/esm2015/src/template_parser/template_preparser.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { isNgContent } from '../ml_parser/tags';
9const NG_CONTENT_SELECT_ATTR = 'select';
10const LINK_ELEMENT = 'link';
11const LINK_STYLE_REL_ATTR = 'rel';
12const LINK_STYLE_HREF_ATTR = 'href';
13const LINK_STYLE_REL_VALUE = 'stylesheet';
14const STYLE_ELEMENT = 'style';
15const SCRIPT_ELEMENT = 'script';
16const NG_NON_BINDABLE_ATTR = 'ngNonBindable';
17const NG_PROJECT_AS = 'ngProjectAs';
18export function preparseElement(ast) {
19 let selectAttr = null;
20 let hrefAttr = null;
21 let relAttr = null;
22 let nonBindable = false;
23 let projectAs = '';
24 ast.attrs.forEach(attr => {
25 const lcAttrName = attr.name.toLowerCase();
26 if (lcAttrName == NG_CONTENT_SELECT_ATTR) {
27 selectAttr = attr.value;
28 }
29 else if (lcAttrName == LINK_STYLE_HREF_ATTR) {
30 hrefAttr = attr.value;
31 }
32 else if (lcAttrName == LINK_STYLE_REL_ATTR) {
33 relAttr = attr.value;
34 }
35 else if (attr.name == NG_NON_BINDABLE_ATTR) {
36 nonBindable = true;
37 }
38 else if (attr.name == NG_PROJECT_AS) {
39 if (attr.value.length > 0) {
40 projectAs = attr.value;
41 }
42 }
43 });
44 selectAttr = normalizeNgContentSelect(selectAttr);
45 const nodeName = ast.name.toLowerCase();
46 let type = PreparsedElementType.OTHER;
47 if (isNgContent(nodeName)) {
48 type = PreparsedElementType.NG_CONTENT;
49 }
50 else if (nodeName == STYLE_ELEMENT) {
51 type = PreparsedElementType.STYLE;
52 }
53 else if (nodeName == SCRIPT_ELEMENT) {
54 type = PreparsedElementType.SCRIPT;
55 }
56 else if (nodeName == LINK_ELEMENT && relAttr == LINK_STYLE_REL_VALUE) {
57 type = PreparsedElementType.STYLESHEET;
58 }
59 return new PreparsedElement(type, selectAttr, hrefAttr, nonBindable, projectAs);
60}
61export var PreparsedElementType;
62(function (PreparsedElementType) {
63 PreparsedElementType[PreparsedElementType["NG_CONTENT"] = 0] = "NG_CONTENT";
64 PreparsedElementType[PreparsedElementType["STYLE"] = 1] = "STYLE";
65 PreparsedElementType[PreparsedElementType["STYLESHEET"] = 2] = "STYLESHEET";
66 PreparsedElementType[PreparsedElementType["SCRIPT"] = 3] = "SCRIPT";
67 PreparsedElementType[PreparsedElementType["OTHER"] = 4] = "OTHER";
68})(PreparsedElementType || (PreparsedElementType = {}));
69export class PreparsedElement {
70 constructor(type, selectAttr, hrefAttr, nonBindable, projectAs) {
71 this.type = type;
72 this.selectAttr = selectAttr;
73 this.hrefAttr = hrefAttr;
74 this.nonBindable = nonBindable;
75 this.projectAs = projectAs;
76 }
77}
78function normalizeNgContentSelect(selectAttr) {
79 if (selectAttr === null || selectAttr.length === 0) {
80 return '*';
81 }
82 return selectAttr;
83}
84//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVtcGxhdGVfcHJlcGFyc2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29tcGlsZXIvc3JjL3RlbXBsYXRlX3BhcnNlci90ZW1wbGF0ZV9wcmVwYXJzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBR0gsT0FBTyxFQUFDLFdBQVcsRUFBQyxNQUFNLG1CQUFtQixDQUFDO0FBRTlDLE1BQU0sc0JBQXNCLEdBQUcsUUFBUSxDQUFDO0FBQ3hDLE1BQU0sWUFBWSxHQUFHLE1BQU0sQ0FBQztBQUM1QixNQUFNLG1CQUFtQixHQUFHLEtBQUssQ0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G4gIHJldHVybiBuZXcgUHJlcGFyc2VkRWxlbWVudCh0eXBlLCBzZWxlY3RBdHRyLCBocmVmQXR0ciwgbm9uQmluZGFibGUsIHByb2plY3RBcyk7XG59XG5cbmV4cG9ydCBlbnVtIFByZXBhcnNlZEVsZW1lbnRUeXBlIHtcbiAgTkdfQ09OVEVOVCxcbiAgU1RZTEUsXG4gIFNUWUxFU0hFRVQsXG4gIFNDUklQVCxcbiAgT1RIRVJcbn1cblxuZXhwb3J0IGNsYXNzIFByZXBhcnNlZEVsZW1lbnQge1xuICBjb25zdHJ1Y3RvcihcbiAgICAgIHB1YmxpYyB0eXBlOiBQcmVwYXJzZWRFbGVtZW50VHlwZSwgcHVibGljIHNlbGVjdEF0dHI6IHN0cmluZywgcHVibGljIGhyZWZBdHRyOiBzdHJpbmcsXG4gICAgICBwdWJsaWMgbm9uQmluZGFibGU6IGJvb2xlYW4sIHB1YmxpYyBwcm9qZWN0QXM6IHN0cmluZykge31cbn1cblxuXG5mdW5jdGlvbiBub3JtYWxpemVOZ0NvbnRlbnRTZWxlY3Qoc2VsZWN0QXR0cjogc3RyaW5nKTogc3RyaW5nIHtcbiAgaWYgKHNlbGVjdEF0dHIgPT09IG51bGwgfHwgc2VsZWN0QXR0ci5sZW5ndGggPT09IDApIHtcbiAgICByZXR1cm4gJyonO1xuICB9XG4gIHJldHVybiBzZWxlY3RBdHRyO1xufVxuIl19
Note: See TracBrowser for help on using the repository browser.