const nodes: TemplateChildNode[] = []
while (!isEnd(context, mode, ancestors)) {
- __DEV__ && assert(context.source.length > 0)
+ __TEST__ && assert(context.source.length > 0)
const s = context.source
let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined
context: ParserContext,
ancestors: ElementNode[]
): TemplateChildNode[] {
- __DEV__ &&
+ __TEST__ &&
assert(last(ancestors) == null || last(ancestors)!.ns !== Namespaces.HTML)
- __DEV__ && assert(startsWith(context.source, '<![CDATA['))
+ __TEST__ && assert(startsWith(context.source, '<![CDATA['))
advanceBy(context, 9)
const nodes = parseChildren(context, TextModes.CDATA, ancestors)
if (context.source.length === 0) {
emitError(context, ErrorCodes.EOF_IN_CDATA)
} else {
- __DEV__ && assert(startsWith(context.source, ']]>'))
+ __TEST__ && assert(startsWith(context.source, ']]>'))
advanceBy(context, 3)
}
}
function parseComment(context: ParserContext): CommentNode {
- __DEV__ && assert(startsWith(context.source, '<!--'))
+ __TEST__ && assert(startsWith(context.source, '<!--'))
const start = getCursor(context)
let content: string
}
function parseBogusComment(context: ParserContext): CommentNode | undefined {
- __DEV__ && assert(/^<(?:[\!\?]|\/[^a-z>])/i.test(context.source))
+ __TEST__ && assert(/^<(?:[\!\?]|\/[^a-z>])/i.test(context.source))
const start = getCursor(context)
const contentStart = context.source[1] === '?' ? 1 : 2
context: ParserContext,
ancestors: ElementNode[]
): ElementNode | undefined {
- __DEV__ && assert(/^<[a-z]/i.test(context.source))
+ __TEST__ && assert(/^<[a-z]/i.test(context.source))
// Start tag.
const wasInPre = context.inPre
type: TagType,
parent: ElementNode | undefined
): ElementNode {
- __DEV__ && assert(/^<\/?[a-z]/i.test(context.source))
- __DEV__ &&
+ __TEST__ && assert(/^<\/?[a-z]/i.test(context.source))
+ __TEST__ &&
assert(
type === (startsWith(context.source, '</') ? TagType.End : TagType.Start)
)
context: ParserContext,
nameSet: Set<string>
): AttributeNode | DirectiveNode {
- __DEV__ && assert(/^[^\t\r\n\f />]/.test(context.source))
+ __TEST__ && assert(/^[^\t\r\n\f />]/.test(context.source))
// Name.
const start = getCursor(context)
mode: TextModes
): InterpolationNode | undefined {
const [open, close] = context.options.delimiters
- __DEV__ && assert(startsWith(context.source, open))
+ __TEST__ && assert(startsWith(context.source, open))
const closeIndex = context.source.indexOf(close, open.length)
if (closeIndex === -1) {
}
function parseText(context: ParserContext, mode: TextModes): TextNode {
- __DEV__ && assert(context.source.length > 0)
+ __TEST__ && assert(context.source.length > 0)
const [open] = context.options.delimiters
// TODO could probably use some perf optimization
context.source.length
].filter(n => n !== -1)
)
- __DEV__ && assert(endIndex > 0)
+ __TEST__ && assert(endIndex > 0)
const start = getCursor(context)
const content = parseTextData(context, endIndex, mode)
function advanceBy(context: ParserContext, numberOfCharacters: number): void {
const { source } = context
- __DEV__ && assert(numberOfCharacters <= source.length)
+ __TEST__ && assert(numberOfCharacters <= source.length)
advancePositionWithMutation(context, source, numberOfCharacters)
context.source = source.slice(numberOfCharacters)
}
}
// perform the work on exit, after all child expressions have been
// processed and merged.
- return () => {
+ return function postTransformElement() {
const { tag, tagType, props } = node
const isPortal = tag === 'portal' || tag === 'Portal'
const isSuspense = tag === 'suspense' || tag === 'Suspense'
node,
context,
// skip reserved "is" prop <component is>
- node.props.filter(p => p !== isProp)
+ isProp ? node.props.filter(p => p !== isProp) : node.props
)
patchFlag = propsBuildResult.patchFlag
dynamicPropNames = propsBuildResult.dynamicPropNames
args.push(patchFlag + '')
}
if (dynamicPropNames && dynamicPropNames.length) {
- args.push(
- `[${dynamicPropNames.map(n => JSON.stringify(n)).join(`, `)}]`
- )
+ args.push(stringifyDynamicPropNames(dynamicPropNames))
}
}
}
}
+function stringifyDynamicPropNames(props: string[]): string {
+ let propsNamesString = `[`
+ for (let i = 0, l = props.length; i < l; i++) {
+ propsNamesString += JSON.stringify(props[i])
+ if (i < l - 1) propsNamesString += ', '
+ }
+ return propsNamesString + `]`
+}
+
export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode
export function buildProps(
// - onXXX handlers / style: merge into array
// - class: merge into single expression with concatenation
function dedupeProperties(properties: Property[]): Property[] {
- const knownProps: Record<string, Property> = {}
+ const knownProps: Map<string, Property> = new Map()
const deduped: Property[] = []
for (let i = 0; i < properties.length; i++) {
const prop = properties[i]
continue
}
const name = prop.key.content
- const existing = knownProps[name]
+ const existing = knownProps.get(name)
if (existing) {
if (
name === 'style' ||
}
// unexpected duplicate, should have emitted error during parse
} else {
- knownProps[name] = prop
+ knownProps.set(name, prop)
deduped.push(prop)
}
}