Browse Source

refactor(compiler): export isLiteralWhitelisted

三咲智子 Kevin Deng 2 years ago
parent
commit
0cdc9f20c6

+ 1 - 0
packages/compiler-core/src/index.ts

@@ -54,6 +54,7 @@ export {
   transformExpression,
   processExpression,
   stringifyExpression,
+  isLiteralWhitelisted,
 } from './transforms/transformExpression'
 export {
   buildSlots,

+ 3 - 1
packages/compiler-core/src/transforms/transformExpression.ts

@@ -44,7 +44,9 @@ import { parse } from '@babel/parser'
 import { IS_REF, UNREF } from '../runtimeHelpers'
 import { BindingTypes } from '../options'
 
-const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this')
+export const isLiteralWhitelisted = /*#__PURE__*/ makeMap(
+  'true,false,null,this',
+)
 
 // a heuristic safeguard to bail constant expressions on presence of
 // likely function invocation and member access

+ 2 - 3
packages/compiler-vapor/src/generators/expression.ts

@@ -5,10 +5,11 @@ import {
   type SourceLocation,
   advancePositionWithClone,
   isInDestructureAssignment,
+  isLiteralWhitelisted,
   isStaticProperty,
   walkIdentifiers,
 } from '@vue/compiler-dom'
-import { isGloballyAllowed, makeMap } from '@vue/shared'
+import { isGloballyAllowed } from '@vue/shared'
 import type { Identifier } from '@babel/types'
 import {
   type CodeFragment,
@@ -98,8 +99,6 @@ export function genExpression(
   }
 }
 
-const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this')
-
 function genIdentifier(
   raw: string,
   { options, vaporHelper, identifiers }: CodegenContext,