From a4ed58c076649a4536b40a9c98c974c77602c76b Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 10 Jan 2019 17:58:06 -0500 Subject: [PATCH] feat(compiler): expose generateCodeFrame method --- packages/vue-template-compiler/README.md | 12 ++++++++++++ src/platforms/web/entry-compiler.js | 1 + src/platforms/weex/entry-compiler.js | 1 + 3 files changed, 14 insertions(+) diff --git a/packages/vue-template-compiler/README.md b/packages/vue-template-compiler/README.md index 922622e5d4e..afdb482e0eb 100644 --- a/packages/vue-template-compiler/README.md +++ b/packages/vue-template-compiler/README.md @@ -33,6 +33,12 @@ Note the returned function code uses `with` and thus cannot be used in strict mo #### Options +- `outputSourceRange` *new in 2.6* + - Type: `boolean` + - Default: `false` + + 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. + - `whitespace` - Type: `string` - Valid values: `'preserve' | 'condense'` @@ -140,6 +146,12 @@ Same as `compiler.compileToFunction` but generates SSR-specific render function 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`. +--- + +### compiler.generateCodeFrame(template, start, end) + +Generate a code frame that highlights the part in `template` defined by `start` and `end`. Useful for error reporting in higher-level tooling. + #### Options #### `pad` diff --git a/src/platforms/web/entry-compiler.js b/src/platforms/web/entry-compiler.js index ee63476e1eb..15a4f685999 100644 --- a/src/platforms/web/entry-compiler.js +++ b/src/platforms/web/entry-compiler.js @@ -3,3 +3,4 @@ export { parseComponent } from 'sfc/parser' export { compile, compileToFunctions } from './compiler/index' export { ssrCompile, ssrCompileToFunctions } from './server/compiler' +export { generateCodeFrame } from 'compiler/codeframe' diff --git a/src/platforms/weex/entry-compiler.js b/src/platforms/weex/entry-compiler.js index 18d79ab742f..b8f3f8ffcfb 100644 --- a/src/platforms/weex/entry-compiler.js +++ b/src/platforms/weex/entry-compiler.js @@ -1 +1,2 @@ export { compile } from 'weex/compiler/index' +export { generateCodeFrame } from 'compiler/codeframe'