gofront 1.3.8 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/codegen/templ.js +22 -7
- package/src/minifier.js +6 -1
package/package.json
CHANGED
package/src/codegen/templ.js
CHANGED
|
@@ -92,21 +92,36 @@ export const templGenMethods = {
|
|
|
92
92
|
_genTemplElement(node, p) {
|
|
93
93
|
const { tag, attrs, children } = node;
|
|
94
94
|
const elVar = this._freshVar("e");
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
95
|
+
// <svg> and its descendants must be created in the SVG namespace.
|
|
96
|
+
const isSvg = tag === "svg" || this._templSvgDepth > 0;
|
|
97
|
+
if (isSvg) {
|
|
98
|
+
this.line(
|
|
99
|
+
`const ${elVar} = document.createElementNS("http://www.w3.org/2000/svg", ${JSON.stringify(tag)});`,
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
this.line(
|
|
103
|
+
`const ${elVar} = document.createElement(${JSON.stringify(tag)});`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
this._templSvgDepth = (this._templSvgDepth || 0) + (isSvg ? 1 : 0);
|
|
98
107
|
for (const attr of attrs) {
|
|
99
|
-
this._genTemplAttr(attr, elVar);
|
|
108
|
+
this._genTemplAttr(attr, elVar, isSvg);
|
|
100
109
|
}
|
|
101
110
|
this._genTemplNodes(children, elVar);
|
|
111
|
+
if (isSvg) this._templSvgDepth--;
|
|
102
112
|
this.line(`${p}.appendChild(${elVar});`);
|
|
103
113
|
},
|
|
104
114
|
|
|
105
|
-
_genTemplAttr(attr, el) {
|
|
115
|
+
_genTemplAttr(attr, el, isSvg) {
|
|
106
116
|
const { name } = attr;
|
|
117
|
+
// SVGElement.className is a read-only SVGAnimatedString.
|
|
118
|
+
const setClass = (js) =>
|
|
119
|
+
isSvg
|
|
120
|
+
? `${el}.setAttribute("class", ${js});`
|
|
121
|
+
: `${el}.className = ${js};`;
|
|
107
122
|
if (attr.kind === "static") {
|
|
108
123
|
if (name === "class") {
|
|
109
|
-
this.line(
|
|
124
|
+
this.line(setClass(JSON.stringify(attr.value)));
|
|
110
125
|
} else {
|
|
111
126
|
this.line(
|
|
112
127
|
`${el}.setAttribute(${JSON.stringify(name)}, ${JSON.stringify(attr.value)});`,
|
|
@@ -115,7 +130,7 @@ export const templGenMethods = {
|
|
|
115
130
|
} else if (attr.kind === "expr") {
|
|
116
131
|
const exprJs = this._genTemplTokenExpr(attr.tokens);
|
|
117
132
|
if (name === "class") {
|
|
118
|
-
this.line(
|
|
133
|
+
this.line(setClass(exprJs));
|
|
119
134
|
} else {
|
|
120
135
|
this.line(
|
|
121
136
|
`${el}.setAttribute(${JSON.stringify(name)}, String(${exprJs}));`,
|
package/src/minifier.js
CHANGED
|
@@ -117,10 +117,14 @@ const REGEX_CONTEXT_VALUES = new Set([
|
|
|
117
117
|
"||",
|
|
118
118
|
]);
|
|
119
119
|
|
|
120
|
+
// Ops after which `/` is division, not a regex start
|
|
121
|
+
const DIVISION_AFTER_OPS = new Set([")", "]", "++", "--"]);
|
|
122
|
+
|
|
120
123
|
function _isRegexContext(tokens) {
|
|
121
124
|
const prev = lastNonWhitespaceToken(tokens);
|
|
122
125
|
if (!prev) return true;
|
|
123
|
-
|
|
126
|
+
if (prev.type === "op") return !DIVISION_AFTER_OPS.has(prev.value);
|
|
127
|
+
return REGEX_CONTEXT_VALUES.has(prev.value);
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
function _scanRegexLiteral(code, i, len) {
|
|
@@ -129,6 +133,7 @@ function _scanRegexLiteral(code, i, len) {
|
|
|
129
133
|
let inCharClass = false;
|
|
130
134
|
while (j < len) {
|
|
131
135
|
const rc = code[j];
|
|
136
|
+
if (rc === "\n") break;
|
|
132
137
|
if (escaped) {
|
|
133
138
|
escaped = false;
|
|
134
139
|
} else if (rc === "\\") {
|