!172 Add for support and benchmark
* refactor: publish new version * feat: add changeset and changed package name * Merge branch 'API-2.0' into api2/for * fix: import package from workspace * feat: add for unit parsing * feat: init benchmark demo * refactor: gitignore add history
This commit is contained in:
parent
b7756e9732
commit
be4b0cb024
|
@ -0,0 +1,8 @@
|
|||
# Changesets
|
||||
|
||||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
||||
|
||||
We have a quick list of common questions to get you started engaging with this project in
|
||||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
|
||||
"changelog": "@changesets/cli/changelog",
|
||||
"commit": false,
|
||||
"fixed": [],
|
||||
"linked": [],
|
||||
"access": "restricted",
|
||||
"baseBranch": "master",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": ["create-inula", "openinula", "inula-cli", "inula-dev-tools", "inula-intl", "inula-request", "inula-router", "inula-vite-app", "inula-webpack-app"]
|
||||
}
|
|
@ -8,3 +8,4 @@ build
|
|||
/packages/inula-router/connectRouter
|
||||
/packages/inula-router/router
|
||||
dist
|
||||
.history
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>Inula-next</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "dev",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/standalone": "^7.22.4",
|
||||
"@openinula/next": "workspace:*",
|
||||
"@iandx/easy-css": "^0.10.14",
|
||||
"babel-preset-inula-next": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-inula-next": "workspace:*"
|
||||
},
|
||||
"keywords": [
|
||||
"dlight.js"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
import { render, View } from '@openinula/next';
|
||||
|
||||
|
||||
let idCounter = 1;
|
||||
|
||||
const adjectives = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean', 'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive', 'cheap', 'expensive', 'fancy'];
|
||||
const colours = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange'];
|
||||
const nouns = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse', 'keyboard'];
|
||||
|
||||
function _random(max) {
|
||||
return Math.round(Math.random() * 1000) % max;
|
||||
}
|
||||
|
||||
function buildData(count) {
|
||||
const data = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
data[i] = {
|
||||
id: idCounter++,
|
||||
label: `${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function Button ({ id, text, fn }) {
|
||||
return (
|
||||
<div class='col-sm-6 smallpad'>
|
||||
<button id={ id } class='btn btn-primary btn-block' type='button' onClick={ fn }>{ text }</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function App () {
|
||||
let data = [];
|
||||
let selected = null;
|
||||
function run() {
|
||||
data = buildData(1000);
|
||||
}
|
||||
function runLots() {
|
||||
data = buildData(10000);
|
||||
}
|
||||
function add() {
|
||||
data.push(...buildData(1000));
|
||||
}
|
||||
function update() {
|
||||
for (let i = 0; i < data.length; i += 10) {
|
||||
data[i].label += ' !!!';
|
||||
}
|
||||
}
|
||||
function swapRows() {
|
||||
if (data.length > 998) {
|
||||
[data[1], data[998]] = [data[998], data[1]];
|
||||
}
|
||||
}
|
||||
function clear() {
|
||||
data = [];
|
||||
}
|
||||
function remove(id) {
|
||||
data = data.filter(d => d.id !== id);
|
||||
}
|
||||
function select(id) {
|
||||
selected = id;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class='container'>
|
||||
<div class='jumbotron'><div class='row'>
|
||||
<div class='col-md-6'><h1>Inula-next Keyed</h1></div>
|
||||
<div class='col-md-6'><div class='row'>
|
||||
<Button id='run' text='Create 1,000 rows' fn={ run } />
|
||||
<Button id='runlots' text='Create 10,000 rows' fn={ runLots } />
|
||||
<Button id='add' text='Append 1,000 rows' fn={ add } />
|
||||
<Button id='update' text='Update every 10th row' fn={ update } />
|
||||
<Button id='clear' text='Clear' fn={ clear } />
|
||||
<Button id='swaprows' text='Swap Rows' fn={ swapRows } />
|
||||
</div></div>
|
||||
</div></div>
|
||||
<table class='table table-hover table-striped test-data'><tbody>
|
||||
<for array={ data } item={ { id, label } } key={ id }>
|
||||
<tr class={ selected === id ? 'danger': '' }>
|
||||
<td class='col-md-1' textContent={ id } />
|
||||
<td class='col-md-4'><a onClick={select.bind(this, id)} textContent={ label } /></td>
|
||||
<td class='col-md-1'><a onClick={remove.bind(this, id)}><span class='glyphicon glyphicon-remove' aria-hidden="true" /></a></td>
|
||||
<td class='col-md-6'/>
|
||||
</tr>
|
||||
</for>
|
||||
</tbody></table>
|
||||
<span class='preloadicon glyphicon glyphicon-remove' aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render('main', App);
|
|
@ -0,0 +1,13 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import inula from 'vite-plugin-inula-next';
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
port: 4320,
|
||||
},
|
||||
base: '',
|
||||
optimizeDeps: {
|
||||
disabled: true,
|
||||
},
|
||||
plugins: [inula({ files: '**/*.{tsx,jsx}' })],
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
# dev
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [2f9d373]
|
||||
- babel-preset-inula-next@0.0.2
|
|
@ -7,6 +7,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="main"></div>
|
||||
<script type="module" src="/src/App.view.tsx"></script>
|
||||
<script type="module" src="/src/App.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "dev",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
@ -10,7 +10,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@babel/standalone": "^7.22.4",
|
||||
"@inula/next": "workspace:*",
|
||||
"@openinula/next": "workspace:*",
|
||||
"@iandx/easy-css": "^0.10.14",
|
||||
"babel-preset-inula-next": "workspace:*"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import { View, render } from '@openinula/next';
|
||||
|
||||
function MyComp() {
|
||||
let count = 0;
|
||||
const db = count * 2;
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="123">Hello dlight fn comp</h1>
|
||||
<section>
|
||||
count: {count}, double is: {db}
|
||||
<button onClick={() => (count += 1)}>Add</button>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
}
|
||||
render('main', MyComp);
|
|
@ -13,7 +13,7 @@ import {
|
|||
insertChildren,
|
||||
use,
|
||||
render,
|
||||
} from '@inula/next';
|
||||
} from '@openinula/next';
|
||||
|
||||
// @ts-ignore
|
||||
function Button({ children, onClick }) {
|
||||
|
@ -35,7 +35,7 @@ function Button({ children, onClick }) {
|
|||
}
|
||||
|
||||
function ArrayModification() {
|
||||
let arr = [];
|
||||
const arr = [];
|
||||
willMount(() => {});
|
||||
return (
|
||||
<section>
|
||||
|
@ -46,9 +46,75 @@ function ArrayModification() {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
function Counter() {
|
||||
let count = 0;
|
||||
const doubleCount = count * 2; // 当count变化时,doubleCount自动更新
|
||||
|
||||
// 当count变化时,watch会自动执行
|
||||
watch(() => {
|
||||
uploadToServer(count);
|
||||
console.log(`count has changed: ${count}`);
|
||||
});
|
||||
|
||||
// 只有在init的时候执行一次
|
||||
console.log(`Counter willMount with count ${count}`);
|
||||
// 在elements被挂载到DOM之后执行
|
||||
didMount(() => {
|
||||
console.log(`Counter didMount with count ${count}`);
|
||||
});
|
||||
|
||||
return (
|
||||
<section>
|
||||
count: {count}, double is: {doubleCount}
|
||||
<button onClick={() => (count ++)}>Add</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Counter() {
|
||||
let count = 0;
|
||||
const doubleCount = count * 2; // 当count变化时,doubleCount自动更新
|
||||
|
||||
uploadToServer(count); // 当count变化时,uploadToServer会自动执行
|
||||
console.log(`count has changed: ${count}`); // 当count变化时,console.log会自动执行
|
||||
|
||||
// 只有在init的时候执行一次
|
||||
willMount(() => {
|
||||
console.log(`Counter willMount with count ${count}`);
|
||||
});
|
||||
// 在elements被挂载到DOM之后执行
|
||||
didMount(() => {
|
||||
console.log(`Counter didMount with count ${count}`);
|
||||
});
|
||||
|
||||
return (
|
||||
<section>
|
||||
count: {count}, double is: {doubleCount}
|
||||
<button onClick={() => (count ++)}>Add</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function MyComp() {
|
||||
let count = 0;
|
||||
let db = count * 2;
|
||||
|
||||
{
|
||||
console.log(count);
|
||||
const i = count * 2;
|
||||
console.log(i);
|
||||
}
|
||||
|
||||
console.log(count);
|
||||
const i = count * 2;
|
||||
console.log(i);
|
||||
|
||||
const XX = () => {
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="123">Hello dlight fn comp</h1>
|
||||
|
|
|
@ -9,5 +9,5 @@ export default defineConfig({
|
|||
optimizeDeps: {
|
||||
disabled: true,
|
||||
},
|
||||
plugins: [inula({ files: '**/*.{view,model}.{ts,js,tsx,jsx}', enableDevTools: true })],
|
||||
plugins: [inula({ files: '**/*.{ts,js,tsx,jsx}' })],
|
||||
});
|
||||
|
|
|
@ -81,5 +81,9 @@
|
|||
"engines": {
|
||||
"node": ">=10.x",
|
||||
"npm": ">=7.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
"changeset": "^0.2.6"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,10 +178,10 @@ inula-cli的所有功能都围绕插件展开,插件可以很方便地让用
|
|||
|
||||
inula-cli支持用户集成已发布在npm仓库的插件,用户可以按需安装并运行这些插件。
|
||||
|
||||
安装可以通过npm安装,这里以插件@inula/add为例:
|
||||
安装可以通过npm安装,这里以插件@openinula/add为例:
|
||||
|
||||
```shell
|
||||
npm i --save-dev @inula/add
|
||||
npm i --save-dev @openinula/add
|
||||
```
|
||||
|
||||
如果需要运行插件,需要在配置文件中配置对应的插件路径
|
||||
|
@ -191,7 +191,7 @@ npm i --save-dev @inula/add
|
|||
|
||||
export default {
|
||||
...
|
||||
plugins:["@inula/add"]
|
||||
plugins:["@openinula/add"]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@inula/store",
|
||||
"name": "@openinula/store",
|
||||
"version": "0.0.0",
|
||||
"description": "DLight shared store",
|
||||
"author": {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@inula/next",
|
||||
"version": "1.0.0-next.9",
|
||||
"name": "@openinula/next",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
"email": "iandxssxx@gmail.com"
|
||||
},
|
||||
"keywords": [
|
||||
"dlight.js"
|
||||
"inula"
|
||||
],
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
|
@ -22,7 +22,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"csstype": "^3.1.3",
|
||||
"@inula/store": "workspace:*"
|
||||
"@openinula/store": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsup": "^6.5.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Store } from '@inula/store';
|
||||
import { Store } from '@openinula/store';
|
||||
|
||||
// ---- Using external Store to store global and document
|
||||
// Because Store is a singleton, it is safe to use it as a global variable
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"name": "inula-router-config",
|
||||
"module": "./esm/connectRouter.js",
|
||||
"main": "./cjs/connectRouter.js",
|
||||
"types": "./@types/index.d.ts",
|
||||
|
|
|
@ -27,7 +27,16 @@ This is a experimental package to implement [API2.0](https://gitee.com/openInula
|
|||
- [x] fragment
|
||||
- [ ] ref (to validate)
|
||||
- [ ] snippet
|
||||
- [ ] for
|
||||
- [x] for
|
||||
|
||||
# 4.8 TODO
|
||||
@YH
|
||||
* Benchmark(result + comparison)
|
||||
* Playground(@HQ publish) deploy
|
||||
* PPT
|
||||
* DEMO
|
||||
* api2.1 compiled code
|
||||
|
||||
|
||||
# function component syntax
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# babel-preset-inula-next
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 2f9d373: feat: change babel import
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "babel-preset-inula-next",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
"email": "iandxssxx@gmail.com"
|
||||
|
@ -32,10 +32,10 @@
|
|||
"@babel/core": "^7.23.3",
|
||||
"@babel/plugin-syntax-jsx": "7.16.7",
|
||||
"@babel/plugin-syntax-typescript": "^7.23.3",
|
||||
"@inula/reactivity-parser": "workspace:*",
|
||||
"@inula/view-generator": "workspace:*",
|
||||
"@inula/view-parser": "workspace:*",
|
||||
"@inula/class-transformer": "workspace:*",
|
||||
"@openinula/reactivity-parser": "workspace:*",
|
||||
"@openinula/view-generator": "workspace:*",
|
||||
"@openinula/view-parser": "workspace:*",
|
||||
"@openinula/class-transformer": "workspace:*",
|
||||
"jsx-view-parser": "workspace:*",
|
||||
"minimatch": "^9.0.3",
|
||||
"vitest": "^1.4.0"
|
||||
|
|
|
@ -227,7 +227,7 @@ export const defaultHTMLTags = [
|
|||
];
|
||||
|
||||
export const availableDecoNames = ['Static', 'Prop', 'Env', 'Content', 'Children'];
|
||||
export const dlightDefaultPackageName = '@inula/next';
|
||||
export const dlightDefaultPackageName = '@openinula/next';
|
||||
|
||||
export const importMap = Object.fromEntries(
|
||||
[
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
declare module '@babel/plugin-syntax-do-expressions';
|
||||
declare module '@babel/plugin-syntax-decorators';
|
||||
declare module '@babel/plugin-syntax-jsx';
|
||||
declare module '@babel/plugin-syntax-typescript';
|
|
@ -1,14 +1,16 @@
|
|||
import syntaxDecorators from '@babel/plugin-syntax-decorators';
|
||||
import syntaxJSX from '@babel/plugin-syntax-jsx';
|
||||
import syntaxTypescript from '@babel/plugin-syntax-typescript';
|
||||
import dlight from './plugin';
|
||||
import { type DLightOption } from './types';
|
||||
import { type ConfigAPI, type TransformOptions } from '@babel/core';
|
||||
import { plugin as fn2Class } from '@inula/class-transformer';
|
||||
import { plugin as fn2Class } from '@openinula/class-transformer';
|
||||
|
||||
export default function (_: ConfigAPI, options: DLightOption): TransformOptions {
|
||||
return {
|
||||
plugins: [
|
||||
['@babel/plugin-syntax-jsx'],
|
||||
['@babel/plugin-syntax-typescript', { isTSX: true }],
|
||||
syntaxJSX.default ?? syntaxJSX,
|
||||
[syntaxTypescript.default ?? syntaxTypescript, { isTSX: true }],
|
||||
[syntaxDecorators.default ?? syntaxDecorators, { legacy: true }],
|
||||
fn2Class,
|
||||
[dlight, options],
|
||||
|
|
|
@ -2,10 +2,10 @@ import type babel from '@babel/core';
|
|||
import { type types as t, type NodePath } from '@babel/core';
|
||||
import { type PropertyContainer, type HTMLTags, type SnippetPropSubDepMap } from './types';
|
||||
import { minimatch } from 'minimatch';
|
||||
import { parseView, ViewUnit } from '@inula/view-parser';
|
||||
import { parseView, ViewUnit } from '@openinula/view-parser';
|
||||
import { parseView as parseJSX } from 'jsx-view-parser';
|
||||
import { parseReactivity } from '@inula/reactivity-parser';
|
||||
import { generateSnippet, generateView } from '@inula/view-generator';
|
||||
import { parseReactivity } from '@openinula/reactivity-parser';
|
||||
import { generateSnippet, generateView } from '@openinula/view-generator';
|
||||
import {
|
||||
alterAttributeMap,
|
||||
availableDecoNames,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@inula/class-transformer",
|
||||
"version": "0.0.0",
|
||||
"name": "@openinula/class-transformer",
|
||||
"version": "0.0.1",
|
||||
"description": "Inula view generator",
|
||||
"keywords": [
|
||||
"inula"
|
||||
|
|
|
@ -19,7 +19,7 @@ export class ThisPatcher {
|
|||
(def): def is Exclude<t.ClassBody['body'][number], t.TSIndexSignature | t.StaticBlock> =>
|
||||
!this.t.isTSIndexSignature(def) && !this.t.isStaticBlock(def)
|
||||
)
|
||||
.map(def => ('name' in def.key ? def.key.name : null));
|
||||
.map(def => (def?.key?.name ? def.key.name : null));
|
||||
|
||||
for (const memberOrMethod of classBodyNode.body) {
|
||||
classPath.scope.traverse(memberOrMethod, {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@inula/error-handler",
|
||||
"version": "1.0.0-alpha.0",
|
||||
"name": "@openinula/error-handler",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
"email": "iandxssxx@gmail.com"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jsx-view-parser",
|
||||
"version": "0.0.0",
|
||||
"version": "0.0.1",
|
||||
"description": "Inula jsx parser",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
|
|
|
@ -536,6 +536,47 @@ export class ViewParser {
|
|||
}
|
||||
|
||||
private pareFor(node: t.JSXElement) {
|
||||
// TODO
|
||||
// ---- Get array
|
||||
const arrayContainer = this.findProp(node, 'array');
|
||||
if (!arrayContainer) throw new Error('Missing [array] prop in for loop');
|
||||
if (!this.t.isJSXExpressionContainer(arrayContainer.value)) throw new Error('Expected expression container for [array] prop');
|
||||
const array = arrayContainer.value.expression;
|
||||
if (this.t.isJSXEmptyExpression(array)) throw new Error('Expected [array] expression not empty');
|
||||
|
||||
// ---- Get key
|
||||
const keyProp = this.findProp(node, 'key');
|
||||
let key: t.Expression = this.t.nullLiteral();
|
||||
if (keyProp) {
|
||||
if (!this.t.isJSXExpressionContainer(keyProp.value)) throw new Error('Expected expression container');
|
||||
if (this.t.isJSXEmptyExpression(keyProp.value.expression)) throw new Error('Expected expression not empty');
|
||||
key = keyProp.value.expression;
|
||||
}
|
||||
|
||||
// ---- Get Item
|
||||
const itemProp = this.findProp(node, 'item');
|
||||
if (!itemProp) throw new Error('Missing [item] prop in for loop');
|
||||
if (!this.t.isJSXExpressionContainer(itemProp.value)) throw new Error('Expected expression container for [item] prop');
|
||||
const item = itemProp.value.expression;
|
||||
if (this.t.isJSXEmptyExpression(item)) throw new Error('Expected [item] expression not empty');
|
||||
// ---- ObjectExpression to ObjectPattern / ArrayExpression to ArrayPattern
|
||||
this.traverse(this.wrapWithFile(item), {
|
||||
ObjectExpression: (path) => {
|
||||
path.node.type = 'ObjectPattern' as any;
|
||||
},
|
||||
ArrayExpression: (path) => {
|
||||
path.node.type = 'ArrayPattern' as any;
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Get children
|
||||
const children = this.t.jsxFragment(this.t.jsxOpeningFragment(), this.t.jsxClosingFragment(), node.children);
|
||||
|
||||
this.viewUnits.push({
|
||||
type: 'for',
|
||||
key,
|
||||
item: item as t.LVal,
|
||||
array,
|
||||
children: this.parseView(children)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,13 +186,4 @@ describe('ElementUnit', () => {
|
|||
const htmlUnit = viewUnits[0] as HTMLUnit;
|
||||
expect(htmlUnit.children!.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should correctly parse the children', () => {
|
||||
const viewUnits = parse('<div><div>ok</div></div>');
|
||||
const htmlUnit = viewUnits[0] as HTMLUnit;
|
||||
const firstChild = htmlUnit.children![0];
|
||||
expect(firstChild.type).toBe('html');
|
||||
expect(t.isStringLiteral((firstChild as HTMLUnit).tag, { value: 'div' })).toBeTruthy();
|
||||
expect((firstChild as HTMLUnit).children![0].type).toBe('text');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { parse } from './mock';
|
||||
|
||||
|
||||
describe('ForUnit', () => {
|
||||
it('should identify for unit', () => {
|
||||
const viewUnits = parse('<for array={items} item={item}> <div>{item}</div> </for>');
|
||||
expect(viewUnits.length).toBe(1);
|
||||
expect(viewUnits[0].type).toBe('for');
|
||||
});
|
||||
});
|
|
@ -17,7 +17,7 @@ describe('TemplateUnit', () => {
|
|||
expect(viewUnits[0].type).toBe('template');
|
||||
});
|
||||
|
||||
it("should correctly parse a nested HTMLUnit's structure into a template", () => {
|
||||
it('should correctly parse a nested HTMLUnit\'s structure into a template', () => {
|
||||
const viewUnits = parse('<div><div></div></div>');
|
||||
const template = (viewUnits[0] as TemplateUnit).template;
|
||||
|
||||
|
@ -28,7 +28,7 @@ describe('TemplateUnit', () => {
|
|||
});
|
||||
|
||||
// ---- Props
|
||||
it("should correctly parse the path of TemplateUnit's dynamic props in root element", () => {
|
||||
it('should correctly parse the path of TemplateUnit\'s dynamic props in root element', () => {
|
||||
const viewUnits = parse('<div class={this.name}><div></div></div>');
|
||||
const dynamicProps = (viewUnits[0] as TemplateUnit).props;
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('TemplateUnit', () => {
|
|||
expect(prop.path).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should correctly parse the path of TemplateUnit's dynamic props in nested element", () => {
|
||||
it('should correctly parse the path of TemplateUnit\'s dynamic props in nested element', () => {
|
||||
const viewUnits = parse('<div><div class={this.name}></div></div>');
|
||||
const dynamicProps = (viewUnits[0] as TemplateUnit).props!;
|
||||
|
||||
|
@ -47,17 +47,17 @@ describe('TemplateUnit', () => {
|
|||
expect(prop.path[0]).toBe(0);
|
||||
});
|
||||
|
||||
it("should correctly parse the path of TemplateUnit's dynamic props with mutable particles ahead", () => {
|
||||
it('should correctly parse the path of TemplateUnit\'s dynamic props with mutable particles ahead', () => {
|
||||
const viewUnits = parse('<div><Comp/><div class={this.name}></div></div>');
|
||||
const dynamicProps = (viewUnits[0] as TemplateUnit).props!;
|
||||
|
||||
expect(dynamicProps).toHaveLength(1);
|
||||
const prop = dynamicProps[0]!;
|
||||
expect(prop.path).toHaveLength(1);
|
||||
expect(prop.path[0]).toBe(1);
|
||||
expect(prop.path[0]).toBe(0);
|
||||
});
|
||||
|
||||
it("should correctly parse the path of TemplateUnit's mutableUnits", () => {
|
||||
it('should correctly parse the path of TemplateUnit\'s mutableUnits', () => {
|
||||
const viewUnits = parse('<div><Comp/><div class={this.name}></div></div>');
|
||||
const mutableParticles = (viewUnits[0] as TemplateUnit).mutableUnits!;
|
||||
|
||||
|
@ -67,7 +67,7 @@ describe('TemplateUnit', () => {
|
|||
expect(particle.path[0]).toBe(0);
|
||||
});
|
||||
|
||||
it("should correctly parse the path of multiple TemplateUnit's mutableUnits", () => {
|
||||
it('should correctly parse the path of multiple TemplateUnit\'s mutableUnits', () => {
|
||||
const viewUnits = parse('<div><Comp/><div class={this.name}></div><Comp/></div>');
|
||||
const mutableParticles = (viewUnits[0] as TemplateUnit).mutableUnits!;
|
||||
|
||||
|
@ -77,6 +77,6 @@ describe('TemplateUnit', () => {
|
|||
expect(firstParticle.path[0]).toBe(0);
|
||||
const secondParticle = mutableParticles[1]!;
|
||||
expect(secondParticle.path).toHaveLength(1);
|
||||
expect(secondParticle.path[0]).toBe(2);
|
||||
expect(secondParticle.path[0]).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -59,6 +59,7 @@ export interface IfUnit {
|
|||
export interface ExpUnit {
|
||||
type: 'exp';
|
||||
content: UnitProp;
|
||||
props: Record<string, UnitProp>;
|
||||
}
|
||||
|
||||
export interface EnvUnit {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@inula/reactivity-parser",
|
||||
"name": "@openinula/reactivity-parser",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
|
@ -29,8 +29,8 @@
|
|||
"vitest": "^0.34.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@inula/error-handler": "workspace:*",
|
||||
"@inula/view-parser": "workspace:*"
|
||||
"@openinula/error-handler": "workspace:*",
|
||||
"@openinula/view-parser": "workspace:*"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createErrorHandler } from '@inula/error-handler';
|
||||
import { createErrorHandler } from '@openinula/error-handler';
|
||||
|
||||
export const DLError = createErrorHandler('ReactivityParser', {
|
||||
1: 'Invalid ViewUnit type',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { type ViewUnit } from '@inula/view-parser';
|
||||
import { type ViewUnit } from '@openinula/view-parser';
|
||||
import { ReactivityParser } from './parser';
|
||||
import { type ViewParticle, type ReactivityParserConfig } from './types';
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import {
|
|||
type SnippetUnit,
|
||||
SwitchUnit,
|
||||
TryUnit,
|
||||
} from '@inula/view-parser';
|
||||
} from '@openinula/view-parser';
|
||||
import { DLError } from './error';
|
||||
|
||||
export class ReactivityParser {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import babelApi, { parseSync, type types as t } from '@babel/core';
|
||||
import { type ReactivityParserConfig } from '../types';
|
||||
import { parseView as pV, type ViewParserConfig } from '@inula/view-parser';
|
||||
import { parseView as pV, type ViewParserConfig } from '@openinula/view-parser';
|
||||
import { parseReactivity as pR } from '../index';
|
||||
|
||||
const htmlTags = [
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@inula/view-generator",
|
||||
"name": "@openinula/view-generator",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
|
@ -25,10 +25,10 @@
|
|||
"@types/node": "^20.10.5",
|
||||
"tsup": "^6.7.0",
|
||||
"typescript": "^5.3.2",
|
||||
"@inula/reactivity-parser": "workspace:*"
|
||||
"@openinula/reactivity-parser": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@inula/error-handler": "workspace:*"
|
||||
"@openinula/error-handler": "workspace:*"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": [
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t, type traverse } from '@babel/core';
|
||||
import { type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import { type SnippetPropMap, type ViewGeneratorConfig } from '../types';
|
||||
import ViewGenerator from '../ViewGenerator';
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type DependencyProp, type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type DependencyProp, type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import LifecycleGenerator from './LifecycleGenerator';
|
||||
|
||||
export default class PropViewGenerator extends LifecycleGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import ViewGenerator from './ViewGenerator';
|
||||
|
||||
export default class MainViewGenerator extends ViewGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type DependencyProp, type CompParticle, type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type DependencyProp, type CompParticle, type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import ForwardPropGenerator from '../HelperGenerators/ForwardPropGenerator';
|
||||
|
||||
export default class CompGenerator extends ForwardPropGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type ViewParticle, type DependencyProp, type EnvParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle, type DependencyProp, type EnvParticle } from '@openinula/reactivity-parser';
|
||||
import PropViewGenerator from '../HelperGenerators/PropViewGenerator';
|
||||
|
||||
export default class EnvGenerator extends PropViewGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type ExpParticle } from '@inula/reactivity-parser';
|
||||
import { type ExpParticle } from '@openinula/reactivity-parser';
|
||||
import ElementGenerator from '../HelperGenerators/ElementGenerator';
|
||||
import { DLError } from '../error';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import BaseGenerator from '../HelperGenerators/BaseGenerator';
|
||||
import { type ForParticle, type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ForParticle, type ViewParticle } from '@openinula/reactivity-parser';
|
||||
|
||||
export default class ForGenerator extends BaseGenerator {
|
||||
run() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type HTMLParticle } from '@inula/reactivity-parser';
|
||||
import { type HTMLParticle } from '@openinula/reactivity-parser';
|
||||
import HTMLPropGenerator from '../HelperGenerators/HTMLPropGenerator';
|
||||
|
||||
export default class HTMLGenerator extends HTMLPropGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type IfParticle, type IfBranch } from '@inula/reactivity-parser';
|
||||
import { type IfParticle, type IfBranch } from '@openinula/reactivity-parser';
|
||||
import CondGenerator from '../HelperGenerators/CondGenerator';
|
||||
|
||||
export default class IfGenerator extends CondGenerator {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { type DependencyProp, type SnippetParticle } from '@inula/reactivity-parser';
|
||||
import { type DependencyProp, type SnippetParticle } from '@openinula/reactivity-parser';
|
||||
import type { types as t } from '@babel/core';
|
||||
import PropViewGenerator from '../HelperGenerators/PropViewGenerator';
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { SwitchBranch, SwitchParticle } from '@inula/reactivity-parser';
|
||||
import { SwitchBranch, SwitchParticle } from '@openinula/reactivity-parser';
|
||||
import CondGenerator from '../HelperGenerators/CondGenerator';
|
||||
|
||||
export default class SwitchGenerator extends CondGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type HTMLParticle, type TemplateParticle } from '@inula/reactivity-parser';
|
||||
import { type HTMLParticle, type TemplateParticle } from '@openinula/reactivity-parser';
|
||||
import HTMLPropGenerator from '../HelperGenerators/HTMLPropGenerator';
|
||||
|
||||
export default class TemplateGenerator extends HTMLPropGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type TextParticle } from '@inula/reactivity-parser';
|
||||
import { type TextParticle } from '@openinula/reactivity-parser';
|
||||
import BaseGenerator from '../HelperGenerators/BaseGenerator';
|
||||
|
||||
export default class TextGenerator extends BaseGenerator {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import BaseGenerator from '../HelperGenerators/BaseGenerator';
|
||||
import { TryParticle, type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { TryParticle, type ViewParticle } from '@openinula/reactivity-parser';
|
||||
|
||||
export default class TryGenerator extends BaseGenerator {
|
||||
run() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import ViewGenerator from './ViewGenerator';
|
||||
|
||||
export default class SnippetGenerator extends ViewGenerator {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type types as t } from '@babel/core';
|
||||
import { type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import { type ViewGeneratorConfig } from './types';
|
||||
import BaseGenerator, { prefixMap } from './HelperGenerators/BaseGenerator';
|
||||
import CompGenerator from './NodeGenerators/CompGenerator';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createErrorHandler } from '@inula/error-handler';
|
||||
import { createErrorHandler } from '@openinula/error-handler';
|
||||
|
||||
export const DLError = createErrorHandler(
|
||||
'ViewGenerator',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { type ViewParticle } from '@inula/reactivity-parser';
|
||||
import { type ViewParticle } from '@openinula/reactivity-parser';
|
||||
import { type ViewGeneratorConfig } from './types';
|
||||
import { type types as t } from '@babel/core';
|
||||
import MainViewGenerator from './MainViewGenerator';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@inula/view-parser",
|
||||
"name": "@openinula/view-parser",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
|
@ -29,7 +29,7 @@
|
|||
"vitest": "^0.34.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@inula/error-handler": "workspace:*"
|
||||
"@openinula/error-handler": "workspace:*"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": [
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { createErrorHandler } from '@inula/error-handler';
|
||||
import { createErrorHandler } from '@openinula/error-handler';
|
||||
|
||||
export const DLError = createErrorHandler(
|
||||
'ViewParser',
|
||||
{
|
||||
1: "Invalid syntax in DLight's View, only accepts dot chain call expression",
|
||||
1: 'Invalid syntax in DLight\'s View, only accepts dot chain call expression',
|
||||
2: 'First argument of $0() must be an expression',
|
||||
3: "Invalid syntax in DLight's View, only accepts expression as props",
|
||||
3: 'Invalid syntax in DLight\'s View, only accepts expression as props',
|
||||
4: 'Invalid Snippet calling, only accepts static snippet calling like `this.Snippet()`',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# vite-plugin-inula-next
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [2f9d373]
|
||||
- babel-preset-inula-next@0.0.2
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vite-plugin-inula-next",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"author": {
|
||||
"name": "IanDx",
|
||||
"email": "iandxssxx@gmail.com"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { transform } from '@babel/core';
|
||||
import dlight, { type DLightOption } from '../../babel-preset-inula-next';
|
||||
import dlight, { type DLightOption } from 'babel-preset-inula-next';
|
||||
import { minimatch } from 'minimatch';
|
||||
import { Plugin, TransformResult } from 'vite';
|
||||
export default function (options: DLightOption = {}): Plugin {
|
||||
|
|
Loading…
Reference in New Issue