forked from cuixiaorui/mini-vue
-
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.
feat(compile-core): support element and interpolation
- Loading branch information
1 parent
89938a3
commit a0d791d
Showing
13 changed files
with
137 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 +1,26 @@ | ||
import { generate } from "../src/codegen"; | ||
import { baseParse } from "../src/parse"; | ||
import { transform } from "../src/transform"; | ||
import { transformElement } from "../src/transforms/transformElement"; | ||
import { transformExpression } from "../src/transforms/transformExpression"; | ||
|
||
test("interpolation module", () => { | ||
const ast = baseParse("{{hello}}"); | ||
transform(ast, { | ||
nodeTransforms: [transformExpression] | ||
nodeTransforms: [transformExpression], | ||
}); | ||
|
||
const { code } = generate(ast); | ||
console.log(code); | ||
}); | ||
|
||
test("element and interpolation", () => { | ||
const ast = baseParse("<div>hi,{{msg}}</div>"); | ||
transform(ast, { | ||
nodeTransforms: [transformExpression, transformElement], | ||
}); | ||
|
||
const { code } = generate(ast); | ||
console.log(code); | ||
console.log(code.children[0]) | ||
}); |
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 helperNameMap = { | ||
[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NodeTypes } from "../ast"; | ||
import { CREATE_ELEMENT_VNODE } from "../runtimeHelpers"; | ||
|
||
export function transformElement(node, context) { | ||
if (node.type === NodeTypes.ELEMENT) { | ||
// TODO 没有实现 block 所以这里直接创建 element | ||
context.helper(CREATE_ELEMENT_VNODE); | ||
} | ||
} |
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