import MagicString from 'magic-string' import { BindingMetadata, BindingTypes, createRoot, NodeTypes, transform, parserOptions, UNREF, SimpleExpressionNode, isFunctionType, walkIdentifiers, unwrapTSNode } from '@vue/compiler-dom' import { DEFAULT_FILENAME, SFCDescriptor, SFCScriptBlock } from './parse' import { parse as _parse, parseExpression, ParserOptions, ParserPlugin } from '@babel/parser' import { camelize, capitalize, generateCodeFrame, makeMap } from '@vue/shared' import { Node, Declaration, ObjectPattern, ObjectExpression, ArrayPattern, Identifier, ExportSpecifier, TSType, TSTypeLiteral, TSFunctionType, ObjectProperty, ArrayExpression, Statement, CallExpression, RestElement, TSInterfaceBody, TSTypeElement, AwaitExpression, Program, ObjectMethod, LVal, Expression, VariableDeclaration } from '@babel/types' import { walk } from 'estree-walker' import { RawSourceMap } from 'source-map' import { CSS_VARS_HELPER, genCssVarsCode, genNormalScriptCssVarsCode } from './cssVars' import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate' import { warnOnce } from './warn' import { rewriteDefaultAST } from './rewriteDefault' import { createCache } from './cache' import { shouldTransform, transformAST } from '@vue/reactivity-transform' // Special compiler macros const DEFINE_PROPS = 'defineProps' const DEFINE_EMITS = 'defineEmits' const DEFINE_EXPOSE = 'defineExpose' const WITH_DEFAULTS = 'withDefaults' const DEFINE_OPTIONS = 'defineOptions' // constants const DEFAULT_VAR = `__default__` const isBuiltInDir = makeMap( `once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is` ) export interface SFCScriptCompileOptions { /** * Scope ID for prefixing injected CSS variables. * This must be consistent with the `id` passed to `compileStyle`. */ id: string /** * Production mode. Used to determine whether to generate hashed CSS variables */ isProd?: boolean /** * Enable/disable source map. Defaults to true. */ sourceMap?: boolean /** * https://babeljs.io/docs/en/babel-parser#plugins */ babelParserPlugins?: ParserPlugin[] /** * (Experimental) Enable syntax transform for using refs without `.value` and * using destructured props with reactivity * @deprecated the Reactivity Transform proposal has been dropped. This * feature will be removed from Vue core in 3.4. If you intend to continue * using it, disable this and switch to the [Vue Macros implementation](https://vue-macros.sxzz.moe/features/reactivity-transform.html). */ reactivityTransform?: boolean /** * Compile the template and inline the resulting render function * directly inside setup(). * - Only affects `