Skip to content

Commit e44ba00

Browse files
committed
(vue3 compiler): add parser test
1 parent eec70dc commit e44ba00

File tree

19 files changed

+304
-112
lines changed

19 files changed

+304
-112
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
5+
6+
7+
export default function html() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
4+
5+
import model from './model';
6+
import text from './text';
7+
import html from './html';
8+
9+
10+
11+
export default {
12+
model,
13+
text,
14+
html
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
export default function model() {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
export default function text() {
4+
5+
}

vue/template-compiler-playground/vue3-compiler/platform-web-compiler/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import {createCompiler} from "../vue3-template-compiler";
22
import {baseOptions} from "./options";
33

44

5-
export const {compile} = createCompiler(baseOptions);
5+
export const {compile, compileToFunctions} = createCompiler(baseOptions);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
function transformNode() {
19+
20+
}
21+
22+
function generateData() {
23+
24+
}
25+
26+
27+
export default {
28+
staticKeys: ['staticClass'],
29+
transformNode,
30+
generateData,
31+
};
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
import kclass from './class';
4+
import style from './style';
5+
import model from './model';
6+
7+
8+
9+
export default [kclass, style, model];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
function preTransformNode() {
17+
18+
}
19+
20+
21+
22+
23+
export default {
24+
preTransformNode,
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
4+
function transformNode() {
5+
6+
}
7+
8+
function generateData() {
9+
10+
}
11+
12+
13+
export default {
14+
staticKeys: ['staticClass'],
15+
transformNode,
16+
generateData,
17+
};
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11

2-
export const baseOptions: CompilerOptions = {};
2+
3+
import modules from './modules';
4+
import directives from './directives';
5+
6+
export const baseOptions = {
7+
expectHTML: true,
8+
modules,
9+
directives,
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {baseOptions} from "../platform-web-compiler/options";
2+
3+
describe('parser', () => {
4+
it('simple element', () => {
5+
const ast = parse('<h1>hello world</h1>', baseOptions);
6+
expect(ast.tag).toBe('h1');
7+
expect(ast.plain).toBe(true);
8+
expect(ast.children[0].text).toBe('hello world');
9+
});
10+
});

vue/template-compiler-playground/vue3-compiler/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* Strict Type-Checking Options */
2424
"strict": true, /* Enable all strict type-checking options. */
25-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25+
// "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
2626
// "strictNullChecks": true, /* Enable strict null checks. */
2727
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
2828
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
4+
export const generate = (ast, options) => {};

vue/template-compiler-playground/vue3-compiler/vue3-template-compiler/index.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,26 @@
1818
/*
1919
* Template compilation options / results
2020
*/
21-
import {ASTElement, CompilerOptions} from "./types";
22-
23-
24-
25-
26-
export const createCompiler = createCompilerCreator((template: string, options: CompilerOptions): CompiledResult => {
21+
import {ASTElement, CompiledResult, CompilerOptions} from "./types";
22+
import {parse} from "./parser";
23+
import {optimize} from "./optimizer";
24+
import {generate} from "./codegenerator";
25+
26+
const createCompileToFunction = (compile) => {};
27+
28+
const createCompilerCreator = (baseCompile: Function) => {
29+
return (options: any) => {
30+
const compile = (template: any, options: any) => {
31+
const compiled = baseCompile(template, options);
32+
33+
return compiled;
34+
};
35+
36+
return {compile, compileToFunctions: createCompileToFunction(compile)};
37+
};
38+
};
39+
40+
export const createCompiler = createCompilerCreator((template: string, options: CompilerOptions): CompiledResult<ErrorType> => {
2741
const ast = parse(template.trim(), options);
2842
optimize(ast, options);
2943
const code = generate(ast, options);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
export const optimize = (ast, options) => {};

0 commit comments

Comments
 (0)