feat: v-once

Note: only compiler transform is tested - integration with runtime
still needs to be tested.
This commit is contained in:
Evan You
2019-10-09 17:32:58 -04:00
parent 5dfb271551
commit 93c6aa4c90
7 changed files with 63 additions and 13 deletions

View File

@@ -13,6 +13,7 @@ import { transformBind } from './transforms/vBind'
import { defaultOnError, createCompilerError, ErrorCodes } from './errors'
import { trackSlotScopes, trackVForSlotScopes } from './transforms/vSlot'
import { optimizeText } from './transforms/optimizeText'
import { transformOnce } from './transforms/vOnce'
export type CompilerOptions = ParserOptions & TransformOptions & CodegenOptions
@@ -60,6 +61,7 @@ export function baseCompile(
directiveTransforms: {
on: transformOn,
bind: transformBind,
once: transformOnce,
...(options.directiveTransforms || {}) // user transforms
}
})

View File

@@ -0,0 +1,15 @@
import {
DirectiveTransform,
createObjectProperty,
createSimpleExpression
} from '@vue/compiler-core'
export const transformOnce: DirectiveTransform = dir => {
return {
props: createObjectProperty(
createSimpleExpression(`$once`, true, dir.loc),
createSimpleExpression('true', false)
),
needRuntime: false
}
}

View File

@@ -63,7 +63,7 @@ export const walkJS: typeof walk = (ast, walker) => {
}
export const isSimpleIdentifier = (name: string): boolean =>
!/^\d|[^\w]/.test(name)
!/^\d|[^\$\w]/.test(name)
export function getInnerRange(
loc: SourceLocation,