Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 977b947

Browse files
authored
re-implmentation
Vue component compiler implementation as...
2 parents bf67410 + 0ba6e8b commit 977b947

26 files changed

+2736
-44
lines changed

.circleci/config.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/rollup-plugin-vue
5+
docker:
6+
- image: circleci/node:8.5.0
7+
steps:
8+
- checkout
9+
- run:
10+
name: Install yarn if required
11+
command: curl -o- -s -L https://yarnpkg.com/install.sh | bash
12+
- restore_cache:
13+
key: dependency-cache-{{ checksum "package.json" }}
14+
- run:
15+
name: Install package dependencies
16+
command: yarn --no-progress install
17+
- save_cache:
18+
key: dependency-cache-{{ checksum "package.json" }}
19+
paths:
20+
- node_modules
21+
- run:
22+
name: Test
23+
command: npm test

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

.eslintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": ["plugin:vue-libs/recommended"]
4+
}

index.d.ts

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
declare module VueComponentCompiler {
2+
/**
3+
* Parse SFC file into block descriptors.
4+
*
5+
* @param content Contents of the SFC.
6+
* @param file Filepath (used for cache key & in generated source maps)
7+
*/
8+
export function parse(content: string, file: string, config: ParserConfig): SFCDescriptor
9+
10+
/**
11+
* Compile styles for SFC
12+
*
13+
* @param styles List of styles to process.
14+
* @param file SFC file path
15+
*/
16+
export function compileStyle(style: StyleCompilerSource, file: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>>
17+
18+
/**
19+
* Compile template to render functions
20+
*
21+
* @param template Template to compile
22+
* @param file SFC file path
23+
*/
24+
export function compileTemplate(template: TemplateCompilerSource, file: string, config: TemplateCompilerConfig): Promise<TemplateCompilerOutput>
25+
26+
/**
27+
* Assemble processed parts of SFC.
28+
*
29+
* @param source Processed sources with resolvable identifiers (`id`)
30+
* @param file SFC file path
31+
*/
32+
export function assemble(source: AssemblerSource, file: string, config: AssemblerConfig): string
33+
34+
/**
35+
* Generate scope id for SFC, used in scoped styles.
36+
*
37+
* @param file SFC file path
38+
* @param context file is required in context
39+
* @param key
40+
*/
41+
export function generateScopeId(file: string, context: string, key?: string): string
42+
43+
type ParserConfig = {
44+
needMap: boolean
45+
}
46+
47+
type SFCDescriptor = {
48+
script: ScriptDescriptor
49+
styles: Array<StyleDescriptor>
50+
template: TemplateDescriptor
51+
customBlocks: Array<BlockDescriptor>
52+
}
53+
54+
type BlockDescriptor = {
55+
type: string // tag
56+
content: string
57+
start: number
58+
end: number
59+
attrs: Array<{ name: string, value: string | boolean}>
60+
}
61+
62+
type StyleDescriptor = BlockDescriptor & {
63+
scoped?: boolean
64+
module?: string | boolean
65+
lang?: string
66+
src?: string
67+
}
68+
69+
type ScriptDescriptor = BlockDescriptor & {
70+
lang?: string
71+
src?: string
72+
}
73+
74+
type TemplateDescriptor = BlockDescriptor & {
75+
lang?: string
76+
src?: string
77+
}
78+
79+
type CompilerSource = {
80+
code: string
81+
map?: object // prev source map
82+
}
83+
84+
type StyleCompilerSource = CompilerSource & {
85+
descriptor: StyleDescriptor
86+
}
87+
88+
type StyleCompilerConfig = {
89+
scopeId: string // used for scoped styles.
90+
needMap?: boolean
91+
plugins?: Array<object> // postcss plugins
92+
options?: object // postcss options
93+
onWarn?: MessageHandler
94+
}
95+
96+
type MessageHandler = (message: Message) => void
97+
98+
type Message = {
99+
type: string
100+
text?: string
101+
}
102+
103+
type CompilerOutput = {
104+
code: string,
105+
map?: object
106+
}
107+
108+
type StyleCompilerOutput = CompilerOutput & {}
109+
110+
type TemplateCompilerSource = CompilerSource & {
111+
descriptor: TemplateDescriptor
112+
}
113+
114+
type TemplateCompilerConfig = {
115+
scopeId: string
116+
isHot?: boolean // false
117+
isServer?: boolean // false
118+
isProduction?: boolean // true
119+
esModule?: boolean // true
120+
optimizeSSR?: boolean // true
121+
buble: object // see https://github.com/vuejs/vue-template-es2015-compiler/blob/master/index.js#L6
122+
options?: {
123+
preserveWhitspace?: boolean // true
124+
}
125+
transformToRequire?: object
126+
plugins?: Array<Function>
127+
}
128+
129+
type TemplateCompilerOutput = CompilerOutput & {
130+
errors: Array<object>
131+
tips: Array<object>
132+
}
133+
134+
type AssemblerSource = {
135+
script: {
136+
id: string,
137+
descriptor: ScriptDescriptor
138+
}
139+
styles: Array<{
140+
id: string
141+
hotPath: string
142+
descriptor: StyleDescriptor
143+
}>
144+
render: {
145+
id: string
146+
descriptor: TemplateDescriptor
147+
}
148+
customBlocks: Array<{
149+
id: string
150+
descriptor: BlockDescriptor
151+
}>
152+
}
153+
154+
type AssemblerConfig = {
155+
hashKey?: string
156+
esModule?: boolean // true
157+
shortFilePath?: string // = filename
158+
require?: {
159+
vueHotReloadAPI?: string // vue-hot-reload-api
160+
normalizeComponent?: string // vue-component-compiler/src/normalize-component.js
161+
}
162+
scopeId: string // same as scopeId of style compiler.
163+
moduleIdentifier?: string // ~ used in SSR
164+
isHot?: boolean // false
165+
isServer?: boolean // false
166+
isProduction?: boolean // true
167+
isInjectable?: boolean // false
168+
hasStyleInjectFn?: boolean // false
169+
onWarn?: MessageHandler // console.warn
170+
}
171+
}

index.js

Whitespace-only changes.

0 commit comments

Comments
 (0)