This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
247 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
declare module VueComponentCompiler { | ||
/** | ||
* Parse SFC file into block descriptors. | ||
* | ||
* @param content Contents of the SFC. | ||
* @param filename Filepath (used for cache key & in generated source maps) | ||
*/ | ||
export function parse(content: string, filename: string, config: ParserConfig): SFCDescriptor | ||
|
||
/** | ||
* Compile styles for SFC | ||
* | ||
* @param styles List of styles to process. | ||
* @param filename SFC file path | ||
*/ | ||
export function compileStyles(styles: Array<StyleCompilerSource>, filename: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>> | ||
|
||
/** | ||
* Compile template to render functions | ||
* | ||
* @param template Template to compile | ||
* @param filename SFC file path | ||
*/ | ||
export function compileTemplate(template: TemplateCompilerSource, filename: string, config: TemplateCompilerConfig): Promise<TemplateCompilerOutput> | ||
|
||
export function assemble(source: AssemblerSource, filename: string, config: AssemblerConfig): string | ||
|
||
type ParserConfig = { | ||
needMap: boolean | ||
} | ||
|
||
type SFCDescriptor = { | ||
script: ScriptDescriptor | ||
styles: Array<StyleDescriptor> | ||
template: TemplateDescriptor | ||
customBlocks: Array<BlockDescriptor> | ||
} | ||
|
||
type BlockDescriptor = { | ||
type: string // tag | ||
content: string | ||
start: number | ||
end: number | ||
attrs: Array<{ name: string, value: string | boolean}> | ||
} | ||
|
||
type StyleDescriptor = BlockDescriptor & { | ||
scoped?: boolean | ||
module?: string | boolean | ||
lang?: string | ||
src?: string | ||
} | ||
|
||
type ScriptDescriptor = BlockDescriptor & { | ||
lang?: string | ||
src?: string | ||
} | ||
|
||
type TemplateDescriptor = BlockDescriptor & { | ||
lang?: string | ||
src?: string | ||
} | ||
|
||
type CompilerSource = { | ||
code: string | ||
map?: object // prev source map | ||
} | ||
|
||
type StyleCompilerSource = CompilerSource & { | ||
descriptor: StyleDescriptor | ||
} | ||
|
||
type StyleCompilerConfig = { | ||
scopeId: string // used for scoped styles. | ||
needMap?: boolean | ||
plugins?: Array<object> // postcss plugins | ||
options?: object // postcss options | ||
onWarn?: MessageHandler | ||
} | ||
|
||
type MessageHandler = (message: Message) => void | ||
|
||
type Message = { | ||
type: string | ||
text?: string | ||
} | ||
|
||
type CompilerOutput = { | ||
code: string, | ||
map?: object | ||
} | ||
|
||
type StyleCompilerOutput = CompilerOutput & {} | ||
|
||
type TemplateCompilerSource = CompilerSource & { | ||
descriptor: TemplateDescriptor | ||
} | ||
|
||
type TemplateCompilerConfig = { | ||
isHot?: boolean // false | ||
isServer?: boolean // false | ||
isProduction?: boolean // true | ||
optimizeSSR?: boolean // true | ||
buble: object // see https://github.com/vuejs/vue-template-es2015-compiler/blob/master/index.js#L6 | ||
options?: { | ||
preserveWhitspace?: boolean // true | ||
} | ||
transformToRequire?: object | ||
plugins?: Array<Function> | ||
} | ||
|
||
type TemplateCompilerOutput = CompilerOutput & { | ||
errors: Array<object> | ||
tips: Array<object> | ||
} | ||
|
||
type AssemblerSource = { | ||
script: { | ||
id: string, | ||
descriptor: ScriptDescriptor | ||
} | ||
styles: Array<{ | ||
id: string | ||
hotPath: string | ||
descriptor: StyleDescriptor | ||
}> | ||
render: { | ||
id: string | ||
descriptor: TemplateDescriptor | ||
} | ||
customBlocks: Array<{ | ||
id: string | ||
descriptor: BlockDescriptor | ||
}> | ||
} | ||
|
||
type AssemblerConfig = { | ||
hashKey?: string | ||
esModule?: boolean // true | ||
shortFilePath?: string // = filename | ||
require?: { | ||
vueHotReloadAPI?: string // vue-hot-reload-api | ||
normalizeComponent?: string // vue-component-compiler/src/normalize-component.js | ||
} | ||
moduleId: string // same as scopeId of style compiler. | ||
moduleIdentifier?: string // autogenerated | ||
isHot?: boolean // false | ||
isServer?: boolean // false | ||
isProduction?: boolean // true | ||
isInjectable?: boolean // false | ||
hasStyleInjectFn?: boolean // false | ||
onWarn?: MessageHandler // console.warn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// utility for generating a uid for each component file | ||
// used in scoped CSS rewriting | ||
var path = require('path') | ||
var hash = require('hash-sum') | ||
var cache = Object.create(null) | ||
var sepRE = new RegExp(path.sep.replace('\\', '\\\\'), 'g') | ||
|
||
module.exports = function genId (file, context, key) { | ||
var contextPath = context.split(path.sep) | ||
var rootId = contextPath[contextPath.length - 1] | ||
file = rootId + '/' + path.relative(context, file).replace(sepRE, '/') + (key || '') | ||
return cache[file] || (cache[file] = hash(file)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.