Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = cleanJSXElementLiteralChild;
|
---|
7 |
|
---|
8 | var _generated = require("../../builders/generated");
|
---|
9 |
|
---|
10 | function cleanJSXElementLiteralChild(child, args) {
|
---|
11 | const lines = child.value.split(/\r\n|\n|\r/);
|
---|
12 | let lastNonEmptyLine = 0;
|
---|
13 |
|
---|
14 | for (let i = 0; i < lines.length; i++) {
|
---|
15 | if (lines[i].match(/[^ \t]/)) {
|
---|
16 | lastNonEmptyLine = i;
|
---|
17 | }
|
---|
18 | }
|
---|
19 |
|
---|
20 | let str = "";
|
---|
21 |
|
---|
22 | for (let i = 0; i < lines.length; i++) {
|
---|
23 | const line = lines[i];
|
---|
24 | const isFirstLine = i === 0;
|
---|
25 | const isLastLine = i === lines.length - 1;
|
---|
26 | const isLastNonEmptyLine = i === lastNonEmptyLine;
|
---|
27 | let trimmedLine = line.replace(/\t/g, " ");
|
---|
28 |
|
---|
29 | if (!isFirstLine) {
|
---|
30 | trimmedLine = trimmedLine.replace(/^[ ]+/, "");
|
---|
31 | }
|
---|
32 |
|
---|
33 | if (!isLastLine) {
|
---|
34 | trimmedLine = trimmedLine.replace(/[ ]+$/, "");
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (trimmedLine) {
|
---|
38 | if (!isLastNonEmptyLine) {
|
---|
39 | trimmedLine += " ";
|
---|
40 | }
|
---|
41 |
|
---|
42 | str += trimmedLine;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | if (str) args.push((0, _generated.stringLiteral)(str));
|
---|
47 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.