feat(experimental): shouldTransform for ref-transform
This commit is contained in:
@@ -37,6 +37,17 @@ A few commonly used APIs have shorthands (which also removes the need to import
|
||||
|
||||
This package is the lower-level transform that can be used standalone. Higher-level tooling (e.g. `@vitejs/plugin-vue` and `vue-loader`) will provide integration via options.
|
||||
|
||||
### `shouldTransform`
|
||||
|
||||
Can be used to do a cheap check to determine whether full transform should be performed.
|
||||
|
||||
```js
|
||||
import { shouldTransform } from '@vue/ref-transform'
|
||||
|
||||
shouldTransform(`let a = ref(0)`) // false
|
||||
shouldTransform(`let a = $ref(0)`) // true
|
||||
```
|
||||
|
||||
### `transform`
|
||||
|
||||
```js
|
||||
@@ -66,6 +77,8 @@ interface RefTransformOptions {
|
||||
|
||||
### `transformAST`
|
||||
|
||||
Transform with an existing Babel AST + MagicString instance. This is used internally by `@vue/compiler-sfc` to avoid double parse/transform cost.
|
||||
|
||||
```js
|
||||
import { transformAST } from '@vue/ref-transform'
|
||||
import { parse } from '@babel/parser'
|
||||
|
||||
@@ -24,6 +24,11 @@ import { babelParserDefaultPlugins } from '@vue/shared'
|
||||
const TO_VAR_SYMBOL = '$'
|
||||
const TO_REF_SYMBOL = '$$'
|
||||
const shorthands = ['ref', 'computed', 'shallowRef']
|
||||
const transformCheckRE = /[^\w]\$(?:\$|ref|computed|shallowRef)?\(/
|
||||
|
||||
export function shouldTransform(src: string): boolean {
|
||||
return transformCheckRE.test(src)
|
||||
}
|
||||
|
||||
export interface ReactiveDeclarator {
|
||||
node: VariableDeclarator
|
||||
|
||||
Reference in New Issue
Block a user