Skip to content

Commit 7a6f802

Browse files
authored
perf: minify runtime comments, remove unnecessary attr quotes (#1557)
1 parent 2002ff6 commit 7a6f802

File tree

57 files changed

+87
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+87
-81
lines changed

packages/marko/src/runtime/components/beginComponent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ module.exports = function beginComponent(
6565

6666
if ((ownerIsRenderBoundary || ownerWillRerender) && key != null) {
6767
out.w(
68-
"<!--" +
68+
"<!" +
6969
runtimeId +
7070
"^" +
7171
componentId +
7272
" " +
7373
ownerComponentDef.id +
7474
" " +
7575
key +
76-
"-->"
76+
">"
7777
);
7878
} else {
79-
out.w("<!--" + runtimeId + "#" + componentId + "-->");
79+
out.w("<!" + runtimeId + "#" + componentId + ">");
8080
}
8181

8282
return componentDef;

packages/marko/src/runtime/components/endComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var getComponentsContext = ComponentsContext.___getComponentsContext;
55

66
module.exports = function endComponent(out, componentDef) {
77
if (componentDef.___renderBoundary) {
8-
out.w("<!--" + out.global.runtimeId + "/-->");
8+
out.w("<!" + out.global.runtimeId + "/>");
99
getComponentsContext(out).___isPreserved = componentDef.___parentPreserved;
1010
}
1111
};

packages/marko/src/runtime/html/AsyncStream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ var proto = (AsyncStream.prototype = {
573573

574574
___beginFragment: function(key, component, preserve) {
575575
if (preserve) {
576-
this.write("<!--F#" + escapeXmlString(key) + "-->");
576+
this.write("<!F#" + escapeXmlString(key) + ">");
577577
}
578578
if (this._elStack) {
579579
this._elStack.push(preserve);
@@ -585,7 +585,7 @@ var proto = (AsyncStream.prototype = {
585585
___endFragment: function() {
586586
var preserve = this._elStack.pop();
587587
if (preserve) {
588-
this.write("<!--F/-->");
588+
this.write("<!F/>");
589589
}
590590
},
591591

packages/marko/src/runtime/html/helpers/attr.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ function notEmptyAttr(name, value) {
3838
);
3939
}
4040

41-
return " " + name + singleQuote(JSON.stringify(value));
41+
return " " + name + singleQuote(JSON.stringify(value), 2);
4242
case RegExp.prototype.toString:
43-
return " " + name + doubleQuote(value.source);
43+
return " " + name + guessQuotes(value.source);
4444
}
4545
}
4646

@@ -51,23 +51,29 @@ function isEmpty(value) {
5151
return value == null || value === false;
5252
}
5353

54-
function doubleQuote(value) {
55-
return '="' + escapeDoubleQuotes(value) + '"';
54+
function doubleQuote(value, startPos) {
55+
return '="' + escapeDoubleQuotes(value, startPos) + '"';
5656
}
5757

58-
function singleQuote(value) {
59-
return "='" + escapeSingleQuotes(value) + "'";
58+
function singleQuote(value, startPos) {
59+
return "='" + escapeSingleQuotes(value, startPos) + "'";
6060
}
6161

6262
function guessQuotes(value) {
63-
if (value.length) {
64-
if (value[0] === "{") {
65-
// Assume json.
66-
return singleQuote(value);
63+
for (var i = 0, len = value.length; i < len; i++) {
64+
switch (value[i]) {
65+
case '"':
66+
return singleQuote(value, i + 1);
67+
case "'":
68+
case ">":
69+
case " ":
70+
case "\t":
71+
case "\n":
72+
case "\r":
73+
case "\f":
74+
return doubleQuote(value, i + 1);
6775
}
68-
69-
return doubleQuote(value);
7076
}
7177

72-
return "";
78+
return value && "=" + value;
7379
}

packages/marko/src/runtime/html/helpers/escape-quotes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"use strict";
22

33
exports.d = function(value) {
4-
return escapeDoubleQuotes(value + "");
4+
return escapeDoubleQuotes(value + "", 0);
55
};
66

77
exports.___escapeDoubleQuotes = escapeDoubleQuotes;
88

99
exports.___escapeSingleQuotes = escapeSingleQuotes;
1010

11-
function escapeSingleQuotes(value) {
12-
return escapeQuote(value, "'", "&#39;");
11+
function escapeSingleQuotes(value, startPos) {
12+
return escapeQuote(value, startPos, "'", "&#39;");
1313
}
1414

15-
function escapeDoubleQuotes(value) {
16-
return escapeQuote(value, '"', "&#34;");
15+
function escapeDoubleQuotes(value, startPos) {
16+
return escapeQuote(value, startPos, '"', "&#34;");
1717
}
1818

19-
function escapeQuote(str, quote, escaped) {
19+
function escapeQuote(str, startPos, quote, escaped) {
2020
var result = "";
2121
var lastPos = 0;
2222

23-
for (var i = 0, len = str.length; i < len; i++) {
23+
for (var i = startPos, len = str.length; i < len; i++) {
2424
if (str[i] === quote) {
2525
result += str.slice(lastPos, i) + escaped;
2626
lastPos = i + 1;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if (a > b) {
22
before();
33

4-
out.w("<div class=\"greeting\">Hello World</div>");
4+
out.w("<div class=greeting>Hello World</div>");
55

66
after();
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
before();
22

3-
out.w("<div class=\"greeting\">Hello World</div>");
3+
out.w("<div class=greeting>Hello World</div>");
44

55
after();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
out.w("<div class=\"greeting\">Hello World</div>")
1+
out.w("<div class=greeting>Hello World</div>")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
out.w("<div class=\"greeting\">Hello World</div>")
1+
out.w("<div class=greeting>Hello World</div>")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
out.w("<div class=\"greeting\"" +
1+
out.w("<div class=greeting" +
22
marko_attr("foo", bar) +
33
">Hello World</div>")

0 commit comments

Comments
 (0)