MCPcopy
hub / github.com/vuejs/core / createExp

Function createExp

packages/compiler-core/src/parser.ts:971–1010  ·  view source on GitHub ↗
(
  content: SimpleExpressionNode['content'],
  isStatic: SimpleExpressionNode['isStatic'] = false,
  loc: SourceLocation,
  constType: ConstantTypes = ConstantTypes.NOT_CONSTANT,
  parseMode = ExpParseMode.Normal,
)

Source from the content-addressed store, hash-verified

969}
970
971function createExp(
972 content: SimpleExpressionNode['content'],
973 isStatic: SimpleExpressionNode['isStatic'] = false,
974 loc: SourceLocation,
975 constType: ConstantTypes = ConstantTypes.NOT_CONSTANT,
976 parseMode = ExpParseMode.Normal,
977) {
978 const exp = createSimpleExpression(content, isStatic, loc, constType)
979 if (
980 !__BROWSER__ &&
981 !isStatic &&
982 currentOptions.prefixIdentifiers &&
983 parseMode !== ExpParseMode.Skip &&
984 content.trim()
985 ) {
986 if (isSimpleIdentifier(content)) {
987 exp.ast = null // fast path
988 return exp
989 }
990 try {
991 const plugins = currentOptions.expressionPlugins
992 const options: BabelOptions = {
993 plugins: plugins ? [...plugins, 'typescript'] : ['typescript'],
994 }
995 if (parseMode === ExpParseMode.Statements) {
996 // v-on with multi-inline-statements, pad 1 char
997 exp.ast = parse(` ${content} `, options).program
998 } else if (parseMode === ExpParseMode.Params) {
999 exp.ast = parseExpression(`(${content})=>{}`, options)
1000 } else {
1001 // normal exp, wrap with parens
1002 exp.ast = parseExpression(`(${content})`, options)
1003 }
1004 } catch (e: any) {
1005 exp.ast = false // indicate an error
1006 emitError(ErrorCodes.X_INVALID_EXPRESSION, loc.start.offset, e.message)
1007 }
1008 }
1009 return exp
1010}
1011
1012function emitError(code: ErrorCodes, index: number, message?: string) {
1013 currentOptions.onError(

Callers 4

oninterpolationFunction · 0.85
ondirargFunction · 0.85
onattribendFunction · 0.85
createAliasExpressionFunction · 0.85

Calls 4

createSimpleExpressionFunction · 0.90
isSimpleIdentifierFunction · 0.90
emitErrorFunction · 0.85
parseFunction · 0.50

Tested by

no test coverage detected