-
Notifications
You must be signed in to change notification settings - Fork 0
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
jindy
committed
Jun 27, 2022
1 parent
43d2774
commit c13829e
Showing
10 changed files
with
186 additions
and
5 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,5 +1,7 @@ | ||
export const TO_DISPLAY_STRING = Symbol("toDisplayString") | ||
export const CREATE_ELEMENT_VNODE = Symbol("createElementVNode") | ||
|
||
export const helperMapName = { | ||
[TO_DISPLAY_STRING]: "toDisplayString", | ||
[CREATE_ELEMENT_VNODE]: "createElementVNode", | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createVNodeCall, NodeTypes } from "../ast" | ||
import { CREATE_ELEMENT_VNODE } from "../runtimeHelpers" | ||
|
||
export function transformElement(node: any, context) { | ||
if (node.type === NodeTypes.ELEMENT) { | ||
return () => { | ||
// context.helper(CREATE_ELEMENT_VNODE) | ||
|
||
// 中间层 | ||
// tag | ||
const vnodeTag = `'${node.tag}'` | ||
// children | ||
const children = node.children | ||
const vnodeChildren = children[0] | ||
// props | ||
let vnodeProps | ||
|
||
// const vnodeElement = { | ||
// type: NodeTypes.ELEMENT, | ||
// tag: vnodeTag, | ||
// props: vnodeProps, | ||
// children: vnodeChildren, | ||
// } | ||
|
||
node.codegenNode = createVNodeCall( | ||
context, | ||
vnodeTag, | ||
vnodeProps, | ||
vnodeChildren | ||
) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { NodeTypes } from "../ast" | ||
import { isText } from "../util" | ||
|
||
export function transformText(node) { | ||
return () => { | ||
const { children, type } = node | ||
if (type === NodeTypes.ELEMENT) { | ||
let currentContainer | ||
for (let index = 0; index < children.length; index++) { | ||
const child = children[index] | ||
if (isText(child)) { | ||
for (let j = index + 1; j < children.length; j++) { | ||
const next = children[j] | ||
if (isText(next)) { | ||
if (!currentContainer) { | ||
currentContainer = children[index] = { | ||
type: NodeTypes.COMPOUND_EXPRESSION, | ||
children: [child], | ||
} | ||
} | ||
currentContainer.children.push(" + ") | ||
currentContainer.children.push(next) | ||
children.splice(j, 1) | ||
j-- | ||
} else { | ||
currentContainer = undefined | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { NodeTypes } from "./ast" | ||
|
||
export function isText(node) { | ||
return node.type === NodeTypes.INTERPOLATION || node.type === NodeTypes.TEXT | ||
} |
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