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 | */
|
---|
8 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/compiler/src/ml_parser/html_whitespaces", ["require", "exports", "@angular/compiler/src/ml_parser/ast", "@angular/compiler/src/ml_parser/entities", "@angular/compiler/src/ml_parser/parser"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.removeWhitespaces = exports.WhitespaceVisitor = exports.replaceNgsp = exports.PRESERVE_WS_ATTR_NAME = void 0;
|
---|
20 | var html = require("@angular/compiler/src/ml_parser/ast");
|
---|
21 | var entities_1 = require("@angular/compiler/src/ml_parser/entities");
|
---|
22 | var parser_1 = require("@angular/compiler/src/ml_parser/parser");
|
---|
23 | exports.PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
|
---|
24 | var SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
|
---|
25 | // Equivalent to \s with \u00a0 (non-breaking space) excluded.
|
---|
26 | // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
|
---|
27 | var WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
|
---|
28 | var NO_WS_REGEXP = new RegExp("[^" + WS_CHARS + "]");
|
---|
29 | var WS_REPLACE_REGEXP = new RegExp("[" + WS_CHARS + "]{2,}", 'g');
|
---|
30 | function hasPreserveWhitespacesAttr(attrs) {
|
---|
31 | return attrs.some(function (attr) { return attr.name === exports.PRESERVE_WS_ATTR_NAME; });
|
---|
32 | }
|
---|
33 | /**
|
---|
34 | * Angular Dart introduced &ngsp; as a placeholder for non-removable space, see:
|
---|
35 | * https://github.com/dart-lang/angular/blob/0bb611387d29d65b5af7f9d2515ab571fd3fbee4/_tests/test/compiler/preserve_whitespace_test.dart#L25-L32
|
---|
36 | * In Angular Dart &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
|
---|
37 | * and later on replaced by a space. We are re-implementing the same idea here.
|
---|
38 | */
|
---|
39 | function replaceNgsp(value) {
|
---|
40 | // lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
|
---|
41 | return value.replace(new RegExp(entities_1.NGSP_UNICODE, 'g'), ' ');
|
---|
42 | }
|
---|
43 | exports.replaceNgsp = replaceNgsp;
|
---|
44 | /**
|
---|
45 | * This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
|
---|
46 | * - consider spaces, tabs and new lines as whitespace characters;
|
---|
47 | * - drop text nodes consisting of whitespace characters only;
|
---|
48 | * - for all other text nodes replace consecutive whitespace characters with one space;
|
---|
49 | * - convert &ngsp; pseudo-entity to a single space;
|
---|
50 | *
|
---|
51 | * Removal and trimming of whitespaces have positive performance impact (less code to generate
|
---|
52 | * while compiling templates, faster view creation). At the same time it can be "destructive"
|
---|
53 | * in some cases (whitespaces can influence layout). Because of the potential of breaking layout
|
---|
54 | * this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
|
---|
55 | * whitespace removal. The default option for whitespace removal will be revisited in Angular 6
|
---|
56 | * and might be changed to "on" by default.
|
---|
57 | */
|
---|
58 | var WhitespaceVisitor = /** @class */ (function () {
|
---|
59 | function WhitespaceVisitor() {
|
---|
60 | }
|
---|
61 | WhitespaceVisitor.prototype.visitElement = function (element, context) {
|
---|
62 | if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
|
---|
63 | // don't descent into elements where we need to preserve whitespaces
|
---|
64 | // but still visit all attributes to eliminate one used as a market to preserve WS
|
---|
65 | return new html.Element(element.name, html.visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
---|
66 | }
|
---|
67 | return new html.Element(element.name, element.attrs, visitAllWithSiblings(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
---|
68 | };
|
---|
69 | WhitespaceVisitor.prototype.visitAttribute = function (attribute, context) {
|
---|
70 | return attribute.name !== exports.PRESERVE_WS_ATTR_NAME ? attribute : null;
|
---|
71 | };
|
---|
72 | WhitespaceVisitor.prototype.visitText = function (text, context) {
|
---|
73 | var isNotBlank = text.value.match(NO_WS_REGEXP);
|
---|
74 | var hasExpansionSibling = context &&
|
---|
75 | (context.prev instanceof html.Expansion || context.next instanceof html.Expansion);
|
---|
76 | if (isNotBlank || hasExpansionSibling) {
|
---|
77 | // Process the whitespace in the tokens of this Text node
|
---|
78 | var tokens = text.tokens.map(function (token) {
|
---|
79 | return token.type === 5 /* TEXT */ ? createWhitespaceProcessedTextToken(token) : token;
|
---|
80 | });
|
---|
81 | // Process the whitespace of the value of this Text node
|
---|
82 | var value = processWhitespace(text.value);
|
---|
83 | return new html.Text(value, text.sourceSpan, tokens, text.i18n);
|
---|
84 | }
|
---|
85 | return null;
|
---|
86 | };
|
---|
87 | WhitespaceVisitor.prototype.visitComment = function (comment, context) {
|
---|
88 | return comment;
|
---|
89 | };
|
---|
90 | WhitespaceVisitor.prototype.visitExpansion = function (expansion, context) {
|
---|
91 | return expansion;
|
---|
92 | };
|
---|
93 | WhitespaceVisitor.prototype.visitExpansionCase = function (expansionCase, context) {
|
---|
94 | return expansionCase;
|
---|
95 | };
|
---|
96 | return WhitespaceVisitor;
|
---|
97 | }());
|
---|
98 | exports.WhitespaceVisitor = WhitespaceVisitor;
|
---|
99 | function createWhitespaceProcessedTextToken(_a) {
|
---|
100 | var type = _a.type, parts = _a.parts, sourceSpan = _a.sourceSpan;
|
---|
101 | return { type: type, parts: [processWhitespace(parts[0])], sourceSpan: sourceSpan };
|
---|
102 | }
|
---|
103 | function processWhitespace(text) {
|
---|
104 | return replaceNgsp(text).replace(WS_REPLACE_REGEXP, ' ');
|
---|
105 | }
|
---|
106 | function removeWhitespaces(htmlAstWithErrors) {
|
---|
107 | return new parser_1.ParseTreeResult(html.visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
|
---|
108 | }
|
---|
109 | exports.removeWhitespaces = removeWhitespaces;
|
---|
110 | function visitAllWithSiblings(visitor, nodes) {
|
---|
111 | var result = [];
|
---|
112 | nodes.forEach(function (ast, i) {
|
---|
113 | var context = { prev: nodes[i - 1], next: nodes[i + 1] };
|
---|
114 | var astResult = ast.visit(visitor, context);
|
---|
115 | if (astResult) {
|
---|
116 | result.push(astResult);
|
---|
117 | }
|
---|
118 | });
|
---|
119 | return result;
|
---|
120 | }
|
---|
121 | });
|
---|
122 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaHRtbF93aGl0ZXNwYWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9tbF9wYXJzZXIvaHRtbF93aGl0ZXNwYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7SUFFSCwwREFBOEI7SUFDOUIscUVBQXdDO0lBQ3hDLGlFQUF5QztJQUc1QixRQUFBLHFCQUFxQixHQUFHLHVCQUF1QixDQUFDO0lBRTdELElBQU0saUJBQWlCLEdBQUcsSUFBSSxHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxRQUFRLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQztJQUV0Riw4REFBOEQ7SUFD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