@kdujs/compiler-ssr-canary
Advanced tools
Comparing version 3.20241209.0-minor.0 to 3.20241209.0
@@ -0,1 +1,6 @@ | ||
/** | ||
* @kdujs/compiler-ssr-canary v3.20241209.0 | ||
* (c) 2021-present NKDuy | ||
* @license MIT | ||
**/ | ||
'use strict'; | ||
@@ -54,3 +59,3 @@ | ||
); | ||
function ssrProcessIf(node, context, disableNestedFragments = false) { | ||
function ssrProcessIf(node, context, disableNestedFragments = false, disableCommentAsIfAlternate = false) { | ||
const [rootBranch] = node.branches; | ||
@@ -79,3 +84,3 @@ const ifStatement = compilerDom.createIfStatement( | ||
} | ||
if (!currentIf.alternate) { | ||
if (!currentIf.alternate && !disableCommentAsIfAlternate) { | ||
currentIf.alternate = compilerDom.createBlockStatement([ | ||
@@ -137,9 +142,16 @@ compilerDom.createCallExpression(`_push`, ["`<!---->`"]) | ||
let method = SSR_RENDER_SLOT; | ||
const parent = context.parent; | ||
if (parent && parent.type === 1 && parent.tagType === 1 && compilerDom.resolveComponentType(parent, context, true) === compilerDom.TRANSITION && parent.children.filter((c) => c.type === 1).length === 1) { | ||
method = SSR_RENDER_SLOT_INNER; | ||
if (!(context.scopeId && context.slotted !== false)) { | ||
args.push("null"); | ||
let parent = context.parent; | ||
if (parent) { | ||
const children = parent.children; | ||
if (parent.type === 10) { | ||
parent = context.grandParent; | ||
} | ||
args.push("true"); | ||
let componentType; | ||
if (parent.type === 1 && parent.tagType === 1 && ((componentType = compilerDom.resolveComponentType(parent, context, true)) === compilerDom.TRANSITION || componentType === compilerDom.TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) { | ||
method = SSR_RENDER_SLOT_INNER; | ||
if (!(context.scopeId && context.slotted !== false)) { | ||
args.push("null"); | ||
} | ||
args.push("true"); | ||
} | ||
} | ||
@@ -225,3 +237,3 @@ node.ssrCodegenNode = compilerDom.createCallExpression(context.helper(method), args); | ||
const wipMap$2 = /* @__PURE__ */ new WeakMap(); | ||
const wipMap$3 = /* @__PURE__ */ new WeakMap(); | ||
function ssrTransformSuspense(node, context) { | ||
@@ -235,20 +247,24 @@ return () => { | ||
}; | ||
wipMap$2.set(node, wipEntry); | ||
wipEntry.slotsExp = compilerDom.buildSlots(node, context, (_props, children, loc) => { | ||
const fn = compilerDom.createFunctionExpression( | ||
[], | ||
void 0, | ||
// no return, assign body later | ||
true, | ||
// newline | ||
false, | ||
// suspense slots are not treated as normal slots | ||
loc | ||
); | ||
wipEntry.wipSlots.push({ | ||
fn, | ||
children | ||
}); | ||
return fn; | ||
}).slots; | ||
wipMap$3.set(node, wipEntry); | ||
wipEntry.slotsExp = compilerDom.buildSlots( | ||
node, | ||
context, | ||
(_props, _kForExp, children, loc) => { | ||
const fn = compilerDom.createFunctionExpression( | ||
[], | ||
void 0, | ||
// no return, assign body later | ||
true, | ||
// newline | ||
false, | ||
// suspense slots are not treated as normal slots | ||
loc | ||
); | ||
wipEntry.wipSlots.push({ | ||
fn, | ||
children | ||
}); | ||
return fn; | ||
} | ||
).slots; | ||
} | ||
@@ -258,3 +274,3 @@ }; | ||
function ssrProcessSuspense(node, context) { | ||
const wipEntry = wipMap$2.get(node); | ||
const wipEntry = wipMap$3.get(node); | ||
if (!wipEntry) { | ||
@@ -297,3 +313,2 @@ return; | ||
true | ||
/* ssr */ | ||
); | ||
@@ -371,3 +386,6 @@ if (props || directives.length) { | ||
if (prop.name === "html" && prop.exp) { | ||
rawChildrenMap.set(node, prop.exp); | ||
rawChildrenMap.set( | ||
node, | ||
compilerDom.createCompoundExpression([`(`, prop.exp, `) ?? ''`]) | ||
); | ||
} else if (prop.name === "text" && prop.exp) { | ||
@@ -435,3 +453,2 @@ node.children = [compilerDom.createInterpolation(prop.exp, prop.loc)]; | ||
false | ||
/* no newline */ | ||
) | ||
@@ -471,9 +488,10 @@ ); | ||
} else { | ||
if (node.tag === "textarea" && prop.name === "value" && prop.value) { | ||
const name = prop.name; | ||
if (node.tag === "textarea" && name === "value" && prop.value) { | ||
rawChildrenMap.set(node, shared.escapeHtml(prop.value.content)); | ||
} else if (!needMergeProps) { | ||
if (prop.name === "key" || prop.name === "ref") { | ||
if (name === "key" || name === "ref") { | ||
continue; | ||
} | ||
if (prop.name === "class" && prop.value) { | ||
if (name === "class" && prop.value) { | ||
staticClassBinding = JSON.stringify(prop.value.content); | ||
@@ -569,3 +587,3 @@ } | ||
const wipMap$1 = /* @__PURE__ */ new WeakMap(); | ||
const wipMap$2 = /* @__PURE__ */ new WeakMap(); | ||
function ssrTransformTransitionGroup(node, context) { | ||
@@ -583,3 +601,2 @@ return () => { | ||
true | ||
/* ssr (skip event listeners) */ | ||
); | ||
@@ -592,5 +609,6 @@ let propsExp = null; | ||
} | ||
wipMap$1.set(node, { | ||
wipMap$2.set(node, { | ||
tag, | ||
propsExp | ||
propsExp, | ||
scopeId: context.scopeId || null | ||
}); | ||
@@ -601,5 +619,5 @@ } | ||
function ssrProcessTransitionGroup(node, context) { | ||
const entry = wipMap$1.get(node); | ||
const entry = wipMap$2.get(node); | ||
if (entry) { | ||
const { tag, propsExp } = entry; | ||
const { tag, propsExp, scopeId } = entry; | ||
if (tag.type === 7) { | ||
@@ -611,2 +629,5 @@ context.pushStringPart(`<`); | ||
} | ||
if (scopeId) { | ||
context.pushStringPart(` ${scopeId}`); | ||
} | ||
context.pushStringPart(`>`); | ||
@@ -623,2 +644,9 @@ processChildren( | ||
*/ | ||
true, | ||
/** | ||
* TransitionGroup filters out comment children at runtime and thus | ||
* doesn't expect comments to be present during hydration. We need to | ||
* account for that by disabling the empty comment that is otherwise | ||
* rendered for a falsy k-if that has no k-else specified. (#6715) | ||
*/ | ||
true | ||
@@ -634,2 +662,5 @@ ); | ||
} | ||
if (scopeId) { | ||
context.pushStringPart(` ${scopeId}`); | ||
} | ||
context.pushStringPart(`>`); | ||
@@ -640,6 +671,25 @@ processChildren(node, context, false, true); | ||
} else { | ||
processChildren(node, context, true, true); | ||
processChildren(node, context, true, true, true); | ||
} | ||
} | ||
const wipMap$1 = /* @__PURE__ */ new WeakMap(); | ||
function ssrTransformTransition(node, context) { | ||
return () => { | ||
const appear = compilerDom.findProp(node, "appear", false, true); | ||
wipMap$1.set(node, !!appear); | ||
}; | ||
} | ||
function ssrProcessTransition(node, context) { | ||
node.children = node.children.filter((c) => c.type !== 3); | ||
const appear = wipMap$1.get(node); | ||
if (appear) { | ||
context.pushStringPart(`<template>`); | ||
processChildren(node, context, false, true); | ||
context.pushStringPart(`</template>`); | ||
} else { | ||
processChildren(node, context, false, true); | ||
} | ||
} | ||
const wipMap = /* @__PURE__ */ new WeakMap(); | ||
@@ -663,5 +713,6 @@ const WIP_SLOT = Symbol(); | ||
return ssrTransformSuspense(node, context); | ||
} | ||
if (component === compilerDom.TRANSITION_GROUP) { | ||
} else if (component === compilerDom.TRANSITION_GROUP) { | ||
return ssrTransformTransitionGroup(node, context); | ||
} else if (component === compilerDom.TRANSITION) { | ||
return ssrTransformTransition(node); | ||
} | ||
@@ -674,4 +725,6 @@ return; | ||
if (clonedNode.children.length) { | ||
compilerDom.buildSlots(clonedNode, context, (props, children) => { | ||
knodeBranches.push(createKNodeSlotBranch(props, children, context)); | ||
compilerDom.buildSlots(clonedNode, context, (props, kFor, children) => { | ||
knodeBranches.push( | ||
createKNodeSlotBranch(props, kFor, children, context) | ||
); | ||
return compilerDom.createFunctionExpression(void 0); | ||
@@ -695,3 +748,3 @@ }); | ||
wipMap.set(node, wipEntries); | ||
const buildSSRSlotFn = (props, children, loc) => { | ||
const buildSSRSlotFn = (props, _kForExp, children, loc) => { | ||
const param0 = props && compilerDom.stringifyExpression(props) || `_`; | ||
@@ -753,3 +806,3 @@ const fn = compilerDom.createFunctionExpression( | ||
if (component === compilerDom.TRANSITION) { | ||
node.children = node.children.filter((c) => c.type !== 3); | ||
return ssrProcessTransition(node, context); | ||
} | ||
@@ -769,3 +822,2 @@ processChildren(node, context); | ||
true | ||
/* withSlotScopeId */ | ||
), | ||
@@ -794,3 +846,3 @@ knodeBranch | ||
}; | ||
function createKNodeSlotBranch(props, children, parentContext) { | ||
function createKNodeSlotBranch(slotProps, kFor, children, parentContext) { | ||
const rawOptions = rawOptionsMap.get(parentContext.root); | ||
@@ -809,2 +861,16 @@ const subOptions = { | ||
}; | ||
const wrapperProps = []; | ||
if (slotProps) { | ||
wrapperProps.push({ | ||
type: 7, | ||
name: "slot", | ||
exp: slotProps, | ||
arg: void 0, | ||
modifiers: [], | ||
loc: compilerDom.locStub | ||
}); | ||
} | ||
if (kFor) { | ||
wrapperProps.push(shared.extend({}, kFor)); | ||
} | ||
const wrapperNode = { | ||
@@ -815,15 +881,3 @@ type: 1, | ||
tagType: 3, | ||
isSelfClosing: false, | ||
// important: provide k-slot="props" on the wrapper for proper | ||
// scope analysis | ||
props: [ | ||
{ | ||
type: 7, | ||
name: "slot", | ||
exp: props, | ||
arg: void 0, | ||
modifiers: [], | ||
loc: compilerDom.locStub | ||
} | ||
], | ||
props: wrapperProps, | ||
children, | ||
@@ -862,3 +916,3 @@ loc: compilerDom.locStub, | ||
return v.map(clone); | ||
} else if (shared.isObject(v)) { | ||
} else if (shared.isPlainObject(v)) { | ||
const res = {}; | ||
@@ -945,3 +999,3 @@ for (const key in v) { | ||
} | ||
function processChildren(parent, context, asFragment = false, disableNestedFragments = false) { | ||
function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableCommentAsIfAlternate = false) { | ||
if (asFragment) { | ||
@@ -986,7 +1040,14 @@ context.pushStringPart(`<!--[-->`); | ||
context.pushStringPart( | ||
compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [child.content]) | ||
compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [ | ||
child.content | ||
]) | ||
); | ||
break; | ||
case 9: | ||
ssrProcessIf(child, context, disableNestedFragments); | ||
ssrProcessIf( | ||
child, | ||
context, | ||
disableNestedFragments, | ||
disableCommentAsIfAlternate | ||
); | ||
break; | ||
@@ -1035,2 +1096,33 @@ case 11: | ||
} | ||
function processOption(plainNode) { | ||
if (plainNode.tag === "option") { | ||
if (plainNode.props.findIndex((p) => p.name === "selected") === -1) { | ||
const value = findValueBinding(plainNode); | ||
plainNode.ssrCodegenNode.elements.push( | ||
compilerDom.createConditionalExpression( | ||
compilerDom.createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [ | ||
compilerDom.createConditionalExpression( | ||
compilerDom.createCallExpression(`Array.isArray`, [model]), | ||
compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ | ||
model, | ||
value | ||
]), | ||
compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [ | ||
model, | ||
value | ||
]) | ||
) | ||
]), | ||
compilerDom.createSimpleExpression(" selected", true), | ||
compilerDom.createSimpleExpression("", true), | ||
false | ||
) | ||
); | ||
} | ||
} else if (plainNode.tag === "optgroup") { | ||
plainNode.children.forEach( | ||
(option) => processOption(option) | ||
); | ||
} | ||
} | ||
if (node.tagType === 0) { | ||
@@ -1118,29 +1210,5 @@ const res = { props: [] }; | ||
} else if (node.tag === "select") { | ||
node.children.forEach((option) => { | ||
if (option.type === 1) { | ||
const plainNode = option; | ||
if (plainNode.props.findIndex((p) => p.name === "selected") === -1) { | ||
const value = findValueBinding(plainNode); | ||
plainNode.ssrCodegenNode.elements.push( | ||
compilerDom.createConditionalExpression( | ||
compilerDom.createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [ | ||
compilerDom.createConditionalExpression( | ||
compilerDom.createCallExpression(`Array.isArray`, [model]), | ||
compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [ | ||
model, | ||
value | ||
]), | ||
compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [ | ||
model, | ||
value | ||
]) | ||
) | ||
]), | ||
compilerDom.createSimpleExpression(" selected", true), | ||
compilerDom.createSimpleExpression("", true), | ||
false | ||
/* no newline */ | ||
) | ||
); | ||
} | ||
node.children.forEach((child) => { | ||
if (child.type === 1) { | ||
processOption(child); | ||
} | ||
@@ -1186,3 +1254,2 @@ }); | ||
false | ||
/* no newline */ | ||
) | ||
@@ -1200,3 +1267,3 @@ ) | ||
} | ||
if (node.type === 1 && node.tagType === 1 && (compilerDom.isBuiltInType(node.tag, "Transition") || compilerDom.isBuiltInType(node.tag, "KeepAlive"))) { | ||
if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) { | ||
const rootChildren = filterChild(context.root); | ||
@@ -1218,4 +1285,3 @@ if (rootChildren.length === 1 && rootChildren[0] === node) { | ||
if (c.type === 9 || c.type === 1 && compilerDom.findDir(c, "if")) { | ||
if (hasEncounteredIf) | ||
return; | ||
if (hasEncounteredIf) return; | ||
hasEncounteredIf = true; | ||
@@ -1269,3 +1335,3 @@ } else if ( | ||
if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !compilerDom.findDir(node, "for")) { | ||
if (compilerDom.isBuiltInType(node.tag, "Suspense")) { | ||
if (node.tag === "suspense" || node.tag === "Suspense") { | ||
for (const child of node.children) { | ||
@@ -1291,6 +1357,5 @@ if (child.type === 1 && child.tagType === 3) { | ||
function compile(template, options = {}) { | ||
function compile(source, options = {}) { | ||
options = { | ||
...options, | ||
// apply DOM-specific parsing options | ||
...compilerDom.parserOptions, | ||
@@ -1306,3 +1371,3 @@ ssr: true, | ||
}; | ||
const ast = compilerDom.baseParse(template, options); | ||
const ast = typeof source === "string" ? compilerDom.baseParse(source, options) : source; | ||
rawOptionsMap.set(ast, options); | ||
@@ -1331,3 +1396,3 @@ compilerDom.transform(ast, { | ||
on: compilerDom.transformOn, | ||
// model and show has dedicated SSR handling | ||
// model and show have dedicated SSR handling | ||
model: ssrTransformModel, | ||
@@ -1334,0 +1399,0 @@ show: ssrTransformShow, |
@@ -1,4 +0,4 @@ | ||
import { CompilerOptions, CodegenResult } from '@kdujs/compiler-dom'; | ||
import { RootNode, CompilerOptions, CodegenResult } from '@kdujs/compiler-dom'; | ||
export declare function compile(template: string, options?: CompilerOptions): CodegenResult; | ||
export declare function compile(source: string | RootNode, options?: CompilerOptions): CodegenResult; | ||
{ | ||
"name": "@kdujs/compiler-ssr-canary", | ||
"version": "3.20241209.0-minor.0", | ||
"version": "3.20241209.0", | ||
"description": "@kdujs/compiler-ssr", | ||
@@ -31,5 +31,5 @@ "main": "dist/compiler-ssr.cjs.js", | ||
"dependencies": { | ||
"@kdujs/shared": "npm:@kdujs/shared-canary@3.20241209.0-minor.0", | ||
"@kdujs/compiler-dom": "npm:@kdujs/compiler-dom-canary@3.20241209.0-minor.0" | ||
"@kdujs/shared": "npm:@kdujs/shared-canary@3.20241209.0", | ||
"@kdujs/compiler-dom": "npm:@kdujs/compiler-dom-canary@3.20241209.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
46610
1357
1
+ Added@kdujs/compiler-core-canary@3.20241209.0(transitive)
+ Added@kdujs/compiler-dom-canary@3.20241209.0(transitive)
+ Added@kdujs/shared-canary@3.20241209.0(transitive)
+ Addedentities@4.5.0(transitive)
- Removed@kdujs/compiler-core-canary@3.20241209.0-minor.0(transitive)
- Removed@kdujs/compiler-dom-canary@3.20241209.0-minor.0(transitive)
- Removed@kdujs/shared-canary@3.20241209.0-minor.0(transitive)
Updated@kdujs/compiler-dom@npm:@kdujs/compiler-dom-canary@3.20241209.0