Skip to content

Commit

Permalink
Merge pull request #167 from Ubugeeei/30-resolve-component
Browse files Browse the repository at this point in the history
#30 resolve component
  • Loading branch information
ubugeeei authored Nov 4, 2023
2 parents 56dcdc7 + 520ff63 commit f969757
Show file tree
Hide file tree
Showing 115 changed files with 9,553 additions and 84 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ npm i -g @antfu/ni

[![Pages Deploy](https://github.com/Ubugeeei/chibivue/actions/workflows/deploy.yml/badge.svg?branch=main)](https://github.com/Ubugeeei/chibivue/actions/workflows/deploy.yml)

> total: 340,000 chars ↑ (japanese)
> total: 360,000 chars ↑ (japanese)
### book url (GitHub Pages)

Expand Down Expand Up @@ -144,23 +144,24 @@ Please refer to the information below for the progress status.

### Template Compiler

| feature | impl | book |
| ----------------- | ---- | ---- |
| v-bind |||
| v-on |||
| event modifier |||
| v-if |||
| v-for |||
| v-model || |
| v-show | | |
| mustache |||
| slot (default) | | |
| slot (named) | | |
| slot (scoped) | | |
| dynamic component | | |
| comment out |||
| fragment |||
| bind expressions |||
| feature | impl | book |
| ------------------ | ---- | ---- |
| v-bind |||
| v-on |||
| event modifier |||
| v-if |||
| v-for |||
| v-model || |
| v-show | | |
| mustache |||
| slot (default) | | |
| slot (named) | | |
| slot (scoped) | | |
| dynamic component | | |
| comment out |||
| fragment |||
| bind expressions |||
| resolve components |||

### SFC Compiler

Expand All @@ -182,21 +183,20 @@ Please refer to the information below for the progress status.

## 🗓️ Big Plans

- Complete Basic Template Compiler
- Component resolution
- Complete Basic Template Compiler
- Slots
- Complete Basic SFC Compiler
- Complete Basic SFC Compiler
- script setup
- compiler macro
- Overall restructuring
- Overall restructuring
- Fixing typos and errors
- Reviewing English version of the text
- Making explanations more understandable
- Incorporate refactoring of the reactivity package that will likely be included in Vue.js 3.4
- Incorporate refactoring of the reactivity package that will likely be included in Vue.js 3.4
- Implementation and explanation of SSR / SSG
- Implementation and explanation of compile-time optimization
Tree flattening and static hoisting, among others
- 🌟 Implementation and explanation of **__Vapor Mode__**
- 🌟 Implementation and explanation of \***\*Vapor Mode\*\***
Since the official version has not been released, we will implement it based on our predictions.

## 🎉 Bonus Track
Expand All @@ -213,4 +213,4 @@ The title is "**Hyper Ultimate Super Extreme Minimal Vue - writing Vue.js on 15

# Contributing

Please see [contributing.md](https://github.com/Ubugeeei/chibivue/blob/main/.github/contributing.md).
Please see [contributing.md](https://github.com/Ubugeeei/chibivue/blob/main/.github/contributing.md).
Binary file added book/images/resolve_components.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -53,7 +56,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function makeMap(
str: string,
expectsLowerCase?: boolean
): (key: string) => boolean {
const map: Record<string, boolean> = Object.create(null);
const list: Array<string> = str.split(",");
for (let i = 0; i < list.length; i++) {
map[list[i]] = true;
}
return expectsLowerCase
? (val) => !!map[val.toLowerCase()]
: (val) => !!map[val];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function makeMap(
str: string,
expectsLowerCase?: boolean
): (key: string) => boolean {
const map: Record<string, boolean> = Object.create(null);
const list: Array<string> = str.split(",");
for (let i = 0; i < list.length; i++) {
map[list[i]] = true;
}
return expectsLowerCase
? (val) => !!map[val.toLowerCase()]
: (val) => !!map[val];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -57,7 +60,10 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
node.content = rewriteIdentifier(rawExp);
const isLiteral = isLiteralWhitelisted(rawExp);
if (!isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IfConditionalExpression,
IfNode,
NodeTypes,
SimpleExpressionNode,
VNodeCall,
createCallExpression,
createConditionalExpression,
Expand All @@ -15,6 +16,7 @@ import {
createStructuralDirectiveTransform,
traverseNode,
} from "../transform";
import { processExpression } from "./transformExpression";

export const transformIf = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
Expand Down Expand Up @@ -48,6 +50,10 @@ export function processIf(
isRoot: boolean
) => (() => void) | undefined
) {
if (!context.isBrowser && dir.exp) {
dir.exp = processExpression(dir.exp as SimpleExpressionNode, context);
}

if (dir.name === "if") {
const branch = createIfBranch(node, dir);
const ifNode: IfNode = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import { walkIdentifiers } from "../babelUtils";
import { NodeTransform, TransformContext } from "../transform";
import { advancePositionWithClone, isSimpleIdentifier } from "../utils";
import { makeMap } from "../../shared/makeMap";

const isLiteralWhitelisted = makeMap("true,false,null,this");

export const transformExpression: NodeTransform = (node, ctx) => {
if (node.type === NodeTypes.INTERPOLATION) {
Expand Down Expand Up @@ -58,8 +61,9 @@ export function processExpression(
};

if (isSimpleIdentifier(rawExp)) {
const isLiteral = isLiteralWhitelisted(rawExp);
const isScopeVarReference = ctx.identifiers[rawExp];
if (!asParams && !isScopeVarReference) {
if (!asParams && !isScopeVarReference && !isLiteral) {
node.content = rewriteIdentifier(rawExp);
}
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IfConditionalExpression,
IfNode,
NodeTypes,
SimpleExpressionNode,
VNodeCall,
createCallExpression,
createConditionalExpression,
Expand All @@ -15,6 +16,7 @@ import {
createStructuralDirectiveTransform,
traverseNode,
} from "../transform";
import { processExpression } from "./transformExpression";

export const transformIf = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
Expand Down Expand Up @@ -48,6 +50,10 @@ export function processIf(
isRoot: boolean
) => (() => void) | undefined
) {
if (!context.isBrowser && dir.exp) {
dir.exp = processExpression(dir.exp as SimpleExpressionNode, context);
}

if (dir.name === "if") {
const branch = createIfBranch(node, dir);
const ifNode: IfNode = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>chibivue</title>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "playground",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^4.9.3",
"vite": "^4.2.0"
}
}
Loading

0 comments on commit f969757

Please sign in to comment.