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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gofront",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "author": "Luuk van Venrooij",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -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
- this.line(
96
- `const ${elVar} = document.createElement(${JSON.stringify(tag)});`,
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(`${el}.className = ${JSON.stringify(attr.value)};`);
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(`${el}.className = ${exprJs};`);
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
- return prev.type === "op" || REGEX_CONTEXT_VALUES.has(prev.value);
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 === "\\") {