|
| 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 | +} |
0 commit comments