@reckona/mreact-compiler 0.0.132 → 0.0.135
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/dist/emit-client.js +6 -1
- package/dist/emit-client.js.map +1 -1
- package/dist/emit-server-shared.d.ts +1 -0
- package/dist/emit-server-shared.d.ts.map +1 -1
- package/dist/emit-server-shared.js +11 -0
- package/dist/emit-server-shared.js.map +1 -1
- package/dist/emit-server-stream.d.ts.map +1 -1
- package/dist/emit-server-stream.js +18 -6
- package/dist/emit-server-stream.js.map +1 -1
- package/dist/emit-server.d.ts.map +1 -1
- package/dist/emit-server.js +18 -6
- package/dist/emit-server.js.map +1 -1
- package/package.json +2 -2
- package/src/emit-client.ts +6 -1
- package/src/emit-server-shared.ts +15 -0
- package/src/emit-server-stream.ts +19 -5
- package/src/emit-server.ts +19 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-server.d.ts","sourceRoot":"","sources":["../src/emit-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwD,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"emit-server.d.ts","sourceRoot":"","sources":["../src/emit-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwD,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAoBrE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AASD,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CA6GpF"}
|
package/dist/emit-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { emitEscapeHtmlHelper } from "./emit-escape-helper.js";
|
|
2
2
|
import { createCodeBuilder } from "./emit-code-builder.js";
|
|
3
3
|
import { escapeHtmlAttribute as escapeHtml } from "@reckona/mreact-shared/html-escape";
|
|
4
|
-
import { htmlAttributeName, isDangerousHtmlAttribute, isStaticUrlValueUnsafe, isUrlAttribute, isVoidHtmlElement, parseStaticStyleObjectLiteral, parseStyleLiteralValue, simpleSideEffectFreeExpression, } from "./emit-server-shared.js";
|
|
4
|
+
import { htmlAttributeName, isBooleanishStringAttribute, isDangerousHtmlAttribute, isStaticUrlValueUnsafe, isUrlAttribute, isVoidHtmlElement, parseStaticStyleObjectLiteral, parseStyleLiteralValue, simpleSideEffectFreeExpression, } from "./emit-server-shared.js";
|
|
5
5
|
import { emitOxcCompatObjectChildren, oxcServerStringReactNodeRenderHelperPlaceholder, } from "./oxc-runtime-emit.js";
|
|
6
6
|
// Module-local handle to the URL-safety helper name for the current emit
|
|
7
7
|
// call. Used by deeply-nested attribute emitters to avoid threading the
|
|
@@ -597,6 +597,7 @@ function readFormValueAttributeCode(attr) {
|
|
|
597
597
|
return attr.kind === "static-attr" ? stringLiteral(attr.value) : `(${attr.code})`;
|
|
598
598
|
}
|
|
599
599
|
function emitDynamicAttributeExpression(name, code, escapeHelperName) {
|
|
600
|
+
const booleanishString = isBooleanishStringAttribute(name);
|
|
600
601
|
if (isUrlAttribute(name)) {
|
|
601
602
|
// Run the value through the inline URL safety helper. The helper
|
|
602
603
|
// returns the value when safe and `undefined` when the attribute
|
|
@@ -610,9 +611,13 @@ function emitDynamicAttributeExpression(name, code, escapeHelperName) {
|
|
|
610
611
|
// Safe because `simpleSideEffectFreeExpression` only matches expressions
|
|
611
612
|
// whose evaluation has no observable side effects (identifier read,
|
|
612
613
|
// member chain, literal, this).
|
|
613
|
-
return
|
|
614
|
+
return booleanishString
|
|
615
|
+
? `(${inlineExpr} == null ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(${inlineExpr}) + ${stringLiteral('"')})`
|
|
616
|
+
: `(${inlineExpr} == null || ${inlineExpr} === false ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(${inlineExpr} === true ? "" : ${inlineExpr}) + ${stringLiteral('"')})`;
|
|
614
617
|
}
|
|
615
|
-
return
|
|
618
|
+
return booleanishString
|
|
619
|
+
? `(() => { const _value = (${code}); return _value == null ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(_value) + ${stringLiteral('"')}; })()`
|
|
620
|
+
: `(() => { const _value = (${code}); return _value == null || _value === false ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(_value === true ? "" : _value) + ${stringLiteral('"')}; })()`;
|
|
616
621
|
}
|
|
617
622
|
function emitDynamicStyleAttributeExpression(code, escapeHelperName, escapeBatchHelperName) {
|
|
618
623
|
const staticStyleExpression = emitStaticStyleObjectAttributeExpression(code, escapeHelperName);
|
|
@@ -893,7 +898,12 @@ function emitClientBoundaryHelper(name) {
|
|
|
893
898
|
` const _props = props ?? {};`,
|
|
894
899
|
` const _nonSerializable = ${propsHelperName}(_props);`,
|
|
895
900
|
` const _nonSerializableAttr = _nonSerializable ? ' data-mreact-client-boundary-nonserializable="true"' : "";`,
|
|
896
|
-
` const _json = (JSON.stringify(_props) ?? "{}")
|
|
901
|
+
` const _json = (JSON.stringify(_props) ?? "{}")`,
|
|
902
|
+
` .replaceAll("&", "\\\\u0026")`,
|
|
903
|
+
` .replaceAll("<", "\\\\u003c")`,
|
|
904
|
+
` .replaceAll(">", "\\\\u003e")`,
|
|
905
|
+
` .replaceAll("\\u2028", "\\\\u2028")`,
|
|
906
|
+
` .replaceAll("\\u2029", "\\\\u2029");`,
|
|
897
907
|
` return \`<template data-mreact-client-boundary="\${_escapedName}"\${_nonSerializableAttr}></template>\${childrenHtml}<script type="application/json" data-mreact-client-boundary-props="\${_escapedName}">\${_json}</script>\`;`,
|
|
898
908
|
`}`,
|
|
899
909
|
].join("\n");
|
|
@@ -958,11 +968,13 @@ function emitSpreadAttributesHelper(name, escapeHelperName, urlSafeHelperName) {
|
|
|
958
968
|
` let _out = "";`,
|
|
959
969
|
` for (const _rawName of Object.keys(props)) {`,
|
|
960
970
|
` let _value = props[_rawName];`,
|
|
961
|
-
` if (_value == null
|
|
971
|
+
` if (_value == null) continue;`,
|
|
962
972
|
` if (_rawName === "key" || _rawName === "ref" || _rawName === "children") continue;`,
|
|
963
973
|
` if (/^on[A-Za-z]/.test(_rawName)) continue;`,
|
|
964
974
|
` let _name = tagName === "input" && _rawName === "defaultValue" ? "value" : tagName === "input" && _rawName === "defaultChecked" ? "checked" : (${name}$aliases[_rawName] ?? _rawName);`,
|
|
965
975
|
` if (!/^[A-Za-z_:][A-Za-z0-9:_.-]*$/.test(_name)) continue;`,
|
|
976
|
+
` const _booleanish = _name.startsWith("aria-") || _name.startsWith("data-") || _name === "contenteditable" || _name === "draggable" || _name === "spellcheck";`,
|
|
977
|
+
` if (_value === false && !_booleanish) continue;`,
|
|
966
978
|
` if (_name === "style") {`,
|
|
967
979
|
` const _style = ${name}$style(_value);`,
|
|
968
980
|
` if (_style !== "") _out += " style=\\"" + ${escapeHelperName}(_style) + "\\"";`,
|
|
@@ -978,7 +990,7 @@ function emitSpreadAttributesHelper(name, escapeHelperName, urlSafeHelperName) {
|
|
|
978
990
|
` _value = ${urlSafeHelperName}(_name, _value === true ? "" : _value);`,
|
|
979
991
|
` if (_value === undefined) continue;`,
|
|
980
992
|
` }`,
|
|
981
|
-
` _out += " " + _name + "=\\"" + ${escapeHelperName}(_value === true ? "" : _value) + "\\"";`,
|
|
993
|
+
` _out += " " + _name + "=\\"" + ${escapeHelperName}(_value === true && !_booleanish ? "" : _value) + "\\"";`,
|
|
982
994
|
` }`,
|
|
983
995
|
` return _out;`,
|
|
984
996
|
`}`,
|