Skip to content

Commit a4ed58c

Browse files
committed
feat(compiler): expose generateCodeFrame method
1 parent 5371617 commit a4ed58c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

packages/vue-template-compiler/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Note the returned function code uses `with` and thus cannot be used in strict mo
3333

3434
#### Options
3535

36+
- `outputSourceRange` *new in 2.6*
37+
- Type: `boolean`
38+
- Default: `false`
39+
40+
Set this to true will cause the `errors` returned in the compiled result become objects in the form of `{ msg, start, end }`. The `start` and `end` properties are numbers that mark the code range of the error source in the template. This can be passed on to the `compiler.generateCodeFrame` API to generate code frame for the error.
41+
3642
- `whitespace`
3743
- Type: `string`
3844
- Valid values: `'preserve' | 'condense'`
@@ -140,6 +146,12 @@ Same as `compiler.compileToFunction` but generates SSR-specific render function
140146

141147
Parse a SFC (single-file component, or `*.vue` file) into a descriptor (refer to the `SFCDescriptor` type in [flow declarations](https://github.com/vuejs/vue/blob/dev/flow/compiler.js)). This is used in SFC build tools like `vue-loader` and `vueify`.
142148

149+
---
150+
151+
### compiler.generateCodeFrame(template, start, end)
152+
153+
Generate a code frame that highlights the part in `template` defined by `start` and `end`. Useful for error reporting in higher-level tooling.
154+
143155
#### Options
144156

145157
#### `pad`

src/platforms/web/entry-compiler.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
export { parseComponent } from 'sfc/parser'
44
export { compile, compileToFunctions } from './compiler/index'
55
export { ssrCompile, ssrCompileToFunctions } from './server/compiler'
6+
export { generateCodeFrame } from 'compiler/codeframe'

src/platforms/weex/entry-compiler.js

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { compile } from 'weex/compiler/index'
2+
export { generateCodeFrame } from 'compiler/codeframe'

0 commit comments

Comments
 (0)