-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
286 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
export function patchAttr(el: Element, key: string, value: any) { | ||
if (value == null) { | ||
// TODO explain why we are no longer checking boolean/enumerated here | ||
|
||
export function patchAttr( | ||
el: Element, | ||
key: string, | ||
value: any, | ||
isSVG: boolean | ||
) { | ||
if (isSVG && key.indexOf('xlink:') === 0) { | ||
// TODO handle xlink | ||
} else if (value == null) { | ||
el.removeAttribute(key) | ||
} else { | ||
// TODO in dev mode, warn against incorrect values for boolean or | ||
// enumerated attributes | ||
el.setAttribute(key, value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
describe('ssr: render props', () => { | ||
test('class', () => {}) | ||
|
||
test('styles', () => { | ||
test('style', () => { | ||
// only render numbers for properties that allow no unit numbers | ||
}) | ||
|
||
describe('attrs', () => { | ||
test('basic', () => {}) | ||
test('normal attrs', () => {}) | ||
|
||
test('boolean attrs', () => {}) | ||
test('boolean attrs', () => {}) | ||
|
||
test('enumerated attrs', () => {}) | ||
test('enumerated attrs', () => {}) | ||
|
||
test('skip falsy values', () => {}) | ||
}) | ||
|
||
describe('domProps', () => { | ||
test('innerHTML', () => {}) | ||
test('ignore falsy values', () => {}) | ||
|
||
test('textContent', () => {}) | ||
test('props to attrs', () => {}) | ||
|
||
test('textarea', () => {}) | ||
|
||
test('other renderable domProps', () => { | ||
// also test camel to kebab case conversion for some props | ||
}) | ||
}) | ||
test('ignore non-renderable props', () => {}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
// import { renderToString, renderComponent } from '../src' | ||
|
||
describe('ssr: renderToString', () => { | ||
test('basic', () => {}) | ||
describe('elements', () => { | ||
test('text children', () => {}) | ||
|
||
test('nested components', () => {}) | ||
test('array children', () => {}) | ||
|
||
test('nested components with optimized slots', () => {}) | ||
test('void elements', () => {}) | ||
|
||
test('mixing optimized / vnode components', () => {}) | ||
test('innerHTML', () => {}) | ||
|
||
test('nested components with vnode slots', () => {}) | ||
test('textContent', () => {}) | ||
|
||
test('async components', () => {}) | ||
test('textarea value', () => {}) | ||
}) | ||
|
||
test('parallel async components', () => {}) | ||
describe('components', () => { | ||
test('nested components', () => {}) | ||
|
||
test('nested components with optimized slots', () => {}) | ||
|
||
test('mixing optimized / vnode components', () => {}) | ||
|
||
test('nested components with vnode slots', () => {}) | ||
|
||
test('async components', () => {}) | ||
|
||
test('parallel async components', () => {}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,64 @@ | ||
export function renderProps() {} | ||
import { escape } from './escape' | ||
import { | ||
normalizeClass, | ||
normalizeStyle, | ||
propsToAttrMap, | ||
hyphenate, | ||
isString, | ||
isNoUnitNumericStyleProp, | ||
isOn, | ||
isSSRSafeAttrName, | ||
isBooleanAttr | ||
} from '@vue/shared/src' | ||
|
||
export function renderClass() {} | ||
export function renderProps( | ||
props: Record<string, unknown>, | ||
isCustomElement: boolean = false | ||
): string { | ||
let ret = '' | ||
for (const key in props) { | ||
if (key === 'key' || key === 'ref' || isOn(key)) { | ||
continue | ||
} | ||
const value = props[key] | ||
if (key === 'class') { | ||
ret += ` class="${renderClass(value)}"` | ||
} else if (key === 'style') { | ||
ret += ` style="${renderStyle(value)}"` | ||
} else if (value != null) { | ||
const attrKey = isCustomElement | ||
? key | ||
: propsToAttrMap[key] || key.toLowerCase() | ||
if (isBooleanAttr(attrKey)) { | ||
ret += ` ${attrKey}=""` | ||
} else if (isSSRSafeAttrName(attrKey)) { | ||
ret += ` ${attrKey}="${escape(value)}"` | ||
} | ||
} | ||
} | ||
return ret | ||
} | ||
|
||
export function renderStyle() {} | ||
export function renderClass(raw: unknown): string { | ||
return escape(normalizeClass(raw)) | ||
} | ||
|
||
export function renderStyle(raw: unknown): string { | ||
if (!raw) { | ||
return '' | ||
} | ||
const styles = normalizeStyle(raw) | ||
let ret = '' | ||
for (const key in styles) { | ||
const value = styles[key] | ||
const normalizedKey = key.indexOf(`--`) === 0 ? key : hyphenate(key) | ||
if ( | ||
isString(value) || | ||
(typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey)) | ||
) { | ||
// only render valid values | ||
ret += `${normalizedKey}:${value};` | ||
} | ||
} | ||
return escape(ret) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.