feat: expose compiler APIs
This commit is contained in:
@@ -4,7 +4,7 @@ import { SourceMapConsumer, RawSourceMap } from 'source-map'
|
||||
describe('compiler: codegen', () => {
|
||||
test('basic source map support', async () => {
|
||||
const ast = parse(`hello {{ world }}`)
|
||||
const { code, map } = generate(ast, { module: false })
|
||||
const { code, map } = generate(ast)
|
||||
expect(code).toBe(`["hello ", world]`)
|
||||
|
||||
const consumer = await new SourceMapConsumer(map as RawSourceMap)
|
||||
|
||||
@@ -15,6 +15,7 @@ import { advancePositionWithMutation } from './utils'
|
||||
export interface CodegenOptions {
|
||||
// Assume ES module environment. If true, will generate import statements for
|
||||
// runtime helpers; otherwise will grab the helpers from global `Vue`.
|
||||
// default: false
|
||||
module?: boolean
|
||||
// Filename for source map generation.
|
||||
filename?: string
|
||||
@@ -68,7 +69,7 @@ function createCodegenContext(
|
||||
options: CodegenOptions
|
||||
): CodegenContext {
|
||||
const context: CodegenContext = {
|
||||
module: true,
|
||||
module: false,
|
||||
filename: `template.vue.html`,
|
||||
...options,
|
||||
source: ast.loc.source,
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
export { parse, ParserOptions, TextModes } from './parse'
|
||||
export { transform, TransformOptions, Transform } from './transform'
|
||||
export {
|
||||
transform,
|
||||
createDirectiveTransform,
|
||||
TransformOptions,
|
||||
Transform
|
||||
} from './transform'
|
||||
export { generate, CodegenOptions, CodegenResult } from './codegen'
|
||||
export { ErrorCodes } from './errors'
|
||||
export { ErrorCodes, CompilerError, createCompilerError } from './errors'
|
||||
|
||||
export * from './ast'
|
||||
|
||||
Reference in New Issue
Block a user